#include "ColorsGameState.h" #include "ColorsUI.h" #include using namespace std; void main(int argc, char *argv) { //This is the controller, the main program. It interacts with the //ColorsUI class which is the view and the ColorsGameState which is //the model/game. The work done here is kept to a minimum. Any game //changes you wish to be made should be done with the GameState and any //UI changes you wish to make should be done to the UI class. while(1) //Here we start the whole game loop! { //See if they need the rules explained ColorsUI aUI(2); //Default initialization of the UI aUI.explainRules(); //Find the number of players int numberOfPlayers= aUI.findNumPlayers(); //Initialize the game ColorsGameState aGame(numberOfPlayers); aUI.setNumPlayers(numberOfPlayers); bool gameOver = false; int moveResult; //Run the game, looping thru moves and displays until we get gameOver while (gameOver==false) { aUI.updateDisplay(aGame.playerHands,aGame.board, aGame.lastRound()); //Print current board bool takeMove; //Loop thru getting a move until we get a correct one while (1) { takeMove = aUI.getTypeMove(aGame.currentPlayer, aGame.lastRound()); //Get type of move bool acceptableMove = aGame.verifyTypeMove(takeMove); //verify type of move if (acceptableMove==true) {break;} aUI.invalidMove(aGame.currentPlayer); } int rowMove; while (1) { //get row rowMove = aUI.getRowMove(takeMove, aGame.currentPlayer, *(aGame.topOfDeck)); //verify row bool acceptableMove = aGame.verifyRowMove(takeMove, rowMove); if (acceptableMove ==true) {break;} aUI.invalidMove(aGame.currentPlayer); } //accept Move moveResult = aGame.acceptMove(takeMove, rowMove); //Now we have a valid move which has been entered //Check for win, if not, let the loop repeat if (moveResult ==1) {break;} } //Now the game is over, figure out the winner vector allScores = aGame.scoreAllPlayers(); //Calculate the scores int winningScore = aGame.getTopScore(allScores); //Calculate the top Score vector winningPlayers = aGame.getWinners(winningScore); //Find winners aUI.printScores(allScores); //Print all Scores aUI.printWinners(winningScore, winningPlayers); //Print winners //Game is now completely over, see if they want to play again //If so, we'll loop, else we'll quit; bool newGame = aUI.wantNewGame(); if (newGame==false) {return;} //else we loop } }