Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def win_sequence(current_turn):
- print(current_turn + ", you win!->")
- grid_draw()
- input('Press enter to end the game')
- global turn
- turn = 2
- def grid_draw():
- print("\n |1||2||3|")
- for rows, values in grid_h.items():
- print(f'{rows}-', end = '')
- for items in values:
- print(f"|{items}|", end = '')
- print("\n")
- def row_input():
- value = input('Type row and press enter to continue\n')
- if value != '':
- value = int(value)
- if value in accept_no:
- change_h[0] = int(value)
- change_v[1] = int(value) - 1 #-1 because it deals with the list and not the dict key
- column_input()
- else:
- row_input()
- else:
- row_input()
- def column_input():
- value = input('Type column and press enter to continue\n')
- if value != '':
- value = int(value)
- if value in accept_no:
- change_h[1] = int(value) - 1
- change_v[0] = int(value)
- else:
- column_input()
- else:
- column_input()
- def reset():
- global value
- value = 0
- global accept_no
- accept_no = [1,2,3]
- global grid_h
- grid_h = { 1: ['0','0','0'], 2: ['0','0','0'], 3: ['0','0','0']}
- global grid_v
- grid_v = { 1: ['0','0','0'], 2: ['0','0','0'], 3: ['0','0','0']}
- global turn
- turn = 1
- global player_1
- player_1 = input("Player one name:")
- global player_2
- player_2 = input("Player two name:")
- global player_turn
- player_turn = player_1
- global change_h
- change_h = [0,0] #changes with inputs
- global change_v
- change_v = [0,0]
- reset()
- while turn == 1:
- grid_draw()
- #for rows, values in grid_v.items(): #displays the vertical grid without formatting
- #print(values)
- print(f"{player_turn}, it is your turn")
- row_input()
- if player_turn == player_1:
- if grid_h[change_h[0]][change_h[1]] == '0':
- grid_h[change_h[0]][change_h[1]] = 'x'
- grid_v[change_v[0]][change_v[1]] = 'x'
- else:
- print('Area was occupied, please try again')
- row_input()
- else:
- if grid_h[change_h[0]][change_h[1]] == '0':
- grid_h[change_h[0]][change_h[1]] = 'o'
- grid_v[change_v[0]][change_v[1]] = 'o'
- else:
- print('Area was occupied, please try again')
- row_input()
- if grid_h[1] == ['x','x','x'] or grid_h[2] == ['x','x','x'] or grid_h[3] == ['x','x','x'] or grid_v[1] == ['x','x','x'] or grid_v[2] == ['x','x','x'] or grid_v[3] == ['x','x','x']:
- win_sequence(player_turn)
- if grid_h[1] == ['o','o','o'] or grid_h[2] == ['o','o','o'] or grid_h[3] == ['o','o','o'] or grid_v[1] == ['o','o','o'] or grid_v[2] == ['o','o','o'] or grid_v[3] == ['o','o','o']:
- win_sequence(player_turn)
- if grid_h[1][2] == 'x' and grid_h[2][1] == 'x' and grid_h[3][0] == 'x' or grid_h[1][0] == 'x' and grid_h[2][1] == 'x' and grid_h[3][2] == 'x':
- win_sequence(player_turn)
- if grid_h[1][2] == 'o' and grid_h[2][1] == 'o' and grid_h[3][0] == 'o' or grid_h[1][0] == 'o' and grid_h[2][1] == 'o' and grid_h[3][2] == 'o':
- win_sequence(player_turn)
- if player_turn == player_1:
- player_turn = player_2
- else:
- player_turn = player_1
- if '0' not in [x for y in grid_h.values() for x in y]:
- print("Game Over: Draw!")
- grid_draw()
- input('Press enter to end the game')
- turn = 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement