Add the cpp files for Assignment 4.
This commit is contained in:
parent
94ac292f32
commit
cfcce88ebc
4 changed files with 345 additions and 0 deletions
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
Program Name: Videogamer
|
||||
Process: designing a set of classes to represent types of characters that might
|
||||
be seen in a video game.
|
||||
Function Input/Parameters: ???
|
||||
Function Output/Parameters: ???
|
||||
Function Output/Returned: ???
|
||||
Device Input/Device: ???
|
||||
Device Output/Monitor: ???
|
||||
Dependencies: ???
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// class definitions
|
||||
class GameCharacter
|
||||
{
|
||||
private:
|
||||
//
|
||||
protected:
|
||||
double characterHealth;
|
||||
string characterName;
|
||||
int characterLevel;
|
||||
public:
|
||||
GameCharacter()
|
||||
{
|
||||
//
|
||||
characterHealth = 0.0;
|
||||
characterName = "My Character";
|
||||
characterLevel = 1;
|
||||
}
|
||||
GameCharacter(double health, string name, int level)
|
||||
{
|
||||
//
|
||||
characterHealth = health;
|
||||
characterName = name;
|
||||
characterLevel = level;
|
||||
}
|
||||
// ~GameCharacter()
|
||||
// {
|
||||
// //
|
||||
// }
|
||||
// virtual ~GameCharacter() = 0;
|
||||
virtual ~GameCharacter()
|
||||
{
|
||||
return;
|
||||
// cout << "This not works?" << endl;
|
||||
}
|
||||
// accessor functions
|
||||
double getCharacterHealth()
|
||||
{
|
||||
return characterHealth;
|
||||
}
|
||||
string getCharacterName()
|
||||
{
|
||||
return characterName;
|
||||
}
|
||||
int getCharacterLevel()
|
||||
{
|
||||
return characterLevel;
|
||||
}
|
||||
// mutator functions
|
||||
void setCharacterHealth(double setHealth)
|
||||
{
|
||||
characterHealth = setHealth;
|
||||
}
|
||||
void setCharacterName(string setName)
|
||||
{
|
||||
characterName = setName;
|
||||
}
|
||||
void setCharacterLevel(int setLevel)
|
||||
{
|
||||
characterLevel = setLevel;
|
||||
}
|
||||
// virtual functions
|
||||
virtual void performUniqueAttack()
|
||||
{
|
||||
// nothing happens?
|
||||
}
|
||||
};
|
||||
|
||||
class Knight : public GameCharacter
|
||||
{
|
||||
private:
|
||||
string armorType;
|
||||
public:
|
||||
Knight() : GameCharacter()
|
||||
{
|
||||
armorType = "Leather Armor";
|
||||
setCharacterName("My Knight Character");
|
||||
}
|
||||
Knight(double health, string name, int level, string armor) : GameCharacter(health, name, level)
|
||||
{
|
||||
armorType = armor;
|
||||
}
|
||||
~Knight()
|
||||
{
|
||||
//
|
||||
// cout << "This works?" << endl;
|
||||
}
|
||||
// accessor functions
|
||||
string getArmorType()
|
||||
{
|
||||
return armorType;
|
||||
}
|
||||
// mutator functions
|
||||
void setArmorType(string armor)
|
||||
{
|
||||
armorType = armor;
|
||||
}
|
||||
// virtual functions
|
||||
void performUniqueAttack()
|
||||
{
|
||||
//
|
||||
cout << getCharacterName() << " performed Knight Attack wearing " << armorType << "!" << endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Mage : public GameCharacter
|
||||
{
|
||||
private:
|
||||
double mageMana;
|
||||
public:
|
||||
Mage() : GameCharacter()
|
||||
{
|
||||
mageMana = 0.0;
|
||||
setCharacterName("My Mage Character");
|
||||
}
|
||||
Mage(double health, string name, int level, double mana) : GameCharacter(health, name, level)
|
||||
{
|
||||
mageMana = mana;
|
||||
}
|
||||
~Mage()
|
||||
{
|
||||
//
|
||||
// cout << "This works?" << endl;
|
||||
}
|
||||
// accessor functions
|
||||
double getMana()
|
||||
{
|
||||
return mageMana;
|
||||
}
|
||||
// mutator functions
|
||||
void setMana(double mana)
|
||||
{
|
||||
mageMana = mana;
|
||||
}
|
||||
// virtual functions
|
||||
void performUniqueAttack()
|
||||
{
|
||||
//
|
||||
cout << getCharacterName() << " performed Mage Attack with their " << mageMana << " amount of mana." << endl;
|
||||
}
|
||||
};
|
||||
|
||||
// function definitions
|
||||
|
||||
// main function
|
||||
int main()
|
||||
{
|
||||
int setSize = 4;
|
||||
GameCharacter *characterSet[setSize];
|
||||
characterSet[0] = new Knight(100.0, "Meta Knight", 20, "Pallidium Armor");
|
||||
characterSet[1] = new Mage(50.0, "Rosalina", 5, 300.0);
|
||||
characterSet[2] = new Knight(100.0, "Eomer", 20, "Chainmail Armor");
|
||||
characterSet[3] = new Mage(50.0, "Gandalf", 20, 900.0);
|
||||
|
||||
for(int characterIterator = 0; characterIterator < setSize; characterIterator++)
|
||||
{
|
||||
characterSet[characterIterator]->performUniqueAttack();
|
||||
}
|
||||
|
||||
for(int deleteIterator = 0; deleteIterator < setSize; deleteIterator++)
|
||||
{
|
||||
delete characterSet[deleteIterator];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue