-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackGround.cpp
175 lines (154 loc) · 4.19 KB
/
BackGround.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
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "iostream"
#include <windows.h>
#include "fstream"
using namespace std;
#define EASY 4 // Matrix size is 4x4
#define MEDIUM 6 // Matrix size is 6x6
#define HARD 8 // Matrix size is 8x8
#define WORD_WIDTH_SPACING 8
#define WORD_HEIGHT_SPACING 3
// Set cursor position
void GoTo(SHORT posX, SHORT posY)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Position;
Position.X = posX;
Position.Y = posY;
SetConsoleCursorPosition(hStdout, Position);
}
struct Selected
{
SHORT posX;
SHORT posY;
bool isSelected;
};
// Calculate position of the word in the console
int calculatePositionWidth(int posInMatrix, int difficulty)
{
return (WORD_WIDTH_SPACING + 1) * posInMatrix + 8; // +8 is for the border
}
int calculatePositionHeight(int posInMatrix, int difficulty)
{
return (WORD_HEIGHT_SPACING + 1) * posInMatrix + 4; // +4 is for the border
}
struct BackGround
{
string **BG;
void GetBG(int difficulty);
void PrintBG(int difficulty, Selected A);
};
/* void BackGround::GetBG(int difficulty)
{
int sizeBG = difficulty * difficulty;
BG = new string *[sizeBG];
for (int i = 0; i < sizeBG; i++)
{
BG[i] = new string[5];
}
ifstream file;
// Open 2.txt in Background folder
file.open("./BackGround/1.txt");
if (file.is_open())
{
string temp;
for (int i = 0; i < difficulty; i++) // Number of row in matrix pikachu
{
for (int j = 0; j < 5; j++) // 5 is the width of the cube
{
getline(file, temp);
for (int k = 0; k < difficulty; k++) // Number of column in matrix pikachu
{
// Cut the string for 9 characters
BG[i + k * difficulty][j] += temp.substr(k * difficulty, k * difficulty + 9);
}
}
}
}
else
{
cout << "Unable to open file" << endl;
}
file.close();
}
void BackGround::PrintBG(char **a, int difficulty, Selected A)
{
int position = A.posY + A.posX * difficulty;
int posY = calculatePositionHeight(A.posY, difficulty);
int posX = calculatePositionWidth(A.posX, difficulty);
for (int i = 0; i < 5; i++)
{
GoTo(posX, posY++);
cout << BG[position][i];
}
} */
void BackGround::GetBG(int difficulty)
{
int sizeBG = difficulty * difficulty;
BG = new string *[sizeBG];
for (int i = 0; i < sizeBG; i++)
{
BG[i] = new string[4];
}
ifstream file;
// Open 2.txt in Background folder
file.open("./BackGround/1.txt");
if (file.is_open())
{
string temp;
for (int i = 0; i < difficulty; i++) // Number of row in matrix pikachu
{
for (int j = 0; j < 4; j++) // 4 is the width of the cube with not overlap the next cube
{
getline(file, temp);
for (int k = 0; k < difficulty; k++) // Number of column in matrix pikachu
{
// Cut the string for 9 characters
BG[i + k * difficulty][j] += temp.substr(k * difficulty, k * difficulty + 9);
}
}
}
}
else
{
cout << "Unable to open file" << endl;
}
file.close();
}
void BackGround::PrintBG(int difficulty, Selected A)
{
if (A.posX < 0 || A.posY < 0 || A.posX >= difficulty || A.posY >= difficulty)
return;
// SetColor(BLACK, WHITE);
int position = A.posY + A.posX * difficulty;
int posY = calculatePositionHeight(A.posY, difficulty);
int posX = calculatePositionWidth(A.posX, difficulty);
for (int i = 0; i < 4; i++)
{
GoTo(posX, posY++);
wcout << BG[position][i].c_str();
}
if (A.posY == difficulty - 1)
{
GoTo(posX, posY++);
wprintf(L" ");
}
}
int main(int argc, char **argv)
{
BackGround backGround;
char **a = new char *[HARD];
backGround.GetBG(HARD);
// Print the background
for (SHORT i = 0; i < HARD; i++)
{
for (SHORT j = 0; j < HARD; j++)
{
backGround.PrintBG(HARD, {i, j});
}
}
system("pause");
return 0;
}