-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uno.cpp
178 lines (127 loc) · 3.67 KB
/
Uno.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "Uno.h"
Uno::Uno()
{
Display::init();
display = new Display(1200, 700, "SDL Uno");
return;
}
Uno::~Uno()
{
delete display;
}
void Uno::RunProgram()
{
//RunMenu();
RunGame();
//RunWinScreen(0);
}
void Uno::RunGame()
{
display->ClearRenderables();
BaseEventHandler handler;
FPSCounter fpsCounter(display->renderer, 2);
Deck drawDeck({0, 0, 100, 150});
drawDeck.CenterTexture({ 0, 0, display->w(), display->h() });
Deck playDeck({ 0, 0, 100, 150 });
playDeck.CenterTexture({0, 0, display->w(), display->h()});
drawDeck.ShiftLocation({-52 });
playDeck.ShiftLocation({ 52 });
display->AddRenderable(&drawDeck);
display->AddRenderable(&playDeck);
GameMaster gameMaster(display, &handler, &playDeck, &drawDeck, 4);
gameMaster.SetWinFunc([this](int winner) {this->RunWinScreen(winner); });
CharIndicatorContainer enemies(&gameMaster, display->renderer, { 0, 0, display->w(), display->h()/3});
display->AddRenderable(&enemies);
gameMaster.SetNewTurnFunc([&enemies](int character, int prevCharacter) {enemies.UpdateCharIndicators(character, prevCharacter);});
Button drawButton({ 20, 300, 150, 150 }, [&gameMaster]() {gameMaster.GivePlayerCard();});
drawButton.AddTexture(display->renderer, "textures/drawButton.png");
display->AddRenderable(&drawButton);
handler.AddInteractable(&drawButton);
while (true)
{
display->PrepareRender();
gameMaster.TakeTurn();
gameMaster.IncreaseTurn();
handler.Handle();
display->RenderAll();
fpsCounter.IncreaseFrameCount();
fpsCounter.DrawSelf(display->renderer);
display->ProcessRender();
SDL_Delay(10);
}
return;
}
void Uno::RunMenu()
{
display->ClearRenderables();
BaseEventHandler handler;
Text menuText(display->renderer, "SDL Uno!", 80, {0, 0, 0, 0}, {255, 255, 255, 255});
menuText.CenterTexture({ 0, 0, display->w(), display->h()/2 });
display->AddRenderable(&menuText);
Button startButton({200, 200, 200, 140}, [this](){RunGame();});
startButton.AddTexture(display->renderer, "textures/UnoPlay.png");
startButton.CenterTexture({ 0, 0, display->w(), display->h() });
handler.AddInteractable(&startButton);
display->AddRenderable(&startButton);
while (true)
{
display->PrepareRender();
handler.Handle();
display->RenderAll();
display->ProcessRender();
SDL_Delay(10);
}
return;
}
void Uno::RunWinScreen(int winner)
{
display->ClearRenderables();
BaseEventHandler handler;
std::string winTextContent = winner == 0 ? "You Win!" : "You Lost!";
Text winText(display->renderer, winTextContent.c_str(), 80, {0, 0, 0, 0}, {255, 255, 255, 255});
winText.CenterTexture({ 0, 0, display->w(), display->h() });
display->AddRenderable(&winText);
while (true)
{
display->PrepareRender();
handler.Handle();
display->RenderAll();
display->ProcessRender();
SDL_Delay(10);
}
return;
}
// a test function that draws out all cards
void Uno::CardTest(Display* display, int gap, int row)
{
if (row > 4)
row = 4;
SDL_Color colors[4] = {Red, Green, Blue, Yellow};
for (int j = 0; j < row; j++)
{
for (int i = 0; i <= 10; i++)
{
display->AddRenderable(new Card(
display->renderer,
{ 5+(i*(100 + gap)), 5+(j * (150 + gap)), 0, 0},
colors[j],
i,
true,
true
));
}
}
}
// holy shit your code is awful, decks sizes are hardcoded rn
// fix that
// 100, 150
// you can click through a button to click the thing beneath it, add z-priotity on clicking
// I feel like this code needs cleaning up, once gamemaster is
// working, do that
/*
// get gamemaster working, skip ai for now, just get it
// taking a players turn, waiting a bit on ai and repeating
*/
/*
I've realised Im misusing inheritance completely but fuck you future me, look back on this and cringe
*/