-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (55 loc) · 2.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
board_list = ["Algebra", ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
current_player = 'X'
def introduction():
print('-------------------------------------------------')
print('----- Krizic - Kruzic [ Terminal igra ] -----')
print('-------------------------------------------------')
print('Odaberite broj 1 - 9 za postavljanje \'X\' ili \'O\'\n')
def draw_board():
print(
f' {board_list[1]} | {board_list[2]} | {board_list[3]}\n'
f'---|---|---\n'
f' {board_list[4]} | {board_list[5]} | {board_list[6]}\n'
f'---|---|---\n'
f' {board_list[7]} | {board_list[8]} | {board_list[9]}'
)
def gameplay():
global current_player
while True:
print(f'Trenutno igra: {current_player}\n')
draw_board()
board_position = int(input('>> '))
if board_list[board_position] == ' ':
board_list[board_position] = current_player
else:
print('Celija je zauzeta, odaberite drugo polje')
if (board_list[1] == board_list[2] == board_list[3] != ' ' or
board_list[4] == board_list[5] == board_list[6] != ' ' or
board_list[7] == board_list[8] == board_list[9] != ' ' or
board_list[1] == board_list[4] == board_list[7] != ' ' or
board_list[2] == board_list[5] == board_list[8] != ' ' or
board_list[3] == board_list[6] == board_list[9] != ' ' or
board_list[1] == board_list[5] == board_list[9] != ' ' or
board_list[3] == board_list[5] == board_list[7] != ' '):
print(f'Igra je gotova! \'{current_player}\' pobjeduje!')
print('Zelite li ponovno igrati? "D(Da) / N(Ne)"')
restart_input = input('>> ').upper()
if restart_input == 'D':
restart()
elif ' ' not in board_list:
print('Igra je gotova! Izjednaceno!')
print('Zelite li ponovno igrati? "D(Da) / N(Ne)"')
restart_input = input('>> ').upper()
if restart_input == 'D':
restart()
else:
if current_player == 'X':
current_player = 'O'
else:
current_player = 'X'
def restart():
global board_list
board_list = ["Algebra", ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
gameplay()
introduction()
gameplay()