Last active
May 9, 2019 13:14
-
-
Save tomaes/052ae192e6fd852e6d680b2f85165e45 to your computer and use it in GitHub Desktop.
the same minesonar.bas micro game in LUA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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