Question

In: Computer Science

can someone code this problem please? Introduction Students will create a C++ program that simulates a...

can someone code this problem please?

Introduction

Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP).

Scenario

You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo.

You need to create a simple Pokemon battle simulation that will run until one of the pokemon’s health points (HP) reaches 0. In the simulation, the player’s Pikachu will battle the enemy Mewtwo. The Mewtwo will always be the first one to attack, then you’ll attack, and so on until the simulation ends (one of the players runs out of health points). Additionally, Mewtwo will only use one attack on the player, whereas the player's Pikachu has 3 attack options. They can either use “Thundershock”, “Quick Attack”, or “Electro Ball”. Once the battle is over, you will be greeted with the message “You win” or “You lose” depending on whether or not the player’s pokemon won the battle.

Instructions to complete the assignment

Your code must perform these major operations:

  • Utilize a while loop to continuously get each person’s turn (player and CPU)
  • Use OOP to create a Pokemon object, allowing 3 attacks which are to be made using functions
  • Use an array to hold the move structs in your Pokemon class
  • Using print statements that reflect the status of the battle

Move.h (Move Struct) Each move struct must have the following attributes:

  • Name (string)
  • Damage (int)

Pokemon.h and Pokemon.cpp (Pokemon Class) Each pokemon class must have the following (pritvate) attributes:

  • Name (string)
  • Health (int)
  • Moves (Array of 3 Moves)
  • isConfused (boolean)

And will have the following (public) member functions:

  • Class constructor. The class constructors takes in name as parameter (Mewtwo or Pikachu) and creates the pokemon object accordingly with the right values for health and available attacks (details in the list below). Note that Mewtwo only gets one attack, so 2 elements of the Moves array will remain empty.
  • Mutators (setHealth, setIsConfused, setMoves). In particular, setMoves set all moves at once and requires 6 parameters, a string and a point value for each move, in this order: string move1, int damage1, string move2, int damage2, string move3, int damage3
  • Accessors (getHealth, getIsConfused)
  • Void type function move(int index, Pokemon& target): this function uses as parameter the index of the attack to use (from 0 to 2) and a reference to the pokemon who is being attacked. The health of the target will be reduced according to the attack received. If Electro Ball is used, the target's health does not change but they get confused and skip the next turn.
  • Void type function displayMoves: This function presents the user with a list of available moves, in this format:
Thunderbolt, Electro Ball, or Quick Attack

Pokemon stats

  • Pikachu (274 HP)
    • Thunderbolt (-125 HP)
    • Electro Ball (Confuses a pokemon, target skips a turn)
    • Quick Attack (-90 HP)
  • Mewtwo (322 HP)
    • Psycho Cut (-90 HP)

main.cpp

In the main file, create two pokemon objects (a Mewtwo and a Pikachu) and a loop with the following sequence of actions:

  • Mewtwo attacks Pikachu
  • Pikachu displays moves
  • User selects move
  • Pikachu attacks Mewtwo

Console Input/Output

• Sample input 1

Thunderbolt    
Electro Ball
Thunderbolt
Thunderbolt

Sample output 1

Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Electro Ball
It confused Mewtwo!
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
You win

Sample input 2

Thunderbolt
Quick Attack
Electro Ball
Quick Attack

Sample output 2

Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Quick Attack
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Electro Ball
It confused Mewtwo!
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Quick Attack
Mewtwo used Psycho Cut
You lose

Solutions

Expert Solution

Code:-

// Move.h
#include<string>
using namespace std;
struct move
{
string name;
int damage;
};

// Pokemon.h
#include "Move.h"
class Pokemon
{
string name;
int health;
struct move moves[3];
bool isConfused;
public:
Pokemon(string);
int getHealth();
bool getIsConfused();
void setHealth(int);
void setMoves(string, int, string, int, string, int);
void setIsConfused(bool);
void move(int, Pokemon&);
void displayMoves();
};

// Pokemon.cpp
#include "Pokemon.h"
#include<iostream>
Pokemon::Pokemon(string name)
{
this->name = name;
this->setIsConfused(false);
if(name == "Pikachu")
   {
this->setHealth(274);
this->setMoves("Thunderbolt",-125,"Electro Ball",0,"Quick Attack", -90);
}
   else
   {
this->setHealth(322);
this->setMoves("Psyco Cut",-90,"",0,"",0);
}
}
int Pokemon::getHealth()
{
return health;
}
bool Pokemon::getIsConfused()
{
return isConfused;
}
void Pokemon::setHealth(int health)
{
this->health = health;
}
void Pokemon::setMoves(string move1, int damage1, string move2, int damage2, string move3, int damage3)
{
moves[0].name = move1;
moves[0].damage = damage1;
moves[1].name = move2;
moves[1].damage = damage2;
moves[2].name = move3;
moves[2].damage = damage3;
}
void Pokemon::setIsConfused(bool confused)
{
isConfused = confused;
}
void Pokemon::move(int index, Pokemon& target)
{
if(index == 1)
{
target.setIsConfused(true);
}
else
{
target.setHealth(target.getHealth() + moves[index].damage);
}
}
void Pokemon::displayMoves()
{
cout << moves[0].name << ", " << moves[1].name << " or " << moves[2].name << endl;
}

// Main.cpp
#include "Pokemon.cpp"
#include <string>
using namespace std;
int main()
{
Pokemon pikachu("Pikachu"),mewtwo("Mewtwo");
while(pikachu.getHealth() > 0 && mewtwo.getHealth() > 0)
{
if(mewtwo.getIsConfused()==false)
   {
mewtwo.move(0,pikachu);
cout<< "Mewtwo used Psyco cut"<<endl;
if(pikachu.getHealth()<=0)
           {
cout<<"You lose";
    break;
}
}
   else
   {
mewtwo.setIsConfused(false);
cout<<"It confused MewTwo"<<endl;
}
do
   {
pikachu.displayMoves();
string mov;
getline(cin,mov);
if(mov == "Thunderbolt")
       {
pikachu.move(0,mewtwo);
cout<<"Pikachu used "<<mov<<endl;
break;
}
       else if(mov == "Electro Ball")
       {
pikachu.move(1,mewtwo);
cout<<"Pikachu used "<<mov<<endl;
break;
}
       else if(mov == "Quick Attack")
       {
pikachu.move(2,mewtwo);
cout<<"Pikachu used "<<mov<<endl;
break;
}
       else
       {
cout<<"Invalid input"<<endl;
}
}
   while(true);
if(mewtwo.getHealth()<=0)
   {
cout<<"You won";
break;
}
}
return 0;
}

Output:-

Please UPVOTE thank you...!!!


Related Solutions

I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Can someone please provide C# code in Events,Delegates and Reflection for the below problem. ----------------- Agent-Policy...
Can someone please provide C# code in Events,Delegates and Reflection for the below problem. ----------------- Agent-Policy XYZ Assurance wants to categorize the policies based on the agent who sold the policy and the Insurance type. Given an Agent name, display the policies that were sold by that agent. Similarly, print the policies in the given Insurance type. Write a program to do the same. They have a list of few policies and want to update the list with a few...
can someone please check this code? – Enter Quantity of Numbers Design a program that allows...
can someone please check this code? – Enter Quantity of Numbers Design a program that allows a user to enter any quantity of numbers until a negative number is entered. Then display the highest number and the lowest number. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations           num number           num high             num low              housekeeping()     while number >=0 detailLoop()      endwhile      finish() stop housekeeping( )           output...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails. Use a random generator to get random guesses every time. If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.   If the user does not guess correctly, subtract a point. Create a menu that allows the user to continue guessing, view the current score...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for Hunterville College. The current tuition is $20,000 per year. Allow the user to enter the rate the tuition increases each year. Display the tuition each year for the next 10 years. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations             num tuition             num year                         num TOTAL_YEARS = 10             num INCREASE_RATE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT