#include #include #include "ColorsUI.h" using namespace std; //The only constructor ColorsUI::ColorsUI(int numberOfPlayers) { numPlayers = numberOfPlayers; } int ColorsUI::findNumPlayers() { //Queries the user for the number of players //Hardcoded to only accept 2-5 //Returns the number of players desired //Note cin can hang when text is entered and it's expecting numbers //so I'll use getline //Find the number of players cout << "Enter number of players (2-5): "; int numberOfPlayers=0; char buffer[1000]; cin.sync(); cin.getline(buffer, sizeof(buffer)); numberOfPlayers = atoi(buffer); while (1) { if ((numberOfPlayers>=2)&&(numberOfPlayers<=5)) {break;} cout << "Please enter the number of players (2-5): "; cin.getline(buffer, sizeof(buffer)); numberOfPlayers = atoi(buffer); } return numberOfPlayers; } void ColorsUI::updateDisplay(vector playerHands, vector board, bool lastRound) { //Displays the board given the information passed in for (int i=0; i<4; i++) {cout << endl;} //Put some spaces //Print out the rows if (lastRound==true) {cout << "LAST ROUND!!" << endl;} cout << "Current board" <> playerAction; if ((playerAction[0]== 'D')||(playerAction[0]== 'd')) {return false;} if ((playerAction[0]== 'T')||(playerAction[0]== 't')) {return true;} cout << "Invalid action!" << endl; } } int ColorsUI::getRowMove(bool take, int currentPlayer, int topCard) { //Gets the row the current move affects and returns an int, 0-based //Note cin can hang when text is entered and it's expecting numbers //so I'll use getline //Print out the next card if they chose to draw a card if (take==false) { cout << endl; cout << "The card drawn is "; cout << cardValues[topCard] << endl; cout << "Please enter the row to place it on: "; } else { cout << "Please enter the row to take: "; } int rowTaken=0; char buffer[1000]; cin.sync(); cin.getline(buffer, sizeof(buffer)); rowTaken = atoi(buffer); return rowTaken-1; //Note our internal numbering starts at 0 } void ColorsUI::invalidMove(int currentPlayer) { //Complains when an invalid move is done cout << "Invalid Move!!!" << endl; cin.sync(); return; } void ColorsUI::explainRules() { //Checks to see if they want the rules explained and then does so //This is the console version so we'll ask in text and print the rules //out in pages cout << "Would you like to hear the rules? (Y/N) "; string answer; cin >> answer; //The default is yes, unless they type n, or no. if ((answer[0]=='n')||(answer[0]=='N')) {return;} //Now explain the rules in pages, doing a "press any key to continue" //I'm assuming their console will have a scroll bar if they need to backtrack cout << "Colors is a card collecting game for 2-5 players. There are 76 colored cards in the deck. "; cout << "There are 7 colors: (R)ed, (G)reen, (B)lue, (Y)ellow, (P)ink, (S)ilver, (V)iolet "; cout << "with 9 cards of each color in the deck. There are also 3 wilds and 8 cards worth +2 points. "; cout << "The goal is to have the highest score at the end by collecting as many as you can of any three colors, "; cout << "but beware, any other colored cards you collect count negatively. Wilds can count as any color and you "; cout << "do not have to specify the color until the end of the game."; cout << endl; char anyKey[1000]; cout << "Press enter to continue; "; cin.sync(); cin.getline(anyKey,1000); cout << endl; cout << "The game is played in rounds. Cards are drawn one at a time from a face down deck and played in rows on the board by the players. "; cout << "Each round a player may take *one* row into his score pile; after he or she does this, they are completely out of the round. "; cout << "After every player has taken a row, the next round begins and everyone gets to play again. "; cout << "Thus there are as many rows as players in each round. "; cout << "Player proceeds clockwise from whichever player is chosen to go first in the first round. In subsequent rounds, "; cout << "the player to the left of the last player to take a row goes first. On a player's turn, he may either 1)Draw the top card "; cout << "of the deck AND place it on any one of the non-full rows on the board (rows may only hold up to 3 cards) OR 2)Take one "; cout << "nonempty row from the board into his score pile (and he is then out for the rest of the round). It is then the next player's turn. "; cout << "Play continues in this way until the round is over. By now, every player has taken a row, so the board is clear and the next round starts immediately. "; cout << endl; cout << "Press enter to continue; "; cin.sync(); cin.getline(anyKey,1000); cout << endl; cout << "Clearly, when playing cards, a player should take into account the colors each of the other players appear to be collecting. He or she does not want "; cout << "to build a row that is ideal to another player. The cards players collect in their score piles are public and must be visible at all times. A player "; cout << "does not have to declare what colors they are collecting until the end of the game and thus may change their mind at any time. "; cout << "Cards can NEVER be removed from a score pile, however, so take rows with caution. "; cout << "Wilds are very valuable as they can be added to any color's stack in your score pile at the end of the game. The +2 points cards are "; cout << "simply added to your score at the end of the game. The game is over when the last round is over. You know you are on the last round when "; cout << "there are no longer enough cards to guarantee that another round can be completed after the current one (i.e. there are not at least 3 * numberOfPlayers cards left in the deck. "; cout << "The game will announce when the current round is definitely the last round. "; cout << endl; cout << "Press enter to continue; "; cin.sync(); cin.getline(anyKey,1000); cout << endl; cout << "Scoring!: " << endl; cout << "After the end of the last round, each player declares which three colors he or she would like scored positively, without fail these are the colors with the most cards. "; cout << "Each of these three *colors* is scored according to the chart below. Notice that it is not linear; specialization is good. Now, the other four colors for each player are also scored according to the chart "; cout << "but negatively! Wilds are added to the positive scoring color of your choice before you score it. Note that you get no bonus for having more than 6 of any one color. "; cout << "Each +2 points card simply adds two points to your score at the end. Now, the player with the highest score wins! " << endl; cout << "Scoring Table" << endl; cout << "# of cards \tScore" << endl; cout << "1 \t1" << endl; cout << "2 \t3" << endl; cout << "3 \t6" << endl; cout << "4 \t10" << endl; cout << "5 \t15" << endl; cout << "6-9 \t21" << endl; cout << endl; cout << "Press enter to play; "; cin.sync(); cin.getline(anyKey,1000); cout << endl; return; } void ColorsUI::printScores(vector allScores) { //Prints out all the scores at the end cout << endl; cout << "Scores" << endl; for (int i=0; i< numPlayers; i++) {cout << "Player " << i+1 << " scored " << allScores[i] << endl;} //Remember the players are numbered internally starting at 0. return; } void ColorsUI::printWinners(int topScore, vector winners) { //Prints out the winners! cout << endl; cout << "The winner"; int numWinners = winners.size(); //if there is only 1 winner... if (numWinners==1) { cout << " is Player "; cout << winners[0]; cout << " with a score of "<< topScore << "!" << endl; return; } //else there are multiple winners cout << "s are "; //Print out all but the last one for (int i=0; i> answer; if ((answer[0]=='y')||(answer[0]=='Y')) {return true;} //else return false; }