diff --git a/Monkey.cpp b/Monkey.cpp new file mode 100644 index 0000000..9e8de19 --- /dev/null +++ b/Monkey.cpp @@ -0,0 +1,75 @@ +#include "Monkey.h" +#include "Forest.h" + +#include +#include + +using namespace std; + + +sf::Texture* Monkey::texture = NULL; +Monkey::Monkey() +{ +} + +Monkey::Monkey(){ +}; + + +Monkey::Monkey(double m, double b, int _x, int _y) : Animal(m, b, _x, _y){ +}; + +Monkey::~Monkey(){ +}; + +void Monkey::talk(){ //Monkey's intelligence level is close to human, + // it already can remember three phrases, not more. + int var = rand()%3; + switch(var) { + case 1: + cout << "Who! Who! Who!" << endl; + break; + case 2: + cout<< "Banano!" <loadFromFile("res/monkey.png")) + cout <<"Someone has stolen le monke!" <setTexture(*texture); +} +void Monkey::walk(Forest *f) { //Monkey jumps everywhere! + bool check = false; + int _x = x, _y = y, c = 0; + while(!check) + { + _x = x, _y = y; + bool sign_x = rand()%2; + bool sign_y = rand()%2; + int length = rand()%3+1; + switch (sign_x) //it moves like a bishop in chess + { + case 0: _x+=length; break; + case 1: _x-=length; break; + } + switch (sign_y) + { + case 0: _y+=length; break; + case 1: _y-=length; break; + } + check = f->check(_x, _y); + c++; + if (c >= 20) break; . + } + x = _x, y = _y; +} \ No newline at end of file diff --git a/Monkey.h b/Monkey.h new file mode 100644 index 0000000..7695ee1 --- /dev/null +++ b/Monkey.h @@ -0,0 +1,28 @@ + +#ifndef FOREST_MONKEY_H +#define FOREST_MONKEY_H + +#include "Animal.h" +#include "Carnivore.h" +#include "Herbivore.h" + +#include + +class Monkey : public Animal, public Carnivore, public Herbivore +{ + //Monkey is free enough to eat whatever it wants, it can eat meat either plants. + //Dramatically there are no enough small animals to be eaten by Monkey. + //We hope it'll find them soon. +public: + Monkey(); + Monkey(double m, double b); + Monkey(double m, double b, int _x, int _y); + ~Monkey(); + void talk() override; + void setSprite() override; + void walk(Forest *f) override; //it also jumps in a special way( not especially special). +private: + static sf::Texture *texture; +}; + +#endif //FOREST_MONKEY_H diff --git a/res/monkey.png b/res/monkey.png new file mode 100644 index 0000000..c3251b3 Binary files /dev/null and b/res/monkey.png differ