Concise game implementations

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Concise game implementations

Post by undef »

Hey,

let's share very short game implementations.

I wrote this pure Lua, terminal based, two player RPS game today:

Code: Select all

choice, winning = {}, { r = 's', p = 'r', s = 'p' }
for n=1, 2 do
	print( ("Player %d:\nType 'r' for rock, 'p' for paper, or 's' for scissors and press return."):format( n ) )
	while not choice[n] do  choice[n] = io.read():match"^[rps]"  end
end

print( choice[1]==choice[2] and "Draw!" or ("Player %d wins!"):format( winning[choice[1]]==choice[2] and 1 or 2 ) )
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Concise game implementations

Post by Nixola »

Code: Select all

choice, winning = {}, { r = 's', p = 'r', s = 'p' }
for n=1, 2 do
	os.execute("cls") 
	os.execute("clear")
	print( ("Player %d:\nType 'r' for rock, 'p' for paper, or 's' for scissors and press return."):format( n ) )
	while not choice[n] do  choice[n] = io.read():match"^[rps]"  end
end

print( choice[1]==choice[2] and "Draw!" or ("Player %d wins!"):format( winning[choice[1]]==choice[2] and 1 or 2 ) )
I added something to clear the terminal, so the second player can't read the first choice ;)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: Concise game implementations

Post by undef »

Ooops, the danger of playtesting alone^^
twitter | steam | indieDB

Check out quadrant on Steam!
Xugro
Party member
Posts: 113
Joined: Wed Sep 29, 2010 8:14 pm

Re: Concise game implementations

Post by Xugro »

Graphical snake in 73 lines of code. There are magic numbers in there, but it should be easily understandable.

Controls:
  • arrow keys for moving
  • Esc or q to quit
There are no borders and the game restarts itself two seconds after losing it.

My trimmed down version is just 51 lines of code long.
Attachments
concise_snake.love
(908 Bytes) Downloaded 165 times
snake.love
(1.06 KiB) Downloaded 154 times
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Concise game implementations

Post by josefnpat »

How about pong in less than 100 lines of code?

https://gist.github.com/josefnpat/a1abc49d7badcfb42d75
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

Re: Concise game implementations

Post by RAFAEL HEBER »

thanks for the pong code!
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Concise game implementations

Post by Inny »

A few years ago I ported HAMURABI.BAS to lua, it's not "concise" but I figure it's worth a mention: https://gist.github.com/inmatarian/5121902
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests