×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create a Program to Implement RPG Game in C++ Assignment Solution

July 15, 2024
Dr. Stephanie Kim
Dr. Stephanie
🇬🇧 United Kingdom
C++
Dr. Stephanie Kim earned her Ph.D. in Computer Science from New York University and is a leading authority in C++ programming. With 8 years of experience, Dr. Kim has successfully completed over 800 C++ assignments, demonstrating her proficiency and dedication to delivering high-quality solutions.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Use meaningful variable and method names in your C# assignments to enhance readability and debugging. Well-structured code not only helps you understand your logic better but also makes collaboration easier with peers or instructors.
News
The Library Carpentry curriculum has released a major update to its Python lesson, integrating JupyterLab, Pandas, and Plotly to enhance data analysis for library professionals

Instructions

Objective

Write a C++ assignment program to implement RPG game.

Requirements and Specifications

Assignment 3

You will be enhancing assignment 2 to have include the following:

Create Object Classes for your Enemy

You will create a base class called Enemy. This class will have the following configuration

Constructor(PlayerXP): The constructor will initiate the HP of the enemy.

Player XP Enemy HP

  1. Random value (1-5)
  2. Random value (1-10)
  3. Random value (1-15) …etc

Private Member HP: Health Points. The amount will be based on the player’s XP based on the given scale below.

getHP(): An accessor function to retrieve the enemy’s HP.

setHP(): A mutator function to set the HP.

Virtual method: attack(Player obj): This method will be implemented in the derived classes and returns a damage against the player.

You will then use your base class to implement subclasses of the following enemies as derived classes:

Raging Reapers:

The Reaper class will have the following implementation of attack (Player Obj):

If the player has an alignment of “Good”, the attack will be half the player’s current HP. Otherwise the attack will be a random number from 1 to 25% of the player’s HP. Round up or down to the nearest point as necessary.

Brute Trolls:

The Troll class will have the following implementation of attack (Player Obj):

If the player has an equipped weapon of a “broad sword”, “Mace” or “Flail” the attack will be equal to the player’s HP. Otherwise the attack will be a random number from 1 to 25% of the player’s HP. Round up or down to the nearest point as necessary.

Winged Demon Knights:

The Knight class will have the following implementation of attack (Player Obj):

If the player is in one of the following spaces “Cathedral” or “Well of reflection” the attack will be 60% of the player’s HP. Otherwise the attack will be a random number from 1 to 25% of the player’s HP. Round up or down to the nearest point as necessary.

Specification and Implementation Separation.

You will separate your Enemy and Player class into an implementation file (.cpp) and a specification file (.h)

Implement “Mystic Blacksmith” Weapon Stack.

When you land in a space you will have a random chance (1 in 3) to encounter a new space, “The Mystic Blacksmith”. The blacksmith has a stack which will allow you to leave multiple weapons in the stack to increase their modifier value. You may choose to leave your weapon with the Blacksmith until you next encounter him

When you retrieve the weapon in from the blacksmith, the modifier will be + the number of turns that weapon has been with the blacksmith. A turn is defined by every time you roll your dice to move.

Example:

On turn 5, you left a Mace with modifier 4. During turn 10, you find the Blacksmith again and retrieve the Mace. The Mace will now have a modifier of 9 (4 plus 5 turn difference).

Use the STL’s implementation of a Stack to do this.

Exception Handling:

You will add the following custom Exception:

WeaponsLimit: Limit the Weapons that can be carried to 5. If more than 5 weapons are attempted to be carried, throw the WeaponsLimit exception, which will display a message to the user that they have reached their max.

ItemLimit: Limit the Items that can be carried to 10. If more than 10 items are attempted to be carried, throw the ItemsLimit exception, which will display a message to the user that they have reached their max.

Lake of Despair:

If in the menu:

  1. Travel to another space on the board
  2. Dismount and explore the current space
  3. Save your game

You choose #1, there will be a 1 in 4 chance you will fall into the Lake of Despair. You will create a recursive function called leaveDespair() which will roll the dice. A value of 1,2,4, and 5 will keep you in the Lake of despair and cause you to roll again. A value of 3 and 6 will let you exit.

You will create leaveDespair() to be a recursive function, such that it will call itself if you don’t roll a 3 or a 6 and rolls again.

  • Grading Criteria (Assignment Total 30 points):
  • Enemy Base Class (5 points)
  • Derived Classes (5 points)
  • Enemy Header and Implementation (5 points)
  • Blacksmith Stack (5 points)
  • Exception Handling (5 points)
  • Despair Recursion (5 points)

Source Code

BOARD

#include "Board.h" // Initialize the board Board::Board() { // Build an empty maps for (int r = 0; r < BOARD_HEIGHT; r++) { for (int c = 0; c < 8; c++) { if (c == 0 || c == BOARD_WIDTH - 1 || r == 0 || r == BOARD_HEIGHT - 1) map[r][c] = '*'; else map[r][c] = ' '; } } } // Plot the token at the given position void Board::plot(char token, const BoardPosition &position) { if (position.getRow() < 0 || position.getRow() >= BOARD_HEIGHT || position.getColumn() < 0 || position.getColumn() >= BOARD_WIDTH) return; map[position.getRow()][position.getColumn()] = token; } // Print out the board ostream& operator << (ostream &out, const Board &board) { for (int r = 0; r < BOARD_HEIGHT; r++) { for (int c = 0; c < BOARD_WIDTH; c++) out << board.map[r][c] << " "; out << endl; } return out; }

ENEMY

#include "Enemy.h" // Generate an anemy and set the its health points // based on the experience points Enemy::Enemy(int xp) { int highestHealthPoints; if (xp == 1) highestHealthPoints = 5; else if (xp == 2) highestHealthPoints = 10; else highestHealthPoints = 15; healthPoints = (rand() % highestHealthPoints) + 1; } // It is recommended to always have a virtual destructor on base classes Enemy::~Enemy() { } // Initialize the character's HP void Enemy::setHP(int points) { if (points < 0) points = 0; healthPoints = points; } // Return the HP of the character int Enemy::getHP() const { return healthPoints; } // Output enemy info ostream& operator << (ostream &out, const Enemy &enemy) { out << "HP: " << enemy.healthPoints; return out; }

WEAPON

#include "Weapon.h" // Default constructor Weapon::Weapon() { name = "Fist"; modifier = 2; } // Initialize weapon Weapon::Weapon(string name, int modifier) { this->name = name; this->modifier = modifier; } // Weapons are the same if they have the same name bool Weapon::operator == (const Weapon &weapon) const { return name == weapon.name; }

Similar Sample

Explore our C++ assignment sample to see how our experts tackle complex programming tasks with precision and clarity. Each assignment exemplifies our commitment to delivering high-quality solutions tailored to meet academic standards and student needs. Whether you're grappling with algorithms, data structures, or application development, our samples showcase our expertise in simplifying C++ challenges effectively.