Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this C++ project where the purpose of it is to create a turn based rpg game using a class called character and a

I have this C++ project where the purpose of it is to create a turn based rpg game using a class called character and a header.

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

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

Main.cpp

#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()) break; player.takeDamage(computer.getStrength()); } else { // Computer attacks first } } // Evaluate winner // Print conclusion return 0; }

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; }

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; };

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago