Concise game implementations
Posted: Thu May 05, 2016 5:43 pm
Hey,
let's share very short game implementations.
I wrote this pure Lua, terminal based, two player RPS game today:
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 ) )