Question

In: Computer Science

C++ Please create 4 different files with this respective names main.cpp , Pokemon.h , Pokemon.cpp Move.h...

C++

Please create 4 different files with this respective names

  • main.cpp , Pokemon.h , Pokemon.cpp Move.h

16.5 Homework 5

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

Please Test the files.......

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

I recently started learning C++ about a week ago, and I made a bit of progress. In honor of Pokemon Go releasing, I decided to make a Pokedex with the original 151 Pokemon. So far I have 120 or so of them in there and it works PERFECTLY! (Thank goodness). I believe my code could be much more efficient and work better. I probably am using bad practices too. If I am, please feel free to tell me and if you find a problem, tell me!

Pokemon.h:

#pragma once
#include <string>


class Pokemon {
public:
    std::string type;
    double weight, height;
    std::string Gender;
    int evoLevel;
    bool finalEvo;
    int dexNum;
    std::string name;

    Pokemon(std::string name2, std::string type2, double weight2, double height2, std::string Gender2, int evoLevel2, bool finalEvo2, int dexNum2);
    Pokemon();
}; 

Pokemon.cpp:

#include "Pokemon.h"

Pokemon::Pokemon(std::string name2, std::string type2, double weight2,  double height2, std::string Gender2, int evoLevel2, bool finalEvo2, int dexNum2) {
    name = name2;
    type = type2;
    weight = weight2;
    height = height2;
    Gender = Gender2;
    evoLevel = evoLevel2;
    finalEvo = finalEvo2;
    dexNum = dexNum2;
}

//Default constructer
Pokemon::Pokemon() {
    name = "Pichario";
    type = "Death";
    weight = 10;
    height = 12;
    Gender = "Male and Female";
    evoLevel = 1;
    finalEvo = true;
    dexNum = 999;
}

main.cpp:

#include <iostream>
#include <string>
#include <vector>
#include "Pokemon.h"


int main() {
    //Create Pokemon objects
    Pokemon bulbasaur("Bulbasaur", "Grass and Poison", 15.2, 28, "Male and Female", 1, false, 1);
    Pokemon ivysaur("Ivysaur", "Grass and Poison", 28.7, 39, "Male and Female", 2, false, 2);
    Pokemon venusaur("Venusaur", "Grass and Poison", 220.5, 79, "Male and Female", 3, true, 3);

    Pokemon charmander("Charmander", "Fire", 18.7, 24, "Male and Female", 1, false, 4);
    Pokemon charmeleon("Charmeleon", "Fire", 41.9, 44, "Male and Female", 2, false, 5);
    Pokemon charizard("Charizard", "Fire and Flying", 199.5, 67, "Male and Female", 3, true, 6);

    Pokemon squirtle("Squirtle", "Water", 19.8, 20, "Male and Female", 1, false, 7);
    Pokemon wartortle("Wartortle", "Water", 49.6, 39, "Male and Female", 2, false, 8);
    Pokemon blastoise("Blastoise", "Water", 188.5, 63, "Male and Female", 3, true, 9);

    Pokemon caterpie("Caterpie", "Bug", 6.4, 12, "Male and Female", 1, false, 10);
    Pokemon metapod("Metapod", "Bug", 21.8, 28, "Male and Female", 2, false, 11);
    Pokemon butterfree("Butterfree", "Bug and Flying", 70.5, 43, "Male and Female", 3, true, 12);

    Pokemon weedle("Weedle", "Bug and Poison", 7.1, 12, "Male and Female", 1, false, 13);
    Pokemon kakuna("Kakuna", "Bug and Poison", 22, 24, "Male and Female", 2, false, 14);
    Pokemon beedrill("Beedrill", "Bug and Poison", 65, 39, "Male and Female", 3, true, 15);

    Pokemon pidgey("Pidgey", "Normal and Flying", 4, 12, "Male and Female", 1, false, 16);
    Pokemon pidgeotto("Pidgeotto", "Normal and Flying", 66.1, 43, "Male and Female", 2, false, 17);
    Pokemon pidgeot("Pidgeot", "Normal and Flying", 87.1, 59, "Male and Female", 3, true, 18);

    Pokemon rattata("Rattata", "Normal", 7.7, 12, "Male and Female", 1, false, 19);
    Pokemon raticate("Raticate", "Normal", 40.8, 28, "Male and Female", 2, true, 20);

Related Solutions

Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp -...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp - main() function (2) Build the ContactNode class per the following specifications: Parameterized constructor. Parameters are name followed by phone number. Public member functions InsertAfter() (2 pts) GetName() - Accessor (1 pt) GetPhoneNumber - Accessor (1 pt) GetNext() - Accessor (1 pt) PrintContactNode() Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr Ex. of PrintContactNode() output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main(),...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp - main() function Build the ItemToPurchase class with the following specifications: Default constructor Public class functions (mutators & accessors) SetName() & GetName() (2 pts) SetPrice() & GetPrice() (2 pts) SetQuantity() & GetQuantity() (2 pts) Private data members string itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 (2)...
Create files with the following names : test1, test2, test3. Create a symbolic link to test2...
Create files with the following names : test1, test2, test3. Create a symbolic link to test2 and name it test4 Create a directory and name it test5. Write a shell script to perform the following tasks: • check if a file named test6 exist. If not, it should create it. • Display a text to indicate whether test4 is symbolic link or not • Display a text to indicate whether test2 is directory or not • Display a text to...
In C++, I have 3 files (Main.cpp, Point.cpp, Point.h). When Compiled and run, it produces 2...
In C++, I have 3 files (Main.cpp, Point.cpp, Point.h). When Compiled and run, it produces 2 errors, in Main.cpp "cannot convert from double to point" and in Point.cpp "name followed by :: must be a class or namespace name". How do you go about fixing these errors without editing Main.cpp? Thanks in advance. //main.cpp #include <iostream> #include <cmath> #include "Point.h" using namespace std; const double PI = 3.14159265359; const double TOL = .0000001; //allows us to do a comparison for...
In C++, develop a menu program which reads in data from 4 different input files -...
In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a method (inputGrade) that can put a name and a grade to the grade object. - Create another method (showAlltheGrades) to show all the grade in that object. - Create the third method (MaxGrade) that can display the maximum grade and the student name. - Using “prompt” and inputGrade method input 10 student names and their grades. - Display all the grades and names by...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a method (inputGrade) that can put a name and a grade to the grade object. - Create another method (showAlltheGrades) to show all the grade in that object. - Create the third method (MaxGrade) that can display the maximum grade and the student name. - Using “prompt” and inputGrade method input 10 student names and their grades. - Display all the grades and names by...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a method (inputGrade) that can put a name and a grade to the grade object. - Create another method (showAlltheGrades) to show all the grade in that object. - Create the third method (MaxGrade) that can display the maximum grade and the student name. - Using “prompt” and inputGrade method input 10 student names and their grades. - Display all the grades and names by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT