Question: Computer Science Use C++ to code a simple game outlined below. Each PLAYER has: - a name - an ability level (0, 1, or 2)

Computer Science

Use C++ to code a simple game outlined below.

Each PLAYER has: - a name - an ability level (0, 1, or 2) - a player status (0: normal ; 1: captain) - a score

Each TEAM has: - a name - a group of players - a total team score - exactly one captain

Whenever a player has a turn, they get a random score: - ability level 0: score is equally likely to be 0, 1, 2, or 3 - ability level 1: score is equally likely to be 2, 3, 4, or 5 - ability level 2: score is equally likely to be 4, 5, 6, or 7

Whenever a TEAM has a turn - every "normal" player on the team gets a turn - the captain gets two turns

A competition goes as follows: - players are created - two teams are created - a draft is conducted in which each team picks players - the competition has 5 rounds - during each round, each team gets a turn (see above) - at the end, team with the highest score wins

You should writethe classes for player and team so that all three test cases work. For best results, start small. Get "player" to work, then team, then the game. Likewise, for "player", start with the constructor and then work up from three Test as you go.

Note: min + (rand() % (int)(max - min + 1)) ... generates a random integer between min and max, inclusive

Feel free to add other helper functions or features or whatever if that helps.

The "vector" data type in C++ can be very helpful here.

Starter code can be found below. Base the code off of the provided work.

File: play_game.cpp

#include

#include "player.cpp"

#include "team.cpp"

using namespace std;

void test_case_1();

void test_case_2();

void test_case_3();

int main(){

// pick a test case to run, orcreate your own

test_case_1();

test_case_2();

test_case_3();

return 0;

}

// Test ability to createplayers

void test_case_1(){

cout << "********** Test Case 1 **********" << endl;

// create a player

player alice("Alice Adams");

// reset player's score to zero

alice.reset_score();

// set player's ability (0, 1, or 2)

alice.set_ability(0);

// player gets a single turn (score is incremented by a random number)

alice.play_turn();

// return the player's score

int score = alice.get_score();

// display the player's name and total score

alice.display();

cout << endl;

}

// Test ability to create teams

void test_case_2(){

cout << "********** Test Case 2 **********" << endl;

// create players by specifying name and skill level

player* alice = new player("Alice Adams" , 0);

player* brett = new player("Brett Booth" , 2);

player* cecil = new player("Cecil Cinder" , 1);

// create team

team the_dragons("The Dragons");

// assign players to teams, set Brett as the captain

the_dragons.add_player(alice , 0);

the_dragons.add_player(brett , 1);

the_dragons.add_player(cecil , 0);

// play five turns

for (int i = 0 ; i<5 ; i++)

the_dragons.play_turn();

// display total result

cout << the_dragons.get_name() << " scored " << the_dragons.get_score() << endl;

// destroy the players!

delete alice, brett, cecil;

cout << endl;

}

// Play a sample game

void test_case_3(){

cout << "********** Test Case 3 **********" << endl;

// step 1 create players

// this time I'll use a loop to make it easier. We'll make 20 players.

// to make things easier we'll assign them all the same ability level

player* player_list[20];

for (int i = 0 ; i<20 ; i++)

player_list[i] = new player("Generic Name" , 2);

// step 2 create teams

team the_dragons("The Dragons");

team the_knights("The Knights");

// step 3 pick teams (the draft)

the_dragons.add_player(player_list[0] , 1); // team 1 gets a captain

for (int i = 1 ; i < 10 ; i++)

the_dragons.add_player(player_list[i],0); // team 1 gets nine normal players

the_knights.add_player(player_list[10] , 1); // team 2 gets a captain

for (int i = 11 ; i < 20 ; i++)

the_knights.add_player(player_list[i],0); // team 2 gets nine normal players

// step 4 - play the game! 5 rounds:

for (int i = 0 ; i < 5 ; i++){

the_dragons.play_turn();

the_knights.play_turn();

}

// step 5 - pick the winner

if (the_dragons.get_score() > the_knights.get_score() )

cout << the_dragons.get_name() << " win!" << endl;

else if (the_knights.get_score() > the_dragons.get_score() )

cout << the_knights.get_name() << " win!" << endl;

else

cout << "its a tie!" << endl;

cout << endl;

}

File: player.cpp

#ifndef _PLAYER_

#define _PLAYER_

class player{

private:

public:

};

#endif

File: team.cpp

#ifndef _TEAM_

#define _TEAM_

#include "player.cpp"

class team{

private:

public:

};

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!