Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Basic TicTacToe Game
- --Local Multiplayer (=there is no AI)
- --Written completely by Piorjade
- --Variablen
- _ver = 0.1
- _verstr = "0.1"
- mainmenu = false
- num = math.random(2)
- if num == 1 then turn = "O" elseif num == 2 then turn = "X" end
- slot1 = ""
- slot2 = ""
- slot3 = ""
- slot4 = ""
- slot5 = ""
- slot6 = ""
- slot7 = ""
- slot8 = ""
- slot9 = ""
- --Funktionen
- function clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- end
- function drawMenu()
- clear()
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(24,6)
- term.write("Start")
- term.setCursorPos(24,8)
- term.write("Exit")
- mainmenu = true
- while mainmenu do
- local event, button, x, y = os.pullEventRaw("mouse_click")
- if button == 1 and x >= 24 and x <= 28 and y == 6 then
- drawTable()
- elseif button == 1 and x >= 24 and x <= 27 and y == 8 then
- clear()
- print("Thanks for playing!")
- break
- end
- end
- end
- function drawTable()
- clear()
- print(" | | ")
- print("-+-+-")
- print(" | | ")
- print("-+-+-")
- print(" | | ")
- playing = true
- game()
- end
- function finish()
- term.setCursorPos(1,9)
- term.write(turn.." won!")
- sleep(2)
- clear()
- print("Thanks for playing!")
- playing = false
- sleep(2)
- os.reboot()
- end
- function game()
- while playing do
- term.setCursorPos(1,7)
- term.write("It is "..turn.."'s turn.")
- local event, button, x, y = os.pullEventRaw("mouse_click")
- if button == 1 and x == 1 and y == 1 and slot1 == "" then
- slot1 = turn
- term.setCursorPos(1,1)
- term.write(turn)
- if slot1 == turn and slot2 == turn and slot3 == turn or slot1 == turn and slot4 == turn and slot7 == turn or slot1 == turn and slot5 == turn and slot9 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 3 and y == 1 and slot2 == "" then
- slot2 = turn
- term.setCursorPos(3,1)
- term.write(turn)
- if slot2 == turn and slot1 == turn and slot3 == turn or slot2 == turn and slot5 == turn and slot8 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 5 and y == 1 and slot3 == "" then
- slot3 = turn
- term.setCursorPos(5,1)
- term.write(turn)
- if slot1 == turn and slot2 == turn and slot3 == turn or slot3 == turn and slot5 == turn and slot7 == turn or slot3 == turn and slot6 == turn and slot9 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 1 and y == 3 and slot4 == "" then
- slot4 = turn
- term.setCursorPos(1,3)
- term.write(turn)
- if slot4 == turn and slot1 == turn and slot7 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 3 and y == 3 and slot5 == "" then
- slot5 = turn
- term.setCursorPos(3,3)
- term.write(turn)
- if slot1 == turn and slot5 == turn and slot9 == turn or slot3 == turn and slot5 == turn and slot7 == turn or slot4 == turn and slot5 == turn and slot6 == turn or slot2 == turn and slot5 == turn and slot8 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 5 and y == 3 and slot6 == "" then
- slot6 = turn
- term.setCursorPos(5,3)
- term.write(turn)
- if slot3 == turn and slot6 == turn and slot9 == turn or slot4 == turn and slot5 == turn and slot6 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 1 and y == 5 and slot7 == "" then
- slot7 = turn
- term.setCursorPos(1,5)
- term.write(turn)
- if slot1 == turn and slot4 == turn and slot7 == turn or slot3 == turn and slot5 == turn and slot7 == turn or slot7 == turn and slot8 == turn and slot9 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 3 and y == 5 and slot8 == "" then
- slot8 = turn
- term.setCursorPos(3,5)
- term.write(turn)
- if slot7 == turn and slot8 == turn and slot9 == turn or slot2 == turn and slot5 == turn and slot8 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- elseif button == 1 and x == 5 and y == 5 and slot9 == "" then
- slot9 = turn
- term.setCursorPos(5,5)
- term.write(turn)
- if slot7 == turn and slot8 == turn and slot9 == turn or slot3 == turn and slot6 == turn and slot9 == turn or slot1 == turn and slot5 == turn and slot9 == turn then
- finish()
- break
- else
- if turn == "X" then
- turn = "O"
- else
- turn = "X"
- end
- end
- end
- end
- end
- --Code
- clear()
- drawMenu()
Advertisement
Add Comment
Please, Sign In to add comment