Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local numbers = {":zero:",":one:",":two:",":three:",":four:",":five:",":six:",":seven:","eight:",":nine:"}
- local x = 10
- local y = 10
- local mines = 13
- local am = 0
- local seed = 4
- local notusedvalue = 0
- local countup = 0
- local offset = 3
- local str = ""
- for i=1,seed do
- notusedvalue = math.random(1,3)
- end
- -- we want to generate the field (and maybe insert mines?)
- local field = {}
- for i=1,x do
- table.insert(field,{})
- for ii=1,y do
- countup = countup + 1
- local tab = field[i]
- local ran = math.random(1,x*y)
- if ran <= mines + offset and am ~= mines then
- table.insert(tab,":bomb:")
- am = am + 1
- elseif ran > mines + offset and am ~= mines then
- local amount = x*y
- local current = countup
- local minesleft = mines-am
- --print(i,ii,current,amount,minesleft)
- if minesleft+current == amount then
- table.insert(tab,":bomb:")
- am = am + 1
- else
- table.insert(tab,"")
- end
- else
- table.insert(tab,"")
- end
- end
- end
- function getCord(x,y)
- local tab = field[x]
- return tab[y]
- end
- function addNumber(x,y)
- local tab = field[x]
- number = tab[y]
- if number == "" then
- tab[y] = ":one:"
- elseif number == ":one:" then
- tab[y] = ":two:"
- elseif number == ":two:" then
- tab[y] = ":three:"
- elseif number == ":three:" then
- tab[y] = ":four:"
- elseif number == "four" then
- tab[y] = ":five:"
- elseif number == ":five:" then
- tab[y] = ":six:"
- elseif number == ":six:" then
- tab[y] = ":seven:"
- elseif number == ":seven:" then
- tab[y] = ":eight:"
- elseif number == ":eight:" then
- tab[y] = ":nine:"
- end
- end
- for i,v in pairs(field) do
- for ii,vv in pairs(v) do
- local xx = i
- local yy = ii
- if vv == ":bomb:" then
- if xx-1 > 0 then
- if yy+1 <= y then
- addNumber(xx-1,yy+1)
- end
- if yy-1 > 0 then
- addNumber(xx-1,yy-1)
- end
- addNumber(xx-1,yy)
- end
- if xx+1 <= x then
- if yy+1 <= y then
- addNumber(xx+1,yy+1)
- end
- if yy-1 > 0 then
- addNumber(xx+1,yy-1)
- end
- addNumber(xx+1,yy)
- end
- if yy+1 <= y then
- addNumber(xx,yy+1)
- end
- if yy-1 > 0 then
- addNumber(xx,yy-1)
- end
- end
- end
- end
- for i,v in pairs(field) do
- if i ~= 1 then str = str.."\n" end
- for ii,vv in pairs(v) do
- if vv == "" then
- str = str.."||:zero:|| "
- else
- str = str.."||"..vv.."|| "
- end
- end
- end
- print(str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement