Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Monkey.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "Monkey.h"
#include "Forest.h"

#include <iostream>
#include <SFML/Graphics.hpp>

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!" <<endl;
break;
default:
cout<< "Aaaaaaa!" <<endl;
break;
}
}
void Monkey::setSprite()
{
if (!texture)
{
texture = new sf::Texture;
if (!texture->loadFromFile("res/monkey.png"))
cout <<"Someone has stolen le monke!" <<endl;
}
s = new sf::Sprite;
s->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;
}
28 changes: 28 additions & 0 deletions Monkey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#ifndef FOREST_MONKEY_H
#define FOREST_MONKEY_H

#include "Animal.h"
#include "Carnivore.h"
#include "Herbivore.h"

#include <SFML/Graphics.hpp>

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
Binary file added res/monkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.