Question: Using AWS Cloud9 for a school project. Each time I am in the main.cpp file and right-click Run, I receive the following errors. Below I
Using AWS Cloud9 for a school project. Each time I am in the main.cpp file and right-click "Run", I receive the following errors. Below I have included copyable code, as well as project prompt for reference. Please advise on either something wrong with the code, or whatever else I am doing wrong.
Prompt:
Character Class
Each character will be represented by a Character C++ Class. Each character, both the player and the "computer" will have the following properties:
- Name, so the characters have some way to identify which one is which
- Strength, to represent how hard they can hit
- Health, to represent how much damage they can take before dying
- Defense, to reduce incoming damage
- Speed, to determine which character will attack first
Custom RPG Mechanics
Using the described character classes, each turn the characters take turns in combat. Combat follows the following rules:
- Each turn the characters will deal damage to each other
- The character with higher "speed" will deal damager first
- A character will deal damage based on how strong they are
- Characters can reduce incoming damage based on how tough they are
- damage taken = attacker's strength - defender's defense
- Characters are defeated when their health reaches 0
Requirements
Using the mechanics described above, create a combat program that has the following requirements:
- (20 pts) Two characters should take turns attacking each other until one runs out of health
- (20 pts) Once one character runs out of health the game ends
- (20 pts) Characters should be represented by a Character class
- (20 pts) The character class should not utilize any public member variables
- (20 pts) The character class should have an overloaded constructor for setting initial values
Note: Some students have asked why we have an "if" condition evaluating speed if it's going to be the same for the entire execution of the code. The reason is if you were to randomize speed values or decide to change it, the code will react appropriately to these changes.
Current Code:
******************************
main.cpp
#include #include "character.h"
using namespace std;
int main(){ // Initialize characters Character player("Barbarian", 5, 3, 20, 2); // Player Character Character computer("Dragon", 7, 4, 50, 1); // Computer Character while(player.isAlive() && computer.isAlive()){ // Combat // Who is faster? if(player.getSpeed() > computer.getSpeed()){ // Player attacks first computer.takeDamage(player.getStrength()); // health = health - (attacker's str - def); if(computer.isAlive() == false) break; player.takeDamage(computer.getStrength()); } else { // Computer attacks first player.takeDamage(computer.getStrength()); if(player.isAlive() == false){ break; } computer.takeDamage(player.getStrength()); } } // Evaluate winner if(player.isAlive()){ cout
***********************************
character.cpp
#include "character.h"
Character::Character(string n, int st, int d, int h, int sp){ name = n; strength = st; defense = d; health = h; speed = sp; }
bool Character::isAlive() const { return health > 0; }
int Character::getSpeed() const { return speed; }
int getStrength() const{ return strength; }
void takeDamage(int damage) const{ // defense reduces the damage // if the attack is weaker than the defense then the damage is 0.
damage = max(0,damage - defense); health = health - damage; }
********************************************
character.h
#ifndef CHARACTER_H #define CHARACTER_H
#include
using namespace std;
class Character{ private: string name; int strength; int defense; int health; int speed; public: Character(string n, int st, int d, int h, int sp); bool isAlive() const; int getSpeed() const; int getStrength() const; void takeDamage(int damage) const; };
#endif
*******************************
Error message:
File Edit Find View Go Run Tools Window Support Preview Run Share a Go to Anything (Ctrl-P) E character.cpp character.h X e main.cpp Run Command: main.cpp Runner C++ CWD ENV OPEN FILES x character.cpp - Icharacter.cpp x character.h - Icharacter.h x main.cpp - /main.cpp Running /home/ec2-user/environment/main.cpp /home/ec2-user/environment/main.cpp:1:9: error: #include expects "FILENAME" or
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
