In: Computer Science
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:
Move.h (Move Struct) Each move struct must have the following attributes:
Pokemon.h and Pokemon.cpp (Pokemon Class) Each pokemon class must have the following (pritvate) attributes:
And will have the following (public) member functions:
Thunderbolt, Electro Ball, or Quick Attack
Pokemon stats
main.cpp
In the main file, create two pokemon objects (a Mewtwo and a Pikachu) and a loop with the following sequence of actions:
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
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...!!!