-
Notifications
You must be signed in to change notification settings - Fork 1
/
Frog.cpp
161 lines (139 loc) · 2.35 KB
/
Frog.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include "Frog.h"
#include "plotter.h"
const int MAX_COL = 81;
const int MIN_COL = 1;
const int MAX_ROW = 52;
const int MIN_ROW = 0;
Frog::Frog()
{
color = 'g';
winCount = 0;
numLives = 5;
rowNum = 52;
colNum = 41;
}
void Frog::moveUp()
{
setColor();
drawFrog(color);
if( rowNum > MIN_ROW )
{
if( rowNum == 52 || rowNum == 29 || rowNum == 26 || rowNum == 3 )
{
rowNum -= 3;
}
else
{
rowNum -= 5;
}
}
color = 'g';
drawFrog(color);
}
void Frog::moveDown()
{
setColor();
drawFrog(color);
if( rowNum < MAX_ROW && rowNum > 2 )
{
if( rowNum == 49 || rowNum == 26 || rowNum == 23 )
{
rowNum += 3;
}
else
{
rowNum += 5;
}
}
color = 'g';
drawFrog(color);
}
void Frog::moveLeft()
{
setColor();
drawFrog(color);
if( colNum > MIN_COL )
{
colNum -= 5;
}
color = 'g';
drawFrog(color);
}
void Frog::moveRight()
{
setColor();
drawFrog(color);
if( colNum < MAX_COL )
{
colNum += 5;
}
color = 'g';
drawFrog(color);
}
void Frog::setColor()
{
if( rowNum == 52 || rowNum == 26 )
{
color = 'm';
}
if( rowNum > 26 && rowNum < 52 )
{
color = 'b';
}
if( rowNum > -1 && rowNum < 26 )
{
color = 'd';
}
}
void Frog::drawFrog( char c )
{
if( winCount < 5 )
{
switch(c)
{
case 'm':
p.setColor(magenta);
break;
case 'b':
p.setColor(black);
break;
case 'd':
p.setColor(darkblue);
break;
case 'w':
p.setColor(white);
break;
default:
p.setColor(darkgreen);
break;
}
for( int i = colNum; i < colNum + 3; i++ )
{
p.plot(i, rowNum, SQUARE);
p.plot(i, rowNum+1, SQUARE);
}
}
}
void Frog::win()
{
if( winCount < 5 )
{
winCount++;
}
color = 'g';
rowNum = 52;
colNum = 41;
drawFrog(color);
}
void Frog::die()
{
//show a big red X on the screen
setColor();
drawFrog(color);
numLives--;
color = 'g';
rowNum = 52;
colNum = 41;
drawFrog(color);
}