@@ -13,7 +13,7 @@ def playGame(): Unit = {
1313
1414 // Returns the chosen Game Mode
1515 def chooseGameMode(): GameMode / {WrongInput} = {
16- println("Choose the Game Mode:\n[1 - 2 Players , 2 - vs Computer]:")
16+ println("Choose the Game Mode:\n[1 - Local , 2 - vs Computer]:")
1717 val side = consoleInput()
1818 side match {
1919 case "1" => Local()
@@ -100,7 +100,7 @@ def playGame(): Unit = {
100100 currentSmallBoard = chooseSmallBoard(gameBoard)
101101 gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
102102 } else {
103- println("Opponent is starting the game!\nChoose the starting Small Board. ")
103+ println("Opponent is starting the game!\n ")
104104 if (gameMode is Computer()){
105105 currentSmallBoard = computerPlay(gameBoard.smallCopy, computer)
106106 gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
@@ -112,23 +112,21 @@ def playGame(): Unit = {
112112
113113 // INNER GAME LOOP OF ONE GAME
114114 while (not(endGame)){
115+ with on[OutOfBounds].panic
116+
117+ // Choose the new Small Board
115118 if (currentSmallBoard == 10) {
116- if (isComputerTurn(currentPlayer, computer)){
117- currentSmallBoard = computerPlay(gameBoard.smallCopy, computer)
118- gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
119- }
120- printGameScreen(gameBoard, currentPlayer)
121- currentSmallBoard = chooseSmallBoard(gameBoard)
119+ if (gameMode is Computer()) if (isComputerTurn(currentPlayer, computer)) currentSmallBoard = computerPlay(gameBoard.smallCopy, computer)
120+ else currentSmallBoard = chooseSmallBoard(gameBoard)
122121 gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
123122 }
124123
125- // Before The Player's Move
124+ // The Move Phase
126125 printGameScreen(gameBoard, currentPlayer)
127- currentCell = chooseCell (gameBoard, currentSmallBoard)
128- gameBoard = checkNewCell (gameBoard, currentSmallBoard, currentCell, currentPlayer )
126+ if(gameMode is Computer()) if (isComputerTurn(currentPlayer, computer)) currentCell = computerPlay (gameBoard.bigBoard.get(currentSmallBoard), computer)
127+ else currentCell = chooseCell (gameBoard, currentSmallBoard)
129128
130- // Check the winning situation
131- with on[OutOfBounds].panic
129+ gameBoard = checkNewCell(gameBoard, currentSmallBoard, currentCell, currentPlayer)
132130 checkWinSituation(gameBoard.bigBoard.get(currentSmallBoard - 1), currentPlayer) match {
133131 case Win() => {
134132 println("\nYou won the Small Board!")
@@ -146,19 +144,18 @@ def playGame(): Unit = {
146144 // After The Player's Move
147145 printGameScreen(gameBoard, currentPlayer)
148146 println("Excellent Move! Now Press the Enter to finish your turn.")
149-
150147 consoleInput()
151148
152149 // Change the Current Small Board
153150 if (checkAvailableCell(gameBoard.smallCopy, currentCell)){
154151 gameBoard = deactivateSmallBoard(gameBoard, currentSmallBoard)
155152 currentSmallBoard = currentCell
156153 gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
157- currentCell = 10
158154 } else {
159155 gameBoard = deactivateSmallBoard(gameBoard, currentSmallBoard)
160156 currentSmallBoard = 10
161157 }
158+ currentCell = 10
162159
163160 // Verify if the game has been won
164161 if (checkWinSituation(gameBoard.smallCopy, currentPlayer) is Win()){
@@ -218,7 +215,6 @@ def playGame(): Unit = {
218215 println(msg)
219216 resume(())
220217 }
221- ()
222218 }
223219 println("Goodbye!")
224220}
0 commit comments