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
|
#pragma once
//#define SHOW_DEBUG_HELPERS
#include "SDL2/SDL_events.h"
#ifdef SHOW_DEBUG_HELPERS
#include <iostream>
#endif
#include <SDL2/SDL.h>
#include <string>
#include <vector>
namespace Config {
inline const std::string GAME_NAME{"Minesweeper"};
inline constexpr int BOMB_COUNT{18};
inline constexpr int GRID_COLUMNS{24};
inline constexpr int GRID_ROWS{12};
inline constexpr int PADDING{5};
inline constexpr int CELL_SIZE{50};
inline constexpr int FOOTER_HEIGHT{60};
inline constexpr int GRID_HEIGHT{
CELL_SIZE * GRID_ROWS + PADDING * (GRID_ROWS - 1)
};
inline constexpr int GRID_WIDTH{
CELL_SIZE * GRID_COLUMNS + PADDING * (GRID_COLUMNS - 1)
};
inline constexpr int WINDOW_HEIGHT{
GRID_HEIGHT + FOOTER_HEIGHT + PADDING * 2
};
inline constexpr int WINDOW_WIDTH{
GRID_WIDTH + PADDING * 2
};
inline constexpr SDL_Color BACKGROUND_COLOR{ 170, 170 , 170, 255 };
inline constexpr SDL_Color BUTTON_COLOR{ 200, 200, 200, 255 };
inline constexpr SDL_Color BUTTON_HOVER_COLOR{ 220, 220, 220, 255 };
inline constexpr SDL_Color BUTTON_CLEARED_COLOR{ 240, 240, 240, 255 };
inline constexpr SDL_Color BUTTON_SUCCESS_COLOR{ 210, 235, 210, 255 };
inline constexpr SDL_Color BUTTON_FAILURE_COLOR{ 235, 210, 210, 255 };
inline const std::vector<SDL_Color> TEXT_COLORS{
{ 0, 0, 0, 255}, /* 0, unused */
{ 0, 1, 249, 255}, /* 1 */
{ 1, 126, 1, 255}, /* 2 */
{250, 1, 2, 255}, /* 3 */
{ 1, 0, 128, 255}, /* 4 */
{129, 1, 0, 255}, /* 5 */
{ 0, 128, 128, 255}, /* 6 */
{ 0, 0, 0, 255}, /* 7 */
{128, 128, 128, 255}, /* 8 */
};
inline const std::string FONT{"Roboto-Medium.ttf"};
inline const std::string BOMB_IMAGE{"bomb.png"};
inline const std::string FLAG_IMAGE{"flag.png"};
static_assert(BOMB_COUNT < GRID_COLUMNS * GRID_ROWS,
"Cannot have more bombs than cells");
}
namespace UserEvents {
inline Uint32 NEW_GAME = SDL_RegisterEvents(1);
inline Uint32 GAME_WON = SDL_RegisterEvents(1);
inline Uint32 GAME_LOST = SDL_RegisterEvents(1);
inline Uint32 CELL_CLEARED = SDL_RegisterEvents(1);
inline Uint32 BOMB_PLACED = SDL_RegisterEvents(1);
inline Uint32 FLAG_PLACED = SDL_RegisterEvents(1);
inline Uint32 FLAG_CLEARED = SDL_RegisterEvents(1);
}
namespace Utils {
#ifdef SHOW_DEBUG_HELPERS
inline void CheckSDLError(
const std::string& Msg) {
const char* error = SDL_GetError();
if (*error != '\0') {
std::cerr << Msg << " Error: " << error << '\n';
SDL_ClearError();
}
}
#endif
}
|