Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --spieler 1 O ; spieler 2 X
- j1x1=91
- j1x2=92
- j1x3=93
- j2x1=94
- j2x2=95
- j2x3=96
- j3x1=97
- j3x2=98
- j3x3=99
- i = 0
- m = peripheral.wrap("back")
- function drawfield()
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.black)
- m.clear()
- m.setCursorPos(1,1)
- m.write(getdraw(j1x1))
- m.setCursorPos(3,1)
- m.write(getdraw(j1x2))
- m.setCursorPos(5,1)
- m.write(getdraw(j1x3))
- m.setCursorPos(1,3)
- m.write(getdraw(j2x1))
- m.setCursorPos(3,3)
- m.write(getdraw(j2x2))
- m.setCursorPos(5,3)
- m.write(getdraw(j2x3))
- m.setCursorPos(1,5)
- m.write(getdraw(j3x1))
- m.setCursorPos(3,5)
- m.write(getdraw(j3x2))
- m.setCursorPos(5,5)
- m.write(getdraw(j3x3))
- m.setCursorPos(10,1)
- if i==0 then
- m.write("O")
- else
- m.write("X")
- end
- end
- function reset()
- j1x1=91
- j1x2=92
- j1x3=93
- j2x1=94
- j2x2=95
- j2x3=96
- j3x1=97
- j3x2=98
- j3x3=99
- i = 0
- drawfield()
- end
- function getdraw(x)
- if x == 1 then
- return "O"
- elseif x == 2 then
- return "X"
- else
- return "#"
- end
- end
- function testforwinner()
- if j1x1 == j1x2 and j1x1 == j1x3 then
- win(j1x1)
- elseif j2x1 == j2x2 and j2x1 == j2x3 then
- win(j2x1)
- elseif j3x1 == j3x2 and j3x1 == j3x3 then
- win(j3x1)
- elseif j1x1 == j2x1 and j1x1 == j3x1 then
- win(j1x1)
- elseif j1x2 == j2x2 and j1x2 == j3x2 then
- win(j1x2)
- elseif j1x3 == j2x3 and j1x3 == j3x3 then
- win(j1x3)
- elseif j1x1 == j2x2 and j1x1== j3x3 then
- win(j1x1)
- elseif j1x3 == j2x2 and j1x3 == j3x1 then
- win(j1x3)
- end
- end
- function win(winner)
- --zeigen wo wer gewonnen hat (blinken)
- sleep(2,5)
- if winner==1 then
- b = "O"
- else
- b= "X"
- end
- m.setBackgroundColor(colors.green)
- m.setTextColor(colors.white)
- m.setCursorPos(1,1)
- m.write(b.." gewinnt!")
- sleep(2,5)
- reset()
- end
- drawfield()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if i == 0 then
- i=1
- a=1
- else
- i=0
- a=2
- end
- if yPos == 1 then
- if xPos == 1 or xPos == 2 then
- j1x1 = a
- elseif xPos == 3 or xPos == 4 then
- j1x2 = a
- elseif xPos == 5 or xPos == 6 then
- j1x3 = a
- end
- elseif yPos == 3 then
- if xPos == 1 or xPos == 2 then
- j2x1 = a
- elseif xPos == 3 or xPos == 4 then
- j2x2 = a
- elseif xPos == 5 or xPos == 6 then
- j2x3 = a
- end
- elseif yPos == 5 then
- if xPos == 1 or xPos == 2 then
- j3x1 =a
- elseif xPos == 3 or xPos == 4 then
- j3x2 = a
- elseif xPos == 5 or xPos == 6 then
- j3x3 = a
- end
- end
- --gugen ob schon is ne?
- drawfield()
- testforwinner()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement