ok this is what i got so far:
and i will add the other characters i just want to know am i on the right track ^^
Body.h
Body.cppCode:#pragma once #include"RandomNumber.h" class Body { private: RandomNumber Random; protected: int x; int y; int move; int moved; public: Body(void); ~Body(void); int get_rand(int); void set_position(int); virtual void Move(void); virtual bool IsHumanInRange(Body &); virtual void Hunt(Body &); };
man.hCode:#include<iostream> #include<time.h> #include<stdlib.h> #include"Body.h" #include"RandomNumber.h" Body::Body(void) { int x = 0; int y = 0; int move = 0; int moved = 0; } int Body::get_rand(int upper) { return Random.rand_gen(upper); } void Body::set_position(int range) { x = get_rand(range); y = get_rand(range); } Body::~Body(void) { }
man.cppCode:#pragma once #include"Body.h" class Man: public Body { public: virtual void move(void); void show_position(void); };
zombie.hCode:#include<iostream> #include"console.h" #include"Man.h" #include"Body.h" void Body::Move(void) { std::cin>> move; if((move == 8)&&(moved != 2)) { y = y - 1; } else if((move == 2)&&(moved != 8)) { y = y + 1; } else if((move == 6)&&(moved != 4)) { x = x + 1; } else if((move == 4)&&(moved != 6)) { x = x - 1; } moved = move; } void Man::show_position(void) { gotoxy(x,y); { std::cout<< "M"; } }
Code:#pragma once #include"Body.h" class Zombie: public Body { public: virtual void Move(void); virtual void Hunt(Body &); void show_position(void); };a question:Code:#include<iostream> #include"console.h" #include"Zombie.h" #include"Body.h" void Body::Move(void) { int choice; choice = get_rand(4); if(choice == 0) { y = y - 1; } else if(choice == 1) { y = y + 1; } else if(choice == 2) { x = x + 1; } else { x = x - 1; } } void Body::Hunt(Body & body) { if(this->x > body.x) { this->x = this->x - 1; } else if (this->x < body.x) { this->x = this->x + 1; } else if(this->y > body.y) { this->y = this->y - 1; } else if(this->y < body.y) { this->y = this->y + 1; } } void Zombie::show_position(void) { gotoxy(x,y); { std::cout<< "Z"; } }
class Badger: public Body
{
public:
void ~movement(void) why the (~) destructor there?
and i declined
virtual void Move(void);
virtual bool IsHumanInRange(Body &);
virtual void Hunt(Body &);
in body but defined them individually in man and zombie. Now i need to define "virtual bool IsHumanInRange(Body &);" in zombie or body?
thanks, i do get your idea, but since i am still new to C++ i want to ask all the question i can xD sorry if i get annoying




Reply With Quote