-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorld.cpp
180 lines (150 loc) · 3.31 KB
/
World.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <iostream>
#include <fstream>
#include "World.h"
#include "plotter.h"
const int MAX_X = 85;
const int MIN_X = 0;
const int MAX_Y = 53;
const int MIN_Y = 0;
using namespace std;
void World::drawWorld()
{
setConsoleSize(54, 86);
p.setColor(magenta);
for(int i = 0; i < 85; i++)
{
p.plot(i, 26, SQUARE);
p.plot(i, 27, SQUARE);
p.plot(i, 52, SQUARE);
p.plot(i, 53, SQUARE);
}
s.drawStreet();
r.drawRiver();
for( int i = 1; i <= 5; i++ )
{
wz[i-1].drawWinZone(i);
}
}
/***********************
author: Kyle
function: setConsoleSize(int, int)
input: an int for rows and and int for columns
desc: changes the size of the terminal window
***********************/
void World::setConsoleSize(int rows, int columns)
{
_COORD coord;
coord.X = columns;
coord.Y = rows;
_SMALL_RECT rect;
rect.Top = 0;
rect.Left = 0;
rect.Bottom = rows - 1;
rect.Right = columns - 1;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleScreenBufferSize(handle, coord);
SetConsoleWindowInfo(handle, TRUE, &rect);
}
/***********************
author: Kyle
function: setup()
desc: displays the start screen
exception: throws an exception if ifstream can not be opened
***********************/
void World::setup() throw(char const*)
{
ifstream startScreen("startScreen.txt");
string sScreen;
char in;
if( !startScreen )
{
throw "\n\nCan't Find ASCII Art\n\n";
}
while( startScreen.get(in) )
{
sScreen += in;
}
startScreen.close();
setConsoleSize(28,81);
cout << sScreen;
}
/***********************
author: Kyle
function: quit()
desc: clears screen, displays the end screen
exception: throws an exception if ifstream can not be opened
***********************/
void World::quit(int lives) throw(char const*)
{
system("CLS"); //clear screen
fstream endScreen;
if( lives > 0 )
{
setConsoleSize(35,35);
endScreen.open("winScreen.txt");
string wScreen;
char in;
while( endScreen.get(in) )
{
wScreen += in;
}
endScreen.close();
cout << wScreen;
}
else
{
setConsoleSize(35,40);
endScreen.open("loseScreen.txt");
string lScreen;
char in;
while( endScreen.get(in) )
{
lScreen += in;
}
endScreen.close();
cout << lScreen;
}
}
void World::update(char a)
{
int num = -1;
bool inWinZone = false;
for( int i = 0; i < 5 && !inWinZone; i++ )
{
if( f.getColNum() > wz[i].getColNum() && f.getColNum() < wz[i].getColNum()+5 )
{
if( f.getRowNum() == 3 )
{
inWinZone = true;
num = i;
}
}
}
switch( a )
{
case vk_up:
if( !wz[num].isFull(num) )
{
f.moveUp();
}
if( f.getRowNum() == 0 && inWinZone )
{
f.win();
wz[num].fill(num);
}
if( f.getRowNum() == 0 && !inWinZone )
{
f.die();
}
break;
case vk_down:
f.moveDown();
break;
case vk_left:
f.moveLeft();
break;
case vk_right:
f.moveRight();
break;
}
}