/
animal.cpp
75 lines (65 loc) · 1.14 KB
/
animal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "animal.h"
#include <iostream>
#include <cstdlib>
#include <QRect>
/**
Constructor to load image of animal and reset its state on the board
@pre
@post
@param None
@return None
*/
Animal::Animal()
{
randAnimal();
image.load(picture);
rect = image.rect();
resetState();
}
Animal::~Animal()
{
//std::cout << "Animal deleted\n";
}
void Animal::randAnimal()
{
int rand = std::rand() % 5;
switch(rand)
{
case 0: picture = "turtle.png";
break;
case 1: picture = "donkey.png";
break;
case 2: picture = "fox.png";
break;
case 3: picture = "gazelle.png";
break;
case 4: picture = "cheetah.png";
break;
}
}
void Animal::move(Farmer *f)
{
}
/**
Method to randomly place the animal at the top of the board
@pre Animal is being constructed
@post
@param None
@return None
*/
void Animal::resetState()
{
rand = std::rand() % 1030 + 120;
rect.moveTo(rand, 0);
//std::cout << "X coords: " << getRect().x() << " Y coords: " << getRect().y()<< std::endl;
x = getRect().x();
y = getRect().y();
}
QRect Animal::getRect()
{
return rect;
}
QImage & Animal::getImage()
{
return image;
}