Skip to content

Instantly share code, notes, and snippets.

@tomaes

tomaes/minesonar.lua

Last active May 9, 2019
Embed
What would you like to do?
the same minesonar.bas micro game in LUA
-- minesonar.bas in Lua (aka first Lua test, v2)
r, x, y = 0, math.random(8), math.random(8)
print "There is a mine hidden in an 8x8 field"
repeat
r = r + 1
io.write "Enter x,y coords:"
local ln = io.read "*line"
local s = {}
local i = 1
for coord in string.gmatch(ln, "%d") do
s[i] = tonumber(coord)
i = i + 1
if i == 3 then break end
end
if s[1] == nil or s[2] == nil then
print "try '5,5' or similar; using those for now"
s = {5, 5}
end
local d = math.sqrt((x-s[1])^2+(y-s[2])^2)
print ("dist:" ..d);
until d < 0.1
print ("Done in " ..r.. " rounds!")
if r < 4 then print "Wow! That was quick!" end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment