-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_input.h
More file actions
205 lines (171 loc) · 3.65 KB
/
grid_input.h
File metadata and controls
205 lines (171 loc) · 3.65 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#pragma once
#include <iostream>
#include <conio.h>
#include "windows.h"
#include <fstream>
using namespace std;
class grid_input {
int w;
int row;
int col;
int sx;
int sy;
int dx;
int dy;
int **grid;
public:
grid_input()
{
grid = NULL;
}
grid_input(const grid_input& g)
{
this->w = g.w;
this->row = g.row;
this->col = g.col;
this->sx = g.sx;
this->dx = g.dx;
this->dy = g.dy;
this->grid = new int*[row];
for (int i = 0; i < row; i++)
{
this->grid[i] = new int[col];
for (int j = 0; j < col; j++)
{
this->grid[i][j] = g.grid[i][j];
}
}
}
int get_width()
{
return w;
}
int get_row()
{
return row;
}
int get_col()
{
return col;
}
bool is_clear(const int &r, const int &c)
{
bool flag = (grid[r][c] == 1);
return flag;
}
void del_obj_draw_hurdle(HPEN p, HBRUSH b)
{
DeleteObject(p);
DeleteObject(b);
}
void SetWindow(HWND &cw, HDC &dc)
{
cw = GetConsoleWindow();
dc = GetDC(cw);
}
HBRUSH draw_with_brush(const int& r, const int& g, const int& b, const HDC dc)
{
HBRUSH brush = ::CreateSolidBrush(RGB(r, g, b));
SelectObject(dc, brush);
return brush;
}
HPEN draw_with_pen(const int &px, const int& r, const int& g, const int& b, const HDC dc)
{
HPEN p = CreatePen(PS_SOLID, px, RGB(r, g, b));
SelectObject(dc, p);
return p;
}
void draw_hurdle(const int& a, const int& b, const int& x, const int& y, const int& R, const int& G, const int& B, const int& r1, const int& g1, const int& b1)
{
HWND cw = GetConsoleWindow();
HDC dc = GetDC(cw);
SetWindow(cw, dc);
HPEN p = draw_with_pen(1, R, G, B, dc);
HBRUSH d = draw_with_brush(r1, g1, b1, dc);
Rectangle(dc, a, b, x, y);
ReleaseDC(cw, dc);
del_obj_draw_hurdle(p, d);
}
void draw_coordinates(const int& a, const int& b, const int& r1, const int& g1, const int& b1, const int& rb, const int& gb, const int& bb)
{
draw_hurdle(a * w, b * w, a * w + w, b * w + w, r1, g1, b1, rb, gb, bb);
}
void draw_grid_with_hurdles(const int& i, const int& j, const int& a, const int& b)
{
if (grid[i][j] == 1)
draw_coordinates(a, b, 0, 0, 0, 200, 200, 200);
else if (grid[i][j] == 0)
draw_coordinates(a, b, 255, 255, 255, 75, 158, 86);
else if (grid[i][j] == 2)
draw_coordinates(a, b, 255, 255, 255, 2, 2, 122);
else if (grid[i][j] == 3)
draw_coordinates(a, b, 255, 255, 255, 141, 70, 172);
else if (grid[i][j] == 4)
draw_coordinates(a, b, 255, 255, 255, 105, 84, 35);
}
void draw_grid(const int &x1, const int& x2, const int& y1, const int& y2)
{
int a, b;
a = b = 0;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
draw_coordinates(a, b, 255, 255, 255, 75, 158, 86);
draw_grid_with_hurdles(i, j, a, b);
if (i == y1 && j == y2)
draw_coordinates(a, b, 0, 0, 0, 255, 25, 30);
else if (i == x1 && j == x2)
draw_coordinates(a, b, 0, 0, 0, 0, 255, 0);
a++;
}
a = 0;
b++;
}
}
bool FileRead(string gri, string size)
{
fstream fin(gri);
fstream fin1(size);
if (fin && fin1)
{
fin1 >> row;
fin1 >> col;
grid = new int*[row];
for (int i = 0; i < row; i++)
{
grid[i] = new int[col];
for (int j = 0; j < col; j++)
{
fin >> grid[i][j];
}
}
fin.close();
fin1.close();
return true;
}
else
{
cout << "\nFile Not Opened! Hence, program will terminate now!\n" << endl;
return false;
}
}
grid_input(char* f1, char* f1_size, const int &wide)
{
ifstream fin(f1);
ifstream fin_size(f1_size);
if (!FileRead(f1, f1_size))
exit(0);
w = wide;
}
~grid_input()
{
for (int i = 0; i < row; i++)
{
delete[] grid[i];
grid[i] = NULL;
}
delete[] grid;
grid = NULL;
}
};