-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardGUI.h
More file actions
116 lines (90 loc) · 4.53 KB
/
Copy pathBoardGUI.h
File metadata and controls
116 lines (90 loc) · 4.53 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
/***********************************************************************//**
* Draw the chessboard with side bar,
* and get input from user (square clicked, promotion, undo)
* during game play.
***************************************************************************/
#ifndef BOARDGUI_H
#define BOARDGUI_H
#include <SDL2/SDL_mixer.h>
#include "Board.h"
#include "GUI.h"
#include "TextureWrapper.h"
class BoardGUI : public GUI {
public:
/***************************************************************************
* All input values returned by this GUI's getInput method
***************************************************************************/
static const int INPUT_MIN_SQUARE = 1; /**< The smallest value of a chess square input, corresponds to square a1. */
static const int INPUT_MAX_SQUARE = 64; /**< The smallest value of a chess square input, corresponds to square h8. */
static const int INPUT_UNDO = -1; /**< User chooses undo */
static const int INPUT_HOME = -2; /**< User chooses to return to the start screen */
static const int INPUT_PROMOTE_QUEEN = -3; /**< User promotes pawn to queen */
static const int INPUT_PROMOTE_ROOK = -4; /**< User promotes pawn to rook */
static const int INPUT_PROMOTE_BISHOP = -5; /**< User promotes pawn to bishop */
static const int INPUT_PROMOTE_KNIGHT = -6; /**< User promotes pawn to knight */
/***************************************************************************
* Public methods
***************************************************************************/
/**
* Load all the images needed for displaying to SDL_Texture
* @param brd: the pointer to the board that this GUI will be drawing.
* @param renderer: an SDL_Renderer
*/
BoardGUI(Board* brd, SDL_Renderer* renderer);
~BoardGUI();
/**
* Draw the chessboard on screen.
* @param renderer: the renderer to draw.
*/
void draw(SDL_Renderer* renderer);
void playMusic();
void stopMusic();
void playMoveSFX();
/**
* Set which player is human
* @param color: the color of human player, according to Board::Colors enum
*/
void setPlayer(int color);
/**
* Called when user make a move
* Update move pointers (arrows pointing to potential moves).
*/
void updateMovePointers();
void destroyMedia();
private:
Board* b; /**< Contains the board's state and logic */
/****************************************************************************
* Images used in drawing
****************************************************************************/
TextureWrapper bgImg, boardImg, piecesSprite;
TextureWrapper undoButton, undoButtonFaded, undoButtonGlow;
TextureWrapper homeButton, homeButtonGlow;
TextureWrapper playerTxt, comTxt, promoteTxt;
TextureWrapper moveArrow;
TextureWrapper colorSymbols[2];
TextureWrapper crosshair;
const Uint8 ALPHA_FADED = 100; /**< The alpha value to draw faded chess pieces */
const Uint8 ALPHA_NORMAL = 255; /**<The alpha value to draw normal chess pieces */
/****************************************************************************
* Coordinates of all images
****************************************************************************/
SDL_Rect pieceClips[Board::NUM_COLORED_TYPES]; /**<Each piece is drawn by clipping a square from the piece sprite */
SDL_Rect boardSquares[Board::NUM_SQUARES]; /** Each SDL_Rect fits a square of the board. */
SDL_Rect undoRect, homeRect, playerTxtRect, colorSymbolRect, promoteTxtRect;
SDL_Rect promotePieceRects[4];
int humanSide; /**< The side that is human player (WHITE, BLACK, or BOTH_COLOR) */
/****************************************************************************
* Move pointer animation
****************************************************************************/
std::vector<int> availableMoves;
const int ARROW_HIGH = 20;
const int ARROW_LOW = 10;
float arrowSpeed = 0.015;
float arrowHeight = ARROW_LOW;
/****************************************************************************
* Audio
****************************************************************************/
Mix_Music* bgm;
Mix_Chunk* moveSFX;
};
#endif // BOARDGUI_H