-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sand.cpp
73 lines (61 loc) · 1.5 KB
/
Sand.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
/**********************************************************
** Program Name: final project
** Author: Taylor Jones
** Date: 3/6/2018
** Description: Sand.cpp is the class implementation
** file for the Sand class. This file contains
** definitions for the member functions of the Sand class.
**********************************************************/
#include "Sand.hpp"
#include "Element.hpp"
#include "Alien.hpp"
/**
* @name Sand
* @brief Sand class constructor
* @param none
* @return none
*/
Sand::Sand() {
this->name = "Sand";
this->backColor = YELLOW;
}
/**
* @name ~Sand
* @brief Sand class destructor
* @param none
* @return none
*/
Sand::~Sand() = default;
/**
* @name spaceType
* @brief returns this Space's SpaceType
* @param none
* @return SAND
*/
SpaceType Sand::spaceType() {
return SAND;
}
/**
* @name experience
* @brief while experiencing Sand, there's a 1/3 chance that the experiencer
* is not able to move
* @param experiencer - a pointer to the Element experiencing the sand
* @return void
*/
void Sand::experience(Element* experiencer) {
if (experiencer != nullptr && experiencer->getElementType() == ALIEN) {
auto* alien = dynamic_cast<Alien*>(experiencer);
if (randInt(1, 2) == 2) {
alien->move(alien->getPrevSpace());
alien->experienceSpace();
}
alien->adjustEnergy(-1);
}
}
/**
* @name init
* @brief Sand class initializer (not needed)
* @param none
* @return void
*/
void Sand::init() {}