-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboardInit.cpp
More file actions
115 lines (105 loc) · 4.26 KB
/
Copy pathboardInit.cpp
File metadata and controls
115 lines (105 loc) · 4.26 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
#include "board.h"
#include "textureManager.h"
Board::Board(const char* filename, SDL_Renderer* ren)
{
renderer = ren;
boardTexture = TextureManager::LoadTexture(filename, renderer);
movingPieceType = NONE;
redRectangle = std::make_unique<Rectangle>("ChessPieces/red.png", renderer, 1, 1);
gameRunning = true;
int boardR = 0;
pieces.clear();
rectangles.clear();
for (int i = 0; i < HEIGHT; i++)
{
// Get current row on board
boardR = 8 - i;
for (int j = 0; j < WIDTH; j++)
{
rectangles.push_back(std::make_unique<Rectangle>("ChessPieces/blue.png", renderer, i + 1, j + 1));
if (colors[i][j] == EMPTY)
continue;
addPieces(i, j, boardR);
}
}
fromRow = fromCol = toRow = toCol = -1;
// Create seperate instance of each pawn for simplicity
pawn = std::make_shared<Pawn>("ChessPieces/Chess_plt60.png", renderer, 1, 1, WHITE);
rook = std::make_shared<Rook>("ChessPieces/Chess_rlt60.png", renderer, 1, 1, WHITE);
knight = std::make_shared<Knight>("ChessPieces/Chess_ndt60.png", renderer, 1, 1, WHITE);
bishop = std::make_shared<Bishop>("ChessPieces/Chess_ndt60.png", renderer, 1, 1, WHITE);
queen = std::make_shared<Queen>("ChessPieces/Chess_ndt60.png", renderer, 1, 1, WHITE);
whiteKing = std::make_shared<King>("ChessPieces/Chess_ndt60.png", renderer, 1, 5, WHITE);
blackKing = std::make_shared<King>("ChessPieces/Chess_ndt60.png", renderer, 8, 5, BLACK);
// For promotion rectangle
whiteImagesPromotionTextures[0] = TextureManager::LoadTexture("ChessPieces/Chess_nlt60.png", renderer);
whiteImagesPromotionTextures[1] = TextureManager::LoadTexture("ChessPieces/Chess_blt60.png", renderer);
whiteImagesPromotionTextures[2] = TextureManager::LoadTexture("ChessPieces/Chess_rlt60.png", renderer);
whiteImagesPromotionTextures[3] = TextureManager::LoadTexture("ChessPieces/Chess_qlt60.png", renderer);
blackImagesPromotionTextures[0] = TextureManager::LoadTexture("ChessPieces/Chess_ndt60.png", renderer);
blackImagesPromotionTextures[1] = TextureManager::LoadTexture("ChessPieces/Chess_bdt60.png", renderer);
blackImagesPromotionTextures[2] = TextureManager::LoadTexture("ChessPieces/Chess_rdt60.png", renderer);
blackImagesPromotionTextures[3] = TextureManager::LoadTexture("ChessPieces/Chess_qdt60.png", renderer);
}
Board::~Board()
{
rectangles.clear();
pieces.clear();
Mix_FreeChunk(pieceMoveSound);
Mix_FreeChunk(pieceBeatSound);
Mix_Quit();
}
void Board::addPieces(int i, int j, int boardR)
{
switch (board[i][j])
{
case PAWN:
if (colors[i][j] == WHITE)
pieces.push_back(std::make_shared<Pawn>
("ChessPieces/Chess_plt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<Pawn>
("ChessPieces/Chess_pdt60.png", renderer, boardR, j + 1, BLACK));
break;
case ROOK:
if (colors[i][j] == WHITE)
pieces.push_back(std::make_shared<Rook>
("ChessPieces/Chess_rlt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<Rook>
("ChessPieces/Chess_rdt60.png", renderer, boardR, j + 1, BLACK));
break;
case KNIGHT:
if (colors[i][j] == WHITE)
pieces.push_back(std::make_shared<Knight>
("ChessPieces/Chess_nlt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<Knight>
("ChessPieces/Chess_ndt60.png", renderer, boardR, j + 1, BLACK));
break;
case BISHOP:
if (colors[i][j] == WHITE)
pieces.push_back(std::make_shared<Bishop>
("ChessPieces/Chess_blt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<Bishop>
("ChessPieces/Chess_bdt60.png", renderer, boardR, j + 1, BLACK));
break;
case QUEEN:
if (colors[i][j] == WHITE)
pieces.push_back(std::make_shared<Queen>
("ChessPieces/Chess_qlt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<Queen>
("ChessPieces/Chess_qdt60.png", renderer, boardR, j + 1, BLACK));
break;
case KING:
if (colors[i][j] == 'w')
pieces.push_back(std::make_shared<King>
("ChessPieces/Chess_klt60.png", renderer, boardR, j + 1, WHITE));
else if (colors[i][j] == BLACK)
pieces.push_back(std::make_shared<King>
("ChessPieces/Chess_kdt60.png", renderer, boardR, j + 1, BLACK));
break;
}
}