Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#pragma once #include // // PLAYER_COUNT_MIN // // The minimum number of players in the game. // const unsigned int PLAYER_COUNT_MIN = 1; // //

image text in transcribed

#pragma once #include  // // PLAYER_COUNT_MIN // // The minimum number of players in the game. // const unsigned int PLAYER_COUNT_MIN = 1; // // PLAYER_COUNT_MAX // // The maximum number of players in the game. // const unsigned int PLAYER_COUNT_MAX = 4; // // NO_SUCH_PLAYER // // A special value indicating that there was not a player with // the requested name. // const unsigned int NO_SUCH_PLAYER = 999999; // // playerInit // // Purpose: To initialize the Player module for the specified // players. Each player starts with $0 money, #1 die, // and *0 points. // Parameter(s): //  count: The number of players in the game //  names: The player names // Precondition(s): //  count >= PLAYER_COUNT_MIN //  count  names[i] != "" WHERE 0  isInitialized() // Returns: How many players in the game. // Side Effect: N/A // unsigned int playerGetCount (); // // playerGetIndex // // Purpose: To determine the index of the player with the // specified name. // Parameter(s): //  name: The player name // Precondition(s): //  isInitialized() //  name != "" // Returns: The index of the player with name name. If there // isn't a player with that name, NO_SUCH_PLAYER is // returned. // Side Effect: N/A // unsigned int playerGetIndex (const std::string& name); // // playerPrint // // Purpose: To print the information for the specified player. // Parameter(s): //  player_index: Which player // Precondition(s): //  isInitialized() //  player_index  player_index: Which player // Precondition(s): //  isInitialized() //  player_index  player_index: Which player // Precondition(s): //  isInitialized() //  player_index  player_index: Which player //  money: How much money to check for // Precondition(s): //  isInitialized() //  player_index  money >= 0 // Returns: Whether player player_index has at least money // money. // Side Effect: N/A // bool playerHasMoney (unsigned int player_index, int money); // // playerHasDice // // Purpose: To determine if the specified player has at least // the specified number of dice. // Parameter(s): //  player_index: Which player //  dice: How many dice to check for // Precondition(s): //  isInitialized() //  player_index  dice >= 0 // Returns: Whether player player_index has at least dice dice. // Side Effect: N/A // bool playerHasDice (unsigned int player_index, int dice); // // playerHasPointsAny // // Purpose: To determine if any player has at least the // specified number of points. // Parameter(s): //  points: How many points to check for // Precondition(s): //  isInitialized() //  points >= 0 // Returns: Whether any player has at least points points. // Side Effect: N/A // bool playerHasPointsAnyone (int points); // // playerIncreaseMoneyAndPrint // // Purpose: To give the specified player the specified amount // of additional money. // Parameter(s): //  player_index: Which player //  increase: How much money to give the player // Precondition(s): //  isInitialized() //  player_index  increase >= 0 // Returns: N/A // Side Effect: Player player_index gains increase money. The // change to the player's money is printed, // including the player name. // void playerIncreaseMoneyAndPrint (unsigned int player_index, int increase); // // playerIncreaseDiceAndPrint // // Purpose: To give the specified player the specified number // of additional dice. // Parameter(s): //  player_index: Which player //  increase: How many dice to give the player // Precondition(s): //  isInitialized() //  player_index  increase >= 0 // Returns: N/A // Side Effect: Player player_index gains increase dice. The // change to the player's number of dice is // printed, including the player name. // void playerIncreaseDiceAndPrint (unsigned int player_index, int increase); // // playerIncreasePointsAndPrint // // Purpose: To give the specified player the specified number // of additional points. // Parameter(s): //  player_index: Which player //  increase: How many points to give the player // Precondition(s): //  isInitialized() //  player_index  increase >= 0 // Returns: N/A // Side Effect: Player player_index gains increase points. The // change to the player's points is printed, // including the player name. // void playerIncreasePointsAndPrint (unsigned int player_index, int increase); // // playerDecreaseMoney // // Purpose: To reduce the specified player's money by the // specified amount. // Parameter(s): //  player_index: Which player //  decrease: How much money to take from the player // Precondition(s): //  isInitialized() //  player_index  decrease >= 0 //  playerHasdDice(player_index, decrease) // Returns: N/A // Side Effect: Player player_index loses decrease money. // void playerDecreaseMoney (unsigned int player_index, int decrease); // // playerDecreaseDice // // Purpose: To reduce the specified player's number of dice by // the specified amount. // Parameter(s): //  player_index: Which player //  decrease: How many dice to take from the player // Precondition(s): //  isInitialized() //  player_index  decrease >= 0 //  playerHasdDice(player_index, decrease) // Returns: N/A // Side Effect: Player player_index loses decrease dice. // void playerDecreaseDice (unsigned int player_index, int decrease);
Add #include "Player.h" to your Main.cpp file. Near the beginning of main, declare an array to hold two player names. Place two names in the array. You may use any names you like as long as they start with different letters. Then initialize the player module by calling playerInit, passing the array of player names as the second parameter. Remove the array of player money from Assignment 1. Keep your existing code that calculates how much money the player should get. When the player gains money, call the playerIncreaseMoneyAndPrintfunction. Remove any lines in your code that refer to the array of player money from Assignment 1. To print the player money at the end of the program, call the playerPrint function. Hint: The playerPrint function also prints additional information. When a player's turn starts, print the player name instead of "Player X". Use the playerGetName function rather than your name array. For example, if the player was named "Lin", the message could be printed as: Lin's turn: Add #include "Player.h" to your Main.cpp file. Near the beginning of main, declare an array to hold two player names. Place two names in the array. You may use any names you like as long as they start with different letters. Then initialize the player module by calling playerInit, passing the array of player names as the second parameter. Remove the array of player money from Assignment 1. Keep your existing code that calculates how much money the player should get. When the player gains money, call the playerIncreaseMoneyAndPrintfunction. Remove any lines in your code that refer to the array of player money from Assignment 1. To print the player money at the end of the program, call the playerPrint function. Hint: The playerPrint function also prints additional information. When a player's turn starts, print the player name instead of "Player X". Use the playerGetName function rather than your name array. For example, if the player was named "Lin", the message could be printed as: Lin's turn

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions

Question

3. Tactical/strategic information.

Answered: 1 week ago

Question

Describe the nature of negative messages.

Answered: 1 week ago