-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBoard.cpp
128 lines (99 loc) · 2.5 KB
/
Board.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
//
// Created by nazar on 2/27/19.
//
#include "Board.h"
Board::Board(wxPanel* parent_t, wxFrame *fr)
: wxPanel(parent_t, -1, wxPoint(5, 5), wxSize(170, 310), wxBORDER_SUNKEN)
{
status_scr = fr->GetStatusBar();
pieceFallingFinished = false;
started = false;
paused = false;
score = 0;
lvl = 1;
curX = 0;
curY = 0;
panel = parent_t;
PieceShape tmp;
tmp = PieceShape(rand()%7+1);
next.SetShape(tmp);
ClearBoard();
// std::cout << "BOARD mather - constructor vide" << std::endl;
}
void Board::ClearBoard()
{
for (int i = 0; i < BoardHeight * BoardWidth; i++)
board[i] = None;
}
int Board::CalculatorScore(int points, int n) {
return points*(n+1);
}
bool Board::DoMove(const Piece& piece, int newX, int newY)
{
for (int i = 0; i < 4; i++)
{
int x = newX + piece.x(i);
int y = newY - piece.y(i);
if (!CheckBounds(x, y) || PieceCheck(x, y) != None)
return false;
}
current = piece;
curX = newX;
curY = newY;
Refresh();
return true;
}
void Board::DrawPieceSquare(wxPaintDC& dc, int x, int y, PieceShape pieceShape)
{
wxPen lightPen(light[int(pieceShape)]);
lightPen.SetCap(wxCAP_PROJECTING);
dc.SetPen(lightPen);
dc.DrawLine(x, y + Height() - 1, x, y);
dc.DrawLine(x, y, x + Width() - 1, y);
wxPen darkPen(dark[int(pieceShape)]);
darkPen.SetCap(wxCAP_PROJECTING);
dc.SetPen(darkPen);
dc.DrawLine(x + 1, y + Height() - 1, x + Width() - 1, y + Height() - 1);
dc.DrawLine(x + Width() - 1, y + Height() - 1, x + Width() - 1, y + 1);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(colors[int(pieceShape)]));
dc.DrawRectangle(x + 1, y + 1, Width() - 2, Height() - 2);
}
void Board::setNextOrCurrentPiece(char c, int current_next){
PieceShape ps;
if(current_next == 1) {
curX = BoardWidth / 2;
curY = BoardHeight - 1 + current.MinY();
}
switch (c)
{
case 'I':
ps = I_long;
break;
case 'O':
ps = O_bloc;
break;
case 'T':
ps = T;
break;
case 'L':
ps = L;
break;
case 'J':
ps = J;
break;
case 'Z':
ps = Z;
break;
case 'S':
ps = S;
break;
default:
ps = None;
}
if(current_next==1){
next.SetShape(ps);
}else{
current.SetShape(ps);
}
}