Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local P1 = {}
- local P2 = {}
- local P1len, P2len = 0,0
- function Draw()
- term.setBackgroundColour(colors.white)
- term.clear()
- -- Player 1
- term.setTextColour(colors.blue)
- local first = true
- P1len = 0
- for i,u in pairs(P1) do
- if (first) then
- term.setTextColour(colors.cyan)
- first = false
- else
- term.setTextColour(colors.blue)
- end
- term.setCursorPos(u[1],u[2])
- write("X")
- P1len = P1len + 1
- end
- -- Player 2
- term.setTextColour(colors.red)
- first = true
- P2len = 0
- for i,u in pairs(P2) do
- if (first) then
- term.setTextColour(colors.pink)
- first = false
- else
- term.setTextColour(colors.red)
- end
- term.setCursorPos(u[1],u[2])
- write("O")
- P2len = P2len + 1
- end
- term.setTextColour(colors.black)
- --R1
- term.setCursorPos(3,1)
- write("|")
- term.setCursorPos(5,1)
- write("|")
- --R2
- term.setCursorPos(2,2)
- write("-")
- term.setCursorPos(3,2)
- write("+")
- term.setCursorPos(4,2)
- write("-")
- term.setCursorPos(5,2)
- write("+")
- term.setCursorPos(6,2)
- write("-")
- --R3
- term.setCursorPos(3,3)
- write("|")
- term.setCursorPos(5,3)
- write("|")
- --R4
- term.setCursorPos(2,4)
- write("-")
- term.setCursorPos(3,4)
- write("+")
- term.setCursorPos(4,4)
- write("-")
- term.setCursorPos(5,4)
- write("+")
- term.setCursorPos(6,4)
- write("-")
- --R5
- term.setCursorPos(3,5)
- write("|")
- term.setCursorPos(5,5)
- write("|")
- end
- function ValidateMove(x, y)
- if (x == 1 or x >= 7 or y > 5) then
- return false
- end
- if ( (x-1)%2 == 0 or y%2 == 0) then
- return false
- end
- for i,u in pairs(P1) do
- if (x == u[1] and y == u[2]) then
- return false
- end
- end
- for i,u in pairs(P2) do
- if (x == u[1] and y == u[2]) then
- return false
- end
- end
- return true
- end
- local eventclick = "mouse_click"
- if (monitor ~= nil) then
- term.redirect(monitor)
- eventclick = "monitor_touch"
- end
- while (true) do
- parallel.waitForAny(function()
- local validMove = false
- local event, button, x, y
- Draw()
- while (validMove == false) do
- event, button, x, y = os.pullEvent(eventclick)
- if (ValidateMove(x,y)) then
- validMove = true
- end
- end
- if (P1len >= 3) then
- table.remove(P1, 1)
- end
- table.insert(P1, {x,y})
- Draw()
- validMove = false
- while (validMove == false) do
- event, button, x, y = os.pullEvent(eventclick)
- if (ValidateMove(x,y)) then
- validMove = true
- end
- end
- if (P2len >= 3) then
- table.remove(P2, 1)
- end
- table.insert(P2, {x,y})
- end,
- function()
- os.pullEvent("redstone")
- P1 = {}
- P2 = {}
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment