-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchore-game.cpp
More file actions
87 lines (73 loc) · 1.83 KB
/
chore-game.cpp
File metadata and controls
87 lines (73 loc) · 1.83 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
#include "engine.h"
class ChoreGame : public Engine
{
// (x, y) location of the player
int x = 0;
int y = 0;
// boolean flags to keep track of whether each mission has been completed
bool _schoolMissionCompleted = false;
bool _bankMissionCompleted = false;
void setup()
{
createCanvas(10,10);
}
void keyPressed(int keyCode)
{
switch (keyCode)
{
case 'd':
x = x + 1;
break;
case 'a':
x = x - 1;
break;
case 'w':
y = y - 1;
break;
case 's':
y = y + 1;
break;
}
}
void draw()
{
clear();
stroke("🏫");
point(2, 2);
stroke("🏦");
point(4, 4);
stroke("🚗");
point(x, y);
}
void console()
{
if (y == 4 && x == 4 && !_bankMissionCompleted)
{
cout << "You have arrived at the bank." << endl;
cout << "How much do you want to withdraw? " ;
string c;
cin >> c;
cout << "You have withdrawn " << c << " dollars." << endl;
_bankMissionCompleted = true;
pause();
}
else if (y == 2 && x == 2 && !_schoolMissionCompleted)
{
cout << "You arrived at the school." << endl;
cout << "You dropped off your children." << endl;
_schoolMissionCompleted = true;
pause();
}
else if (_bankMissionCompleted && _schoolMissionCompleted)
{
cout << "You completed all the missions!" << endl;
cout << endl << endl;
quit();
}
}
};
int main()
{
ChoreGame game;
game.play();
}