Question: Question 1 : Base and Utility Classes Define two base classes: GameEntity: An enumeration enum GameEntityType representing the various objects in the game: ExplosionType, MineType,

Question 1: Base and Utility Classes
Define two base classes:
GameEntity:
An enumeration enum GameEntityType representing the various objects in the game: ExplosionType, MineType, NoneType, ShipType. Note that the enumeration order is important.
Data Members:
std::tuple position (representing the position of the entity)GameEntityType type (representing the type of the entity)
Member Functions:
Constructor GameEntity(int x, int y, char type)std::tuple getPos(): Returns the position of the entity.GameEntityType getType(): Returns the type of the entity.
Effect:
Member Functions:
virtual void apply(GameEntity& entity): Accepts a GameEntity object as input and applies the effect to the entity. This function is pure virtual and needs to be implemented in derived classes.
Define a class Utils with the following static functions:
std::tuple generateRandomPos(int gridWidth, int gridHeight): Returns a random position within a grid represented by gridWidth and gridHeight as a std::tuple.
double calculateDistance(std::tuple pos1, std::tuple pos2): Returns the Euclidean distance between two positions given as pos1 and pos2 as a double.
In main-1.cpp, generate some random positions and calculate distances between them.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!