-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.cpp
97 lines (88 loc) · 1.93 KB
/
operation.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
#include "stdafx.h"
#include "operation.h"
void operation::generate_random()
{
random = rand() % 7;
obj.block_generate(random);
}
void operation::change_block_pos(vector<pair<int, int>> &block_pos, vector<vector<char>> &map, int shift_a, int shift_b)
{
for (auto i : block_pos)
{
map[i.first][i.second] = ' ';
}
block_pos = obj.get_block();
for (int i = 0; i < block_pos.size(); i++)
{
block_pos[i].first += shift_a;
block_pos[i].second += shift_b;
}
}
void operation::display_on_map(vector<vector<char>> &map, vector<pair<int, int>> block_pos)
{
for (auto i : block_pos)
{
map[i.first][i.second] = 'o';
}
}
void operation::push_to_map(vector<vector<char>> &map, vector<pair<int, int>> &block_pos)
{
for (int i = 0 ; i<block_pos.size();i++)
{
map[block_pos[i].first][block_pos[i].second] = 'O';
block_pos[i].first = 1;
block_pos[i].second = 1;
}
}
void operation::call_rotate()
{
obj.block_rotate();
}
bool operation::attach_left_right(vector<pair<int, int>> block_pos)
{
int min, max;
min = std::min({ block_pos[0].second, block_pos[1].second, block_pos[2].second, block_pos[3].second });
max = std::max({ block_pos[0].second, block_pos[1].second, block_pos[2].second, block_pos[3].second });
if (max == 11 || min == 0)
return true;
else
return false;
}
bool operation::attach_bottom(vector<pair<int, int>> block_pos, vector<vector<char>> map)
{
for (auto i : block_pos)
{
if (map[i.first + 1][i.second] == 'O' || map[i.first + 1][i.second] == '#')
return true;
}
return false;
}
void operation::elimination(vector<vector<char>> &map)
{
for (int i = 1; i < 21; i++)
{
bool switcher = true;
for (int j = 1; j < 11; j++)
{
if (map[i][j] != 'O')
{
switcher = false;
break;
}
}
if (switcher)
{
for (int j = 1; j < 11; j++)
{
map[i][j] = ' ';
}
for (int a = i - 1; a > 0; a--)
{
for (int b = 1; b < 11; b++)
{
swap(map[a][b], map[a+1][b]);
}
}
}
}
}