Question

In: Computer Science

My assignment is to program the movment around a monopoly board, with three players. After rolling...

My assignment is to program the movment around a monopoly board, with three players. After rolling the two dice, player 1 moves and so fourth. Any solutions for this code would be great. It doesnt matter what they land on, just the number of spaces and taking turns. the coding is C++, the requierments are very basic, there need to be no specification on rather the movements acuacly means. Just rolling a die and sneding player one to space 6 after rolling a three and another three at the same time. A monopoly board as 40 spaces, a 10x10. each player takes turns rolling, and move to where ever they roll.

Solutions

Expert Solution

Please find the requested program below. Also including the screenshot of sample output and screenshot of code to understand the indentation.

Please provide your feedback
Thanks and Happy learning!

#include <iostream>
#include <string>
#include <time.h>

class Player
{
private:
    int m_currentPosition;
    std::string m_name;
public:
    Player(std::string playerName) : m_name(playerName), m_currentPosition(0)
    {
        srand(time(NULL));
    }

    //Assuming the start position as zero(0).
    //If the current position is more than the number of
    //cells in the board(ie 40) then wrap around to the first position(ie 0th position)
    void moveCurrentPosition(int numOfPlacesToMove)
    {
        std::cout << "Moving the current position of " << m_name << " by " << numOfPlacesToMove << std::endl;
        m_currentPosition = (m_currentPosition + numOfPlacesToMove) % 40;
    }

    void play()
    {
        std::cout <<"-------------------------------------------" << std::endl;
        std::cout << m_name << " turn : " << std::endl;

        //roll the dice;
        //Generate a random value between 1 and 6
        int dice1Reading = std::rand() % 6 + 1;
        int dice2Reading = std::rand() % 6 + 1;

        std::cout << "Current position of " << m_name << " : " << std::endl;
        printPlayerCurrentState();
        std::cout << m_name << " dice 1 reading " << dice1Reading << std::endl;
        std::cout << m_name << " dice 2 reading " << dice2Reading << std::endl;

        moveCurrentPosition(dice1Reading + dice2Reading);
        std::cout << "New position of " << m_name << " : " << std::endl;
        printPlayerCurrentState();
        std::cout << "-------------------------------------------" << std::endl;
    }

    void printPlayerCurrentState()
    {
        std::cout << "\t" << m_name << " is at position " << m_currentPosition << std::endl;
    }

};


int main()
{
    Player p1("Player 1");
    Player p2("Player 2");
    Player p3("Player 3");

    //Currently each player plays only one time.
    //If we want to make the game to go on until
    //the user presses Ctr-C, then uncomment the
    //while loop below.
    //while (1)
    //{ 
        p1.play();
        p2.play();
        p3.play();
    //}

    return 0;
}

Related Solutions

Here is my assignment: Write a program that generates a random number between 1 and 50...
Here is my assignment: Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials...
ok here is my homework This assignment focuses on file streams. Your program will accept the...
ok here is my homework This assignment focuses on file streams. Your program will accept the name of an input file from the user, and the name of an output file from the user. You may assume the input file contains no more than 100 lines. Your program will write the lines of the input file to the output file in reverse line order, i.e. the first line of the input file becomes the last line of the output file,...
I am struggling with this assignment for my java class. Objectives: Your program will be graded...
I am struggling with this assignment for my java class. Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1.Create a new project and class in Eclipse and add the main method. (5 points) 2. Construct a Scanner to read input from the keyboard. (5 points) 3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their...
You have one boxcar rolling into a string of three stationary boxcars. After interaction, they all...
You have one boxcar rolling into a string of three stationary boxcars. After interaction, they all couple together and move off to the right, heading for Chicago. Here are the specs: Mass: 20,000 kg All four boxcars have the same mass. Initial conditions: Boxcar 1 has velocity v1 = 8 m/sec, rightward Other three are stationary, v2 = 0, v3 = 0, v4 = 0. Final condition: All four move off together as a combo vcombo = ? So.. what...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
A bowling team consists of five players. Each player bowls three games. Write a program, in...
A bowling team consists of five players. Each player bowls three games. Write a program, in python, that uses a nested loop to enter each player’s name and individual scores (for three games). You will use one variable for the name and only one variable to enter the scores. Do not use score1, score2, and score3. Compute and display the bowler’s name and average score. Also, calculate and display the average team score. YOU MUST USE A NESTED LOOP FOR...
Using energia software Write a program for your MSP430 board to will perform the following three...
Using energia software Write a program for your MSP430 board to will perform the following three tasks: 1. Input: Take a character string as user input through the serial interface. 2. Processing: Convert the entire string to lower case, and 3. Output: Return the processed string to serial output, which will be displayed on your computer monitor. Example: If the input character string is, “Here I am”, the output should be, “here i am”. For serial input and output purpose,...
my program should work for ANY NUMBER OF WORKERS..after all worker gross and net pay have...
my program should work for ANY NUMBER OF WORKERS..after all worker gross and net pay have been calculated, you should display the total number of workers, the total gross pay, and the total net pay. Employee ID Employee Name The number of hours worked The Employees hourly wage… i used while loop EmpName= input(str("PLease enter Employee name: or press -1 to exit: ")) while EmpName != "-1": EmpID= input("Enter Employee ID: ") how do i write this in a list...
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides....
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides. Have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a...
A survey reported that the mean starting salary for college graduates after a three-year program was...
A survey reported that the mean starting salary for college graduates after a three-year program was $35,710.Assume that the distribution of starting salaries follows the normal distribution with a standard deviation of $3320. What percentage of the graduates have starting salaries: (Round z-score computation to 2 decimal places and the final answers to 4 decimal places.) a. Between $31,800 and $39,200? Probability b. More than $43,600? Probability c. Between $39,200 and $43,600? Probability
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT