implemented game mode
This commit is contained in:
parent
616f3a8db5
commit
01d07da8f3
1 changed files with 43 additions and 5 deletions
|
|
@ -1,12 +1,50 @@
|
|||
from .main import Board
|
||||
# noinspection PyUnresolvedReferences
|
||||
from main import Board
|
||||
|
||||
|
||||
def loadboards():
|
||||
boards = {}
|
||||
with open('boards.bds', 'r') as infile:
|
||||
for line in infile.readlines():
|
||||
readline = line.split('|')
|
||||
boards[readline[0]] = readline[1].replace('\n', '')
|
||||
return boards
|
||||
|
||||
|
||||
end = False
|
||||
board = [0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0]
|
||||
b = Board(barray=board)
|
||||
boards = loadboards()
|
||||
|
||||
pos = boards[b.printversion]
|
||||
b.board[int(pos)] = 1
|
||||
b.refresh()
|
||||
print(b)
|
||||
print('----------------------')
|
||||
|
||||
while not end:
|
||||
if b.full and b.winner is 0:
|
||||
print('Draw!')
|
||||
end = True
|
||||
else:
|
||||
n = int(input('Enter field: '))
|
||||
if n > 8:
|
||||
print('haha.')
|
||||
else:
|
||||
if b.board[n] is not 0:
|
||||
print('This field is already used.')
|
||||
else:
|
||||
b.board[n] = -1
|
||||
b.refresh()
|
||||
print(b)
|
||||
print('----------------------')
|
||||
pos = boards[b.printversion]
|
||||
b.board[int(pos)] = 1
|
||||
b.refresh()
|
||||
print(b)
|
||||
print('----------------------')
|
||||
if b.winner is not 0:
|
||||
print(str(b.winner) + ' won!')
|
||||
end = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue