-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.py
More file actions
123 lines (105 loc) · 6.97 KB
/
Copy pathController.py
File metadata and controls
123 lines (105 loc) · 6.97 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from PlayerFactory import PlayerFactory
from GameBoard import GameBoardMaster
from Player import Player
from UserInterface import *
class Controller:
def __init__(self, interface): # Edited, doc strings needs updating
""" (interfaceTypeObject) -> Global Variables
Used for initializing objects for sequencial uses.
>>>self.interface.DisplayWelcome()
Displays the welcome message based on the type of interface being used.
>>>self.Player.PlayerMove(gameBoard, firstPlayer, secondPlayer)
Depending on the type of interface instantiated, the Player object
will pass a message to the user interface asking to move on the interfaceType
"""
self.interface = interface
self.Player = Player(interface)
self.PlayerFactory = PlayerFactory(interface)
def StartGame(self):
""" (None) -> bool
Starts game on the interface it is handed to.
>>>Main()
True
False
"""
#Display welcome message with option to continue or quit
if self.interface.DisplayWelcome() == False:
return True
#Get number of players, restart, or quit
numPlayers = self.interface.GetNumPlayers() # (range(int(0 - 2))) or (str('R' or 'Q')) based on user input
if numPlayers == 'R':
return False
elif numPlayers == 'Q':
return True
elif numPlayers == 0 or numPlayers == 1 or numPlayers == 2:
players = self.PlayerFactory.GetPlayerTypes(numPlayers) # (['playerOneComputer', 'playerTwoComputer']) or (['playerOneHuman', 'playerTwoComputer']) or (['playerOneHuman', 'playerTwoHuman'])
#Display to user the types of players
playerVsPlayerMatchConfig = self.interface.DisplayAndGetPlayerTypes(players) # (str("Computer vs Computer")) or (str("Player vs Computer")) or (str("Player vs Player")
#Assign PlayerOne and PlayerTwo as X or O
playerOneX = self.PlayerFactory.SetPlayerOneX(players) # (True) or (False)
playerTwoX = self.PlayerFactory.SetPlayerTwoX(playerOneX, players) # (True) or (False)
#Assign first and second player as a string
firstPlayerType = self.PlayerFactory.SetFirstPlayerType(players) # (str('playerOneComputer')) or (str('playerOneHuman')) or (str('playerTwoComputer')) or (str('playerTwoHuman'))
secondPlayerType = self.PlayerFactory.SetSecondPlayerType(firstPlayerType, players) # (str('playerOneHuman')) or (str('playerTwoComputer')) or (str('playerTwoHuman'))
#Initialize firstPlayer and secondPlayer as a list of configurations
firstPlayer = self.PlayerFactory.SetPlayerConfig(firstPlayerType, playerOneX, playerTwoX) # [playerType, XorO] = ['playerOneComputer', True] or ['playerOneComputer', False] or ['playerOneHuman', True] or ['playerOneHuman', False] or ['playerTwoComputer', True] or ['playerTwoComputer', False] or ['playerTwoHuman', True] or ['playerTwoHuman', False]
secondPlayer = self.PlayerFactory.SetPlayerConfig(secondPlayerType, playerOneX, playerTwoX) # [playerType, XorO] = ['playerOneComputer', True] or ['playerOneComputer', False] or ['playerOneHuman', True] or ['playerOneHuman', False] or ['playerTwoComputer', True] or ['playerTwoComputer', False] or ['playerTwoHuman', True] or ['playerTwoHuman', False]
#User Confirms Game Settings
userConfirmSettings = self.interface.ConfirmGameSettings(playerVsPlayerMatchConfig, firstPlayer, secondPlayer) # (str('Q' or 'R')) or (True) based on user input
if userConfirmSettings == 'Q':
return True
elif userConfirmSettings == 'R':
return False
#Create New Game Board
gameBoard = GameBoardMaster().CreateNewGameBoard() # [None, None, None, None, None, None, None, None, None]
#Keeps track if game is still playable or is finished
gameBoardStatus = 'Playable'
#Start playing
self.interface.DisplayBoard(gameBoard) # (None)
while gameBoardStatus == 'Playable':
if gameBoardStatus == 'Playable':
firstPlayerMove = self.Player.PlayerMove(gameBoard, firstPlayer, secondPlayer) # (int(1, 2, 3, 4, 5, 6, 7, 8, or 9)) or (str('Quit', or 'Restart')) based on player input
if firstPlayerMove == 'Quit':
return True
elif firstPlayerMove == 'Restart':
return False
gameBoard = GameBoardMaster().UpdateGameBoard(gameBoard, firstPlayerMove, firstPlayer[1]) # [slot, slot, slot, slot, slot, slot, slot, slot, slot] :: slot = (None) or (True) or (False)
self.interface.DisplayBoard(gameBoard) # (None)
gameBoardStatus = GameBoardMaster().CheckBoard(gameBoard, firstPlayer[1]) # 'Full', 'Winner', or 'Playable'
if gameBoardStatus == 'Full':
self.interface.DisplayGameDraw() # (None)
playAgain = self.interface.AskUserPlayAgain() # (True) or (False)
if playAgain == True:
return False
elif playAgain == False:
return True
elif gameBoardStatus == 'Winner':
self.interface.DisplayGameWinner(firstPlayer[0], secondPlayer[0]) # (None)
playAgain = self.interface.AskUserPlayAgain() # (True) or (False)
if playAgain == True:
return False
elif playAgain == False:
return True
if gameBoardStatus == 'Playable':
secondPlayerMove = self.Player.PlayerMove(gameBoard, secondPlayer, firstPlayer) # (int(1, 2, 3, 4, 5, 6, 7, 8, or 9)) or (str('Quit', or 'Restart')) based on player input
if secondPlayerMove == 'Quit':
return True
elif secondPlayerMove == 'Restart':
return False
gameBoard = GameBoardMaster().UpdateGameBoard(gameBoard, secondPlayerMove, secondPlayer[1]) # [slot, slot, slot, slot, slot, slot, slot, slot, slot] :: slot = (None) or (True) or (False)
self.interface.DisplayBoard(gameBoard) # (None)
gameBoardStatus = GameBoardMaster().CheckBoard(gameBoard, secondPlayer[1]) # 'Full', 'Winner', or 'Playable'
if gameBoardStatus == 'Full':
self.interface.DisplayGameDraw() # (None)
playAgain = self.interface.AskUserPlayAgain() # (True) or (False)
if playAgain == True:
return False
elif playAgain == False:
return True
elif gameBoardStatus == 'Winner':
self.interface.DisplayGameWinner(secondPlayer[0], firstPlayer[0]) # (None)
playAgain = self.interface.AskUserPlayAgain() # (True) or (False)
if playAgain == True:
return False
elif playAgain == False:
return True