USing C++ Design four classes of towers for a tower defense game. The first clas
ID: 3666005 • Letter: U
Question
USing C++
Design four classes of towers for a tower defense game. The first class is the base class: Tower. The base class Tower has the following functions: UpgradeCost is a corut function that returns a float that indicates how- much it costs to upgrade a tower. Upgrade is a void function that upgrades a towers range and firepower by multiplying the cost, range and firepower b 1.25. Shoot is a virtual voidfunction that takes a constant reference to a class called Point (assume that Point is defined somewhere else). Tower has three float member variables named cost, range and power. There are three derivatives of the Tower class named: Water, Fire and Earth. Each derivative Tower class starts with the values from the following table. Each of the derivative tower classes and sets the parent class member variables given the above table in its default constructor. Each derivative tower class above overrides the Shoot virtual function.Explanation / Answer
#include<iostream>
using namespace std;
class Tower
{
public:
float cost, range, power
Tower(float theCost, float theRange, float thePower)
{
cost = theCost;
range = theRange;
power = thePower;
}
float UpgradeCost() const
{
//returns a float indicating how much it costs to upgrade the tower
}
void Upgrade()
{
//its upgrades a tower's range and fire power
}
virtual void Shoot(const Point& pointObj)
{
//virtual function that takes constant referece to a class called Point
}
};
class Water:public Tower //Water class derived from Tower class
{
public:
Water(): Tower(float cost, float range, float power)
{
//Water class constructor to initialize the base Tower class member variables
}
void Shoot(const Point& pointObj) //overridden function from base
{
}
};
class Fire:public Tower //Fire class derived from Tower class
{
public:
Fire(): Tower(float cost, float range, float power)
{
//Fire class constructor to initialize the base Tower class member variables
}
void Shoot(const Point& pointObj)
{
}
};
class Earth:public Tower //Earth class derived from Tower class
{
public:
Earth(): Tower(float cost, float range, float power)
{
//Earth class constructor to initialize the base Tower class member variables
}
void Shoot(const Point& pointObj)
{
}
};
int main()
{
Earth earthObj(60,2,4); // object of earth
Water earthObj(50,5,2); // oject of water
Fire earthObj(50,3,3); // oject of
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.