Question

CIS4100 Final Project Description The Objective of this Final Project is to implement the theoretical concepts...

CIS4100 Final Project Description

The Objective of this Final Project is to implement the theoretical concepts covered in the course. You are required to build the classes and test all the functions as described. Each class should have its own .h (specification) and .cpp (implementation) files, then test all the classes in the main.cpp

The Diagram below shows the classes inheritance relationships:

The assigned Types are as follow: Type 1

Type 2

Type 3

         

PitBull Lion Tiger

The class Enemy:

Jet Helicopter Drone

Soldier Robot BadCop

              

The parent class Enemy is the super class to 3 sub classes Type1, Type 2 and Type 3.

  • The class declare the variables: x_position, y_position, width, height and status, all as

    private.

  • The class has getters and setters for all the variables

  • The class will contain the methods: move_position, fire_weapon and update_status:

    These three methods are public and pure virtual

Main

The main method should be in its own .cpp file; It will create Enemy objects and store them in an array. The methods of an object define what the object DOES, the actions it will perform. Main method will loop and ask the Enemy objects to perform actions like move_position, fire_weapon and update_status. The basic layout will be:

int main()

{
const int max_enemy = 20; Enemy* enemy_ptr[max_enemy]; int num_enemy;

// create Enemy objects, place in array // set value of num_enemy

    while ( true ) {

// every Enemy object should move_position

// Pick a random Enemy to fire_weapon

// Pick a random Enemy to update_status

        cout << endl;
    }

return 0; }

You can google 'C++ random number' for help on generating a random number, then use the modulus '%' operator: rand() % num_enemy This will select which Enemy in the array should perform an action.
Keep main() simple! The objects will do the work, and print messages reporting what they have done. The ONLY enemy object methods you are allowed to call are move_position, fire_weapon and update_status

Type 1 - Type 2 - Type 3 Classes

Create the assigned classes and have each one print a simple message for each action it takes: These should be simple classes, a variable to track the name of the object and simple cout statements to report each action. Make sure move_position does NOT output an end of line, if there are 10 objects we DO NOT want it to print 10 lines of output. Do custom messages to match the Enemy, a pitbull will bite and a soldier will shoot a rifle when they fire a weapon. A soldier will say ouch and a Jet will make a ping sound when update status records a hit.

Make sure you can get the simple version of your program working. Test it with different numbers and different combinations of enemy objects. Each time through the main loop it should output messages like the example below:

PitBull moves position Jet moves position Soldier moves position Jet fire weapon: missile
PitBull update status: I have been hit (bark)

Better Enemy Classes!

When you have the simple version working, improve your child classes. Make them behave like they would in a video game. Any change to main() or the Enemy parent class should be very minor (if at all), the focus is on the child classes. Make them move, and fire weapons and record hits when update status is called:

move_position

Each object exists in a 2D space, their X position can range from 0 to 800, y position 0 to 600. Position 0,0 is the top left corner, 800,600 is the bottom right. The ground is at 500 so a person or animal will be at y position 500. A low flying object at y position 300, a high flying one a 100. Objects move on the X axis, have walking objects move 3, running 6 each time move position is called. Flying objects move 15 to 30 with each call depending on their speed. Do not make them all start in the same position, do not make them move at the same speed and do not make them all move in the same direction. When an objects status is zero, it is DEAD, it should no longer move.

fire_weapon

Make sure each object fires an appropriate weapon. In general type 1 objects bite or slash. Type 2 objects have missiles or bombs. Type 3 have guns. Keep track of ammo, if a jet has 4 missiles, have fire weapon report out of ammo on the 5th call. Also check status, when dead, fire weapon should say NO WEAPON FIRED. Since animals do not use ammo, have them vary the attack, e.g. bite leg, slash chest, bite neck.

update_status

Update status means the Enemy object has been HIT. It is to lose status points and DIE if status reaches zero. Type 1 objects should take only 1 or 2 hits before they die, type 3 objects 4 to 5 hits and type 2 should take 7 to 8 hits. As always, make it match the enemy, a Robot will take more hits before death than a Car Jacker. Always report current status points when called, output an extra special statement when death occurs. A soldier might say ouch for a non-lethal hit, but

ARRRGH for a lethal one. The simple way to do this is to start each object with a status that matches the number of hits to kill it and subtract one every time.
Once you have your improved child classes, the output should update each time through the loop, the example below shows the program with 3 loops:

PitBull move to 710,500 Jet move to 320,100 Soldier move to 518,500 Jet fire weapon: missile (2 left)
PitBull update status: hit by bullet, status points 0 (dead)
PitBull move to 710,500 Jet move to 360,100 Soldier move to 514,500 PitBull fire weapon: dead!!!!!

Soldier update status: hit by bullet, status points 3 (ouch)
PitBull move to 710,500 Jet move to 400,100 Soldier move to 510,500 Soldier fire weapon: rifle (12 bullets left)
Jet update status: hit by bullet, status points 7 (ping)

Submission: Compress the project folder that has all the source code and submit it to the Drop Box By The due date to avoid late penalties.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer of the given question:

/***************** File name: Enemy.h *****************/
#pragma once
#include <iostream>

using namespace std;

// Create a parent class Enemy
class Enemy
{
// Declare the private data members
private:
int x_position;
int y_position;
int width;
int height;
int status;
// Declare the methods
protected:
int getXPosition();
void setXPosition(int x);
int getYPosition();
void setYPosition(int y);
int getWidth();
void setWidth(int w);
int getHeight();
void setHeight(int h);
int getStatus();
void setStatus(int s);
public:
virtual void move_position() = 0;
virtual void fire_weapon() = 0;
virtual void update_status() = 0;
};

/***************** File name: Enemy.cpp *****************/
//#include "stdafx.h"
// Header files
#include <iostream>
#include "Enemy.h"

using namespace std;

int Enemy::getXPosition()
{
return x_position;
}
void Enemy::setXPosition(int x)
{
x_position = x;
}
int Enemy::getYPosition()
{
return y_position;
}
void Enemy::setYPosition(int y)
{
y_position = y;
}
int Enemy::getWidth()
{
return width;
}
void Enemy::setWidth(int w)
{
width = w;
}
int Enemy::getHeight()
{
return height;
}
void Enemy::setHeight(int h)
{
height = h;
}
int Enemy::getStatus()
{
return status;
}
void Enemy::setStatus(int s)
{
status = s;
}

/***************** File name: PitBull.h *****************/
#pragma once
#include <iostream>
#include "Enemy.h"

using namespace std;

// Create a child class named PitBull
class PitBull :public Enemy
{
private:
// Declare the private data members
bool direction;//true = right; false = left
public:
// Create the methods.
PitBull();
void move_position();
void fire_weapon();
void update_status();
};
/***************** File name: PitBull.cpp *****************/
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include "Enemy.h"
#include "PitBull.h"

using namespace std;

PitBull::PitBull()
{
setXPosition(400);
setYPosition(500);
setStatus(2);
direction = true;
}
void PitBull::move_position()
{

if (getStatus() != 0)
{
//check to make sure it won't move past 2D space boundary
//object will change direction if it would go past boundary
if ((direction) && (getXPosition() + 10) > 800)
{
direction = false;
}
else if (!(direction) && (getXPosition() - 10) < 0)
{
direction = true;
}
//move to right
if (direction)
{
setXPosition(getXPosition() + 10);
}
//move to left
else
setXPosition(getXPosition() - 10);
cout << "PitBull moves to " << getXPosition() << "," << getYPosition() << " ";
}

else
cout << "PitBull's dead body remains at " << getXPosition() << "," << getYPosition() << " ";
}
void PitBull::fire_weapon()
{
string attacks[8] = { "rip head", "bite head", "rip chest", "bite chest", "rip arm", "bite arm", "rip leg", "bite leg" };
int randAttack;
srand((unsigned int)time(NULL));
cout << "PitBull uses weapon: ";

if (getStatus() != 0)
{
randAttack = rand() % 8;
cout << attacks[randAttack] << endl;
}

else
cout << "dead" << endl;
}
void PitBull::update_status()
{
//check if object is not dead or about to die
if (getStatus() > 1)
{
setStatus(getStatus() - 1);
cout << "PitBull update status: hit by bullet, status points: " << getStatus() << " (ARRRGH )" << endl;
}
//object is dead
else
cout << "PitBull update status: hit by bullet, status points: 0 (dead)" << endl;
}
/***************** File name: Jet.h *****************/
#pragma once
#include <iostream>
#include "Enemy.h"

using namespace std;

// Create a child class named Jet
class Jet :public Enemy
{
private:
// Declare the private data members.
bool direction;//true 8= right; false = left
int ammo;
public:
// Declare the methods.
Jet();
void move_position();
void fire_weapon();
void update_status();
};


/***************** File name: Jet.cpp *****************/
//#include "stdafx.h"
#include <iostream>
#include "Enemy.h"
#include "Jet.h"

using namespace std;

Jet::Jet()
{
setXPosition(800);
setYPosition(100);
setStatus(8);
direction = false;
ammo = 4;
}
void Jet::move_position()
{

if (getStatus() != 0)
{
if ((direction) && ((getXPosition() + 30) > 800))
{
direction = false;
}
else if (!(direction) && (getXPosition() - 30) < 0)
{
direction = true;
}

if (direction)
{
setXPosition(getXPosition() + 30);
}

else
setXPosition(getXPosition() - 30);
cout << "Jet move to " << getXPosition() << "," << getYPosition() << " ";
}
//object is dead
else
{
cout << "Jet's destroyed parts remain at " << getXPosition() << "," << getYPosition() << " ";
}
}
void Jet::fire_weapon()
{
cout << "Jet fires weapon: ";
//check if object is not dead
if (getStatus() != 0)
{
//check if has ammo
if (ammo != 0)
{
ammo--;
cout << "missile (" << ammo << " left)" << endl;
}
//does not have ammo
else
{
cout << "none (no ammo available)" << endl;
}
}
//object is dead
else
{
cout << "dead" << endl;
}

}
void Jet::update_status()
{
//check if object is not dead or about to die
if (getStatus() > 1)
{
setStatus(getStatus() - 1);
cout << "Jet update status: hit by bullet, status points: " << getStatus() << " (ping)" << endl;
}
//object is dead
else
cout << "Jet update status: hit by bullet, status points: 0 (dead)" << endl;
}
/***************** File name: Soldier.h *****************/
#pragma once
#include <iostream>
#include "Enemy.h"

using namespace std;
// Create child class named Soldier.
class Soldier :public Enemy
{
private:
// Declare the private data members
bool direction;//true = right; false = left
int ammo;
public:
// Declare the methods.
Soldier();
void move_position();
void fire_weapon();
void update_status();
};
/***************** File name: Soldier.cpp *****************/
//#include "stdafx.h"
#include <iostream>
#include "Enemy.h"
#include "Soldier.h"

using namespace std;

Soldier::Soldier()
{
setXPosition(0);
setYPosition(500);
setStatus(4);
direction = true;
ammo = 20;
}
void Soldier::move_position()
{
//check if object is not dead
if (getStatus() != 0)
{
//check to make sure it won't move past 2D space boundary
//object will change direction if it would go past boundary
if ((direction) && (getXPosition() + 5) > 800)
{
direction = false;
}
else if (!(direction) && (getXPosition() - 5) < 0)
{
direction = true;
}
//move to right
if (direction)
{
setXPosition(getXPosition() + 5);
}
//move to left
else
setXPosition(getXPosition() - 5);
cout << "Soldier move to " << getXPosition() << "," << getYPosition() << " ";
}
//object is dead
else
cout << "Soldier's dead body remains at " << getXPosition() << "," << getYPosition() << " ";
}
void Soldier::fire_weapon()
{
cout << "Soldier fires weapon: ";
//check if object is not dead
if (getStatus() != 0)
{
//check if has ammo
if (ammo != 0)
{
ammo--;
cout << "arm cannon (" << ammo << " left)" << endl;
}
//does not have ammo
else
cout << "none (no ammo available)" << endl;
}
//object is dead
else
cout << "dead" << endl;
}
void Soldier::update_status()
{
//check if object is not dead or about to die
if (getStatus() > 1)
{
setStatus(getStatus() - 1);
cout << "Soldier update status: hit by bullet, status points: " << getStatus() << " (ouch)" << endl;
}
//object is dead
else
cout << "Soldier update status: hit by bullet, status points: 0 (dead)" << endl;
}

/***************** File name: main.cpp *****************/
//#include "stdafx.h"
// Header files section
// User defined header files
#include "Enemy.h"
#include "Jet.h"
#include "PitBull.h"
#include "Soldier.h"
// Pre defined header files
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>


using namespace std;

int main(int argc, char* argv[])
{
const int max_enemy = 20;
// Declare an arry of objects.
Enemy* enemy_ptr[max_enemy];
int num_enemy;
srand((unsigned int)time(NULL));

// create Enemy objects, place in array
enemy_ptr[0] = new Jet();
enemy_ptr[1] = new PitBull();
enemy_ptr[2] = new Soldier();
// set value of num_enemy
num_enemy = 3;
while (true)
{

  
for (int i = 0; i < num_enemy; i++)
{
enemy_ptr[i]->move_position();
}
cout << endl;
  
int RandIndex = rand() % num_enemy;
enemy_ptr[RandIndex]->fire_weapon();
  
RandIndex = rand() % num_enemy;
enemy_ptr[RandIndex]->update_status();
_getch();
cout << endl;
}
return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
CIS4100 Final Project Description The Objective of this Final Project is to implement the theoretical concepts...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to...

    Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to display several different types (classes) of objects. Let's say, we want to display three objects of type Deer, two objects of type Tree and one object of type Hill. Each of them contains a method called display. We would like to store their object references in a single array and then call their method display one by one in a loop. However, in Java,...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in...

    Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...

  • Project Description Complete the Film Database program described below. This program allows users to store a...

    Project Description Complete the Film Database program described below. This program allows users to store a list of their favorite films. To build this program, you will need to create two classes which are used in the program’s main function. The “Film” class will store information about a single movie or TV series. The “FilmCollection” class will store a set of films, and includes functions which allow the user to add films to the list and view its contents. IMPORTANT:...

  • *IN PYTHON* A role-playing game or RPG is a game in which players assume the roles...

    *IN PYTHON* A role-playing game or RPG is a game in which players assume the roles of characters in a fictional setting. The popularity of the epic saga told in J.R.R. Tolkien's The Hobbit and The Lord of The Rings greatly influenced the genre, as seen in the game Dungeons & Dragons and all of its subsequent variants. In most RPGs, a player creates a character of a specific archetype or class, such as "Fighter", "Wizard", or "Thief". (Note: do...

  • CIS247C Week 3 Project Overview The objective of this week is to enhance last week's Vehicle cla...

    CIS247C Week 3 Project Overview The objective of this week is to enhance last week's Vehicle class by making the following changes: • Create a static variable called numVehicles that holds an int and initialize it to zero. This will allow us to count all the Vehicle objects created in the main class. • Add the copy constructor • Increment numVehicles in all of the constructors • Decrement numVehicle in destructor • Add overloaded versions of setYear and setMpg that...

  • Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...

    Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...

  • c++ Part 1 Consider using the following Card class as a base class to implement a...

    c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...

  • In this hormework, you will implement a simple caledar application The implernentation shauld inc...

    Do that with C++ and please add more comment that make it understandable In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar, an abstract class named Event and two concrete classes narmed Task and Appointment which irherit from the Evernt class. The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which desigate the tirne of the event. It...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT