Repository navigation
Expand file tree
/
Copy pathDog.cpp
More file actions
106 lines (95 loc) · 2.89 KB
/
Copy pathDog.cpp
File metadata and controls
106 lines (95 loc) · 2.89 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/******************************************************************************
** Dog Class Implementation File
** Author: Lauren "Ren" Demeis-Ortiz
** Date: 12/5/19
** Description: This is the class implementation file for the Dog class.
******************************************************************************/
#include "Dog.hpp"
#include <iostream>
/*****************************************************************************
** Dog()
** Description: Constructor
*****************************************************************************/
Dog::Dog()
{
name = "DOG NAME";
row = 17;
col = 76;
avatar = 'Q';
isAwake = true;
}
/*****************************************************************************
** changeState(Space*)
** Description: Changes to awake or asleep
*****************************************************************************/
void Dog::changeState(Space*)
{
if(isAwake) // If dog is awake
{
avatar = '@'; // Dog sleeps
isAwake = false;
}
else
{
avatar = 'Q'; // Dog wakes
isAwake = true;
}
}
/*****************************************************************************
** wake(Space*)
** Description: Dog wakes up and moves out of doorway
*****************************************************************************/
void Dog::wake(Space* ptr)
{
if(!isAwake)
{
this->changeState(ptr); // Changes dog's avatar to awake to sleep
if(ptr->moveDown(row, col, 3, avatar)) // If dog can move down
{
this->updatePos(ptr);
}
else if(ptr->moveUp(row, col, 3, avatar))
{
this->updatePos(ptr);
}
else if(ptr->moveLeft(row, col, 3, avatar))
{
this->updatePos(ptr);
}
else
{
std::cout << "Error: couldn't move dog to wake position.\n";
}
}
}
/*****************************************************************************
** sleep(Space*)
** Description: Dog goes to back to sleep at door to next room
*****************************************************************************/
void Dog::sleep(Space* ptr)
{
if(isAwake)
{
this->changeState(ptr); // Changes dog's avatar to sleep
}
if(ptr->getMapName() != "Bedroom" && ptr->getMapName() != "Garden")
{
row = ptr->getNextRow();
col = ptr->getNextCol();
ptr->addChar(row, col, avatar);
}
else // It is the bedroom and garden. Dog sleeps away from door
{
row = ptr->getNextRow() + 2;
col = ptr->getNextCol();
ptr->addChar(row + 2, col, avatar);
}
}
/*****************************************************************************
** getIsAwake()
** Description: Returns isAwake
*****************************************************************************/
bool Dog::getIsAwake()
{
return isAwake;
}