Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function load()
- term.clear()
- moves = 0
- x = math.random(1, 15);
- y = math.random(1, 15);
- tPlayer = {
- x = x;
- y = y;
- }
- tDone = {(x+10)..":"..(y+2)}
- end
- function getVals( sVals )
- sep = string.find(sVals, ":")
- x = tonumber(string.sub(sVals, 1, (sep-1)))
- y = tonumber(string.sub(sVals, (sep+1), #sVals))
- return x, y
- end
- function drawBoard()
- for i = 3, 17 do
- term.setBackgroundColor(colors.brown)
- term.setCursorPos(11, i)
- term.write(" ")
- end
- end
- function drawDone()
- for k, v in pairs(tDone) do
- x, y = getVals(v)
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.red)
- term.write(" ")
- end
- end
- function drawPlayer()
- term.setCursorPos(10 + tPlayer.x, 2 + tPlayer.y)
- term.setBackgroundColor(colors.white)
- term.write(" ")
- end
- function drawPossible()
- tPossible = {}
- x = tPlayer.x + 10 + 2
- y = tPlayer.y + 2 + 1
- tPossible[1] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- ----------------------------------
- x = tPlayer.x + 10 - 2
- y = tPlayer.y + 2 + 1
- tPossible[2] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- ----------------------------------
- x = tPlayer.x + 10 + 2
- y = tPlayer.y + 2 - 1
- tPossible[3] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- -----------------------------------
- x = tPlayer.x + 10 - 2
- y = tPlayer.y + 2 - 1
- tPossible[4] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- --=================================================
- --=================================================
- x = tPlayer.x + 10 + 1
- y = tPlayer.y + 2 + 2
- tPossible[5] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- ------------------------------------------------
- x = tPlayer.x + 10 - 1
- y = tPlayer.y + 2 + 2
- tPossible[6] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- ---------------------------------------------
- x = tPlayer.x + 10 + 1
- y = tPlayer.y + 2 - 2
- tPossible[7] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- --------------------------------------------
- x = tPlayer.x + 10 - 1
- y = tPlayer.y + 2 - 2
- tPossible[8] = x..":"..y
- term.setCursorPos(x, y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- end
- function drawMoves()
- term.setCursorPos(1,1)
- term.write("Moves: "..moves)
- end
- function drawBorder()
- term.setBackgroundColor(colors.black)
- term.setCursorPos(9, 1)
- term.write(" ")
- term.setCursorPos(9, 2)
- term.write(" ")
- for i = 0, 16 do
- term.setCursorPos(8, i + 3)
- term.write(" ")
- term.setCursorPos(27, i + 3)
- term.write(" ")
- end
- term.setCursorPos(9, 18)
- term.write(" ")
- term.setCursorPos(9, 19)
- term.write(" ")
- end
- load()
- while true do
- drawBoard()
- drawPossible()
- drawDone(tDone)
- drawPlayer()
- drawBorder()
- drawMoves()
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- step = true
- inBoard = true
- if xPos > 10 and xPos < 27 and yPos >= 3 and yPos < 18 then
- inBoard = true
- else
- inBoard = false
- end
- for key, val in pairs(tDone) do
- dx, dy = getVals(val)
- if (xPos-10) == dx-10 and (yPos-2) == dy-2 then
- step = false
- end
- end
- for k, v in pairs(tPossible) do
- x, y = getVals(v)
- if xPos == x and yPos == y and step and inBoard then
- moves = moves + 1
- tDone[#tDone+1] = x..":"..y
- tPlayer.x = x - 10
- tPlayer.y = y - 2
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment