Steuerung über W, A, S, D für den Cursor, Leertaste zum Setzen und Q zum Beenden.
Mir ist sonst grad nichts besseres für PureGolf eingefallen.
Regeln wie gehabt:
1. EnableExplicit muss bleiben.
2. Von außen her muss alles exakt gleich aussehen und reagieren.
3. Die Summe der Längen aller Zeilen nach Anwenden von Trim() sind ausschlaggebend.
4. Ich glaub sonst gab's nix.
Code: Alles auswählen
EnableExplicit
Enumeration
#Empty
#Circle
#Cross
EndEnumeration
Dim Field(2, 2)
Procedure drawField(Array Field.i(2), curRow.i, curCol.i, lastAction.i, winner.i, curPlayer.i)
Protected row.i, col.i, s.s
ClearConsole()
ConsoleLocate(1, 1)
ConsoleColor(7, 0)
PrintN(" | |")
PrintN(" | |")
PrintN(" | |")
PrintN("---+---+---")
PrintN(" | |")
PrintN(" | |")
PrintN(" | |")
PrintN("---+---+---")
PrintN(" | |")
PrintN(" | |")
PrintN(" | |")
If ((ElapsedMilliseconds() - lastAction) / 500) % 2 = 0 And winner = -1
If Field(curRow, curCol) <> #Empty
ConsoleColor(4, 0)
EndIf
ConsoleLocate(curCol * 4 + 1, curRow * 4 + 1)
Print("---")
ConsoleLocate(curCol * 4 + 1, curRow * 4 + 2)
Print("| |")
ConsoleLocate(curCol * 4 + 1, curRow * 4 + 3)
Print("---")
EndIf
ConsoleColor(15, 0)
For row = 0 To 2
For col = 0 To 2
ConsoleLocate(col * 4 + 2, row * 4 + 2)
Select Field(row, col)
Case #Circle
Print("O")
Case #Cross
Print("X")
EndSelect
Next
Next
ConsoleLocate(13, 2)
If winner <> -1
If winner = #Circle
s = "O"
ElseIf winner = #Cross
s = "X"
EndIf
Print(s + " hat gewonnen!")
ConsoleLocate(13, 3)
Print("Nochmal? (J/N)")
Else
If curPlayer = 0
s = "O"
ElseIf curPlayer = 1
s = "X"
EndIf
Print(s + " ist am Zug.")
EndIf
EndProcedure
Procedure resetField(Array Field.i(2))
Protected row.i, col.i
For row = 0 To 2
For col = 0 To 2
Field(row, col) = #Empty
Next
Next
EndProcedure
Procedure checkWin(Array Field.i(2))
Protected content.i, row.i, col.i
For row = 0 To 2
content = Field(row, 0)
If Field(row, 1) = content And Field(row, 2) = content And content <> #Empty
ProcedureReturn content
EndIf
Next
For col = 0 To 2
content = Field(0, col)
If Field(1, col) = content And Field(2, col) = content And content <> #Empty
ProcedureReturn content
EndIf
Next
content = Field(0, 0)
If Field(1, 1) = content And Field(2, 2) = content And content <> #Empty
ProcedureReturn content
EndIf
content = Field(2, 0)
If Field(1, 1) = content And Field(0, 2) = content And content <> #Empty
ProcedureReturn content
EndIf
ProcedureReturn -1
EndProcedure
Define curCol.i = 0, curRow.i = 0
Define input.s
Define curPlayer.i = 0
Define lastAction.i = ElapsedMilliseconds()
Define winner.i
If OpenConsole()
EnableGraphicalConsole(1)
ConsoleCursor(0)
resetField(Field())
Repeat
drawField(Field(), curRow, curCol, lastAction, winner, curPlayer)
Delay(50)
input.s = Inkey()
If input
lastAction = ElapsedMilliseconds()
EndIf
winner = checkWin(Field())
If winner = -1
Select input
Case "q"
Break
Case " "
If Field(curRow, curCol) = #Empty
If curPlayer = 0
Field(curRow, curCol) = #Circle
curPlayer = 1
Else
Field(curRow, curCol) = #Cross
curPlayer = 0
EndIf
EndIf
Case "w"
curRow = (curRow + 2) % 3
Case "a"
curCol = (curCol + 2) % 3
Case "s"
curRow = (curRow + 1) % 3
Case "d"
curCol = (curCol + 1) % 3
EndSelect
Else
Select input
Case "n"
Break
Case "j"
resetField(Field())
curPlayer = 0
EndSelect
EndIf
ForEver
EndIf