Implement a two player game. You are given a main, and a game source file and th
ID: 3761107 • Letter: I
Question
Implement a two player game. You are given a main, and a game source file and the creature class definition file.
1. Create the enumerator type in the creature.h file
2. Allocate the creature (derived) objects in the RequestCreatureType() function (game.cpp) by using the new operator.
3. Implement all the methods for the Creature class and its derived classes.
4. Make the game compile and run successfully.
Files needed is in my google drive in a zipfile -
https://drive.google.com/folderview?id=0B3xYFHxCq-GTZThlNGxsMXloSkU&usp=sharing
For this homework you will have to implement a two player game. You are given a main, and a game source file and the creature class definition file This program is a two player game. Each player will enter a number to choose their type of creature to fight with. A dice will roll for each player, the player with the highest number will have a chance to attack the other player, if there is a tie both players will attack simultaneously. The first player to reach zero (or lower) health loses Game solution>a.exe Player 1 Type? Type 0 Human Type 1: Demon Type 2: Balrog Type 3: Elf layer 2 Type? ype Human ype 1 Demon ype 2 Balrog ype 3: Elf Player 1 is a Hunan Player 2 is a Balrog Player 1 Hunan attacks for 1 points Player 1 Hunan attacks for 9 points Player 2 Balrog attacks for 1 points Balrog speed attack inflicts 14 additional damage points! Player 2 Balrog attacks for 3 points Balrog speed attack inflicts 6 additional damage points! Player 1 Hunan attacks for 6 points layerr 1 Human attacks for 6 points layer 2 Balrog attacks for 9 points Balrog speed attack inflicts 10 additional damage points! player 2 wins Game solution> The objective of this assignment is to design and implement the derived classes for the following species: Human, Demon, Balrog, and Elf, using the base Creature class. Each Creature has a specified Strength which will be used to assess how much damage the creature will inflict, and health (the amount of life each creature has) Species Human: Demon Balrog Elf Strength 10 20 15 Health 30 35 25 40 You must declare the enumerator type for each of the species in the creature.h file, so that the switch statement in the RequestCreature() function (game.cpp) will be able to decipher which type is chosen. Also, in the RequestCreature0 function, you will allocate each of the derived class objects. All of the derived class constructors must take one argument which will take in the player number. To allocate the derived class objects, it is necessary to use the new operator:Explanation / Answer
Creature.h
#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_
#include <iostream>
#include <string>
using namespace std;
// Create "creature" enumerator for HUMAN, DEMON, BALROG, ELF
enum creature{
HUMAN = 0,
DEMON = 1,
BALROG = 2,
ELF = 3};
class Creature
{
private:
int health; // Health level
public:
Creature() {}; // Default constructor
Creature(int playerNumber, int strength, int health); // Custom constructor, where player number, strength and health gets set
bool alive(void); // Returns if creature is still alive (health > 0)
void fight(const Creature &attacker); // (this) creature is being attacked by attacker
int getPlayerNumber(); // Returns the players number
virtual string getSpecies() const; // Returns string of species
~Creature();
protected:
int strength; // how much damage we can inflict
virtual int getDamage() const; // returns how much damage one inflicts
int playerNumber; // Hold the playerNumber
};
#endif
//##################################################################################
Creature.cpp:
#include "Creature.h"
//Creature::Creature() {}; // Default constructor
Creature::Creature(int playerNumber, int strength, int health)
{
this->playerNumber = playerNumber;
this->strength = strength;
this->health = health;
}
bool Creature::alive(void)
{
return this->health > 0;
}
void Creature::fight(const Creature &attacker)
{
this->health = this->health - attacker.getDamage();
}
int Creature::getPlayerNumber()
{
return this->playerNumber;
}
string Creature::getSpecies() const
{
return "Creature";
}
int Creature::getDamage() const
{
return 0;
}
Creature::~Creature()
{
}
//##################################################################################
Human.h:
#ifndef HUMAN_H
#define HUMAN_H
#include <Creature.h>
class Human : public Creature
{
public:
Human():Creature(){};
Human(int playerNumber):Creature(playerNumber,10,30){};
virtual string getSpecies() const; // Returns string of species
protected:
virtual int getDamage() const;
private:
};
#endif // HUMAN_H
//##################################################################################
Human.cpp:
#include "Human.h"
#include <stdlib.h>
string Human::getSpecies() const
{
return "Human";
}
int Human::getDamage() const
{
return rand()%this->strength;
}
//##################################################################################
Demon.h:
#ifndef DEMONS_H
#define DEMONS_H
#include <Creature.h>
class Demon : public Creature
{
public:
Demon():Creature(){};
Demon(int playerNumber):Creature(playerNumber,20,35){};
virtual string getSpecies() const;
protected:
virtual int getDamage() const;
private:
};
#endif // DEMONS_H
//##################################################################################
Demon.cpp:
#include "Demon.h"
#include <stdlib.h>
string Demon::getSpecies() const
{
return "Demons";
}
int Demon::getDamage() const
{
int chance = rand()%20;
int damage = rand()%this->strength;
if(chance == 0)damage += 50;
return damage;
}
//##################################################################################
Balrog.h:
#ifndef BALROG_H
#define BALROG_H
#include <Creature.h>
class Balrog : public Creature
{
public:
Balrog():Creature(){};
Balrog(int playerNumber):Creature(playerNumber,15,25){};
virtual string getSpecies() const; // Returns string of species
protected:
virtual int getDamage() const;
private:
};
#endif // BALROG_H
//##################################################################################
Balrog.cpp:
#include "Balrog.h"
#include <stdlib.h>
string Balrog::getSpecies() const
{
return "Balrog";
}
int Balrog::getDamage() const
{
int damage = rand()%this->strength;
int secondDamage = rand()%(this->strength+1);
return damage + secondDamage;
}
//##################################################################################
Elf.h:
#ifndef ELF_H
#define ELF_H
#include <Creature.h>
class Elf : public Creature
{
public:
Elf():Creature(){};
Elf(int playerNumber):Creature(playerNumber,5,40){};
virtual string getSpecies() const; // Returns string of species
protected:
virtual int getDamage() const;
private:
};
#endif // ELF_H
//##################################################################################
Elf.cpp:
#include "Elf.h"
#include <stdlib.h>
string Elf::getSpecies() const
{
return "Elf";
}
int Elf::getDamage() const
{
int chance = rand()%10;
int damage = rand()%this->strength;
if(chance == 0)damage += damage;
return damage;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.