Tic-Tac-Toe/main.py

38 lines
693 B
Python
Raw Normal View History

2020-12-20 01:53:52 +01:00
"""
| |
-|-|-
| |
-|-|-
| |
"""
2020-12-20 02:13:38 +01:00
class TicTacToe:
def __init__(self):
self.state = list(" "*9)
2020-12-20 01:53:52 +01:00
2020-12-20 02:13:38 +01:00
def print(self):
board = ""+ self.state[0] +"|"+self.state[1] +"|"+self.state[2] +" \n-|-|-\n"+self.state[3] +"|"+self.state[4] +"|"+self.state[5] +"\n-|-|-\n"+self.state[6] +"|"+self.state[7] +"|"+self.state[8] +"\n"
2020-12-20 01:53:52 +01:00
2020-12-20 02:13:38 +01:00
print(board)
def make_move(self, token, field):
if self.state[field] == " ":
self.state[field] = token
else:
print("This field's taken.")
game = TicTacToe()
game.print()
game.make_move("X", 0)
game.print()
# make_move(state, "X", 0)
# print_board(state)
# make_move(state, "O", 3)
# print_board(state)
# make_move(state, "X", 0)
# print_board(state)