-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.cpp
More file actions
184 lines (169 loc) · 4.85 KB
/
Copy pathglobal.cpp
File metadata and controls
184 lines (169 loc) · 4.85 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
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
181
182
183
184
#include "global.h"
/*int window_width = 800;
int window_height = 600;
int field_width = 600;
int field_height = 600;
int NumOfTower = 5;*/
int TowerRadius[] = {80, 80, 70, 110, 150};
char WasteClass[][20] = {"brick", "wire", "drink", "paper"};
int TowerWidth[] = {72, 66, 72, 59, 45};
int TowerHeight[] = {121, 108, 69, 98, 112};
int typesOfwaste = 4;
int rows = (int)field_height/grid_height;
int cols = (int)field_width / grid_width;
std::vector<std::vector<bool>>check_grid = std::vector<std::vector<bool>>(rows, std::vector<bool>(cols, false));
std::vector<std::vector<Waste>>grid = std::vector<std::vector<Waste>>(rows, std::vector<Waste>(cols));
//Brick information begin
int Brick_w=50;
int Brick_h=50;
int Brick_v=10;
int Brick_n=20;
//Brick information end
//Wire information begin
int Wire_w=50;
int Wire_h=50;
int Wire_v=15;
int Wire_n=20;
//Wire information end
//Drink information begin
int Drink_w=50;
int Drink_h=50;
int Drink_v=12;
int Drink_n=20;
//Drink information end
//Paper information begin
int Paper_w=50;
int Paper_h=50;
int Paper_v=-100;
int Paper_n=2;
//Paper information end
int npc_sourceX = 78;
int hint = 6;
int score = 0;
int waste_num = Brick_n+Wire_n+Drink_n+Paper_n;
std::vector<int>typeNum ={Brick_n, Wire_n, Drink_n, Paper_n};
std::vector<Waste> waste_set;
void draw_waste()
{
for (int i=0; i<rows ; i++){
for (int j=0 ; j<cols ; j++){
if (check_grid[i][j] && grid[i][j].found())
grid[i][j].Draw();
}
}
}
void init_grid()
{
std::vector<std::pair<int,int>>ind;
std::set<std::pair<int,int>>ind_set;
srand(time(nullptr));
//generate random coord
std::cout<<"generating random coordinates"<<std::endl;
while(waste_num > (int)ind_set.size())
{
int tmpx = rand()%rows;
int tmpy = rand()%cols;
auto coord = std::make_pair(tmpx,tmpy);
if(ind_set.find(coord)==ind_set.end())
{
ind_set.insert(coord);
ind.push_back(coord);
}
}
std::cout<<"finish generating random coordinates"<<std::endl;
for(WasteType t = BRICK;t<=PAPER; t = WasteType(t+1))
{
std::cout<<"t:"<<t<<std::endl;
while(typeNum[t]--)
{
auto coord = ind.back();
int tmpx = coord.first;
int tmpy = coord.second;
check_grid[tmpx][tmpy] = true;
switch (t){
case BRICK:
//std::cout<<"generating brick"<<std::endl;
grid[tmpx][tmpy] = Waste(
tmpx,
tmpy,
Brick_w,
Brick_h,
t,
Brick_v
);
break;
case WIRE:
//std::cout<<"generating wire"<<std::endl;
grid[tmpx][tmpy] = Waste(
tmpx,
tmpy,
Wire_w,
Wire_h,
t,
Wire_v
);
break;
//grid[tmpx][tmpy].PrintInfo();
//std::cout<<"finish generating wire"<<std::endl;
case DRINK:
//std::cout<<"generating drink"<<std::endl;
grid[tmpx][tmpy] = Waste(
tmpx,
tmpy,
Drink_w,
Drink_h,
t,
Drink_v
);
break;
//std::cout<<"generating drink"<<std::endl;
case PAPER:
//std::cout<<"generating paper"<<std::endl;
grid[tmpx][tmpy] = Waste(
tmpx,
tmpy,
Paper_w,
Paper_h,
t,
Paper_v
);
break;
//std::cout<<"generating paper"<<std::endl;
}
//print_grid();
//waste_set.push_back(grid[tmpx][tmpy]);
ind.pop_back();
}
}
}
void print_grid()
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if(check_grid[i][j] && grid[i][j].get_type() == 3) grid[i][j].PrintInfo();
}
}
}
void set_empty(int x,int y)
{
//check_grid[x][y] = false;
}
int get_waste_value(int x,int y)
{
return grid[x][y].get_value();
}
bool isfull(int x,int y)
{
return check_grid[x][y];
}
bool map_empty(){
for (int i=0; i<rows ; i++){
for (int j=0 ; j<cols ; j++){
if (check_grid[i][j] && !grid[i][j].found())
return false;
}
}
return true;
}