Onsens  1.0
This is C++ game about bitwise logic.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Game.h
Go to the documentation of this file.
1#pragma once
2
3// Including all necessary libraries
4#include <SFML/Graphics.hpp>
5#include <SFML/System.hpp>
6#include <SFML/Window.hpp>
7#include <SFML/Audio.hpp>
8#include <SFML/Network.hpp>
9#include <iostream>
10#include <random>
11#include <windows.h>
12#include <cstdlib>
13#include <ctime>
14#include <sstream>
15#include <string>
16#include <iomanip>
17
18
19class Game
20{
21
22private:
23 // Set width and height of window
24 const int window_w = 1545;
25 const int window_h = 810;
26 sf::RenderWindow* window; // window object
27 sf::Cursor cursor; // cursor object
28 sf::Image icon; // image for custom icon
29
30
31 sf::Event sfmlEvent;
32
33 // Initial backgrounds sprite and texture
34 sf::Texture backgroundTexture;
35 sf::Sprite backgroundSprite;
36
37 // Initial games clock
38 sf::Clock clock;
39 sf::Time elapsed;
40 sf::Font font;
41 sf::Text timer;
42 int sec;
43 int min;
44 int hour;
45 int timeCount = 1;
46 int intSecondsCounted;
47
48 //Initial buttons for the game menu
49 sf::RectangleShape button1;
50 sf::RectangleShape button2;
51 sf::RectangleShape button3;
52 sf::RectangleShape button4;
53
54
55 void init_window();
56
57
58 // Some more game realeted stuff
59 bool ready = 0;
60 bool gameMode = 0;
61 bool firstGamemode1 = 1;
62 bool firstGamemode2 = 1;
63 bool firstGamemode3 = 1;
64 bool firstGamemode4 = 1;
65 bool rules = 0;
66 bool options = 0;
67 bool pause = 0;
68 bool resume = 0;
69 bool breakResume = 0;
70 bool breakPause = 0;
71 int gamemodeNum = 0;
72 int counter = 0;
73 int tableNum = 0;
74 int specialButtonC = 0;
75 bool pressed = false;
76 bool pressed0 = false;
77 bool pressed1 = false;
78 bool pressed2 = false;
79 bool pressed3 = false;
80 bool pressed4 = false;
81 bool pressed5 = false;
82 bool pressed6 = false;
83 bool pressed7 = false;
84 bool pressed8 = false;
85 bool pressed9 = false;
86 bool pressed10 = false;
87 bool pressed11 = false;
88 bool pressed12 = false;
89 bool pressed20 = false;
90 bool pressed21 = false;
91 bool pressed22 = false;
92 bool pressed23 = false;
93 bool pressed24 = false;
94 bool pressed25 = false;
95 std::stringstream ss;
96
97 // in-game images
98 sf::Texture player1TextTexture;
99 sf::Sprite player1Text;
100 sf::Texture player2TextTexture;
101 sf::Sprite player2Text;
102 sf::RectangleShape buttonTable;
103 sf::Texture truthTableTexture;
104 sf::Sprite truthTable;
105 sf::Texture tableHeaderTexture;
106 sf::Sprite tableHeader;
107 sf::Texture tableHoverTexture;
108 sf::Sprite tableHover;
109 sf::Texture transitionTexture;
110 sf::Sprite transitionImg;
111 sf::Texture pyramid1Texture;
112 sf::Sprite pyramid1Img;
113 sf::Texture pyramid2Texture;
114 sf::Sprite pyramid2Img;
115 sf::Texture resumeTexture;
116 sf::Sprite resumeImg;
117 sf::Texture pauseTexture;
118 sf::Sprite pauseImg;
119 sf::Texture specialButtonTexture;
120 sf::Sprite specialButtonImg;
121 sf::Texture changeTexture;
122 sf::Texture notCardPopTexture;
123 sf::Sprite notCardPop;
124
125 // Base Cards
126 struct baseCard
127 {
128 bool value = 0;
129
130 // image of the base card
131 sf::Texture BaseCardImgTexture;
132 sf::Sprite BaseCardImg;
133 };
134
135 baseCard baseCards[6]; // Base cards for player 1
136 baseCard baseCards2[6]; // Base cards for player 2
137
138 // Cards struct
139 struct card
140 {
141 int num = 0; // Pos
142 int value = 0; // 0 or 1
143 char type = 0; // and / or / xor
144
145 // some properties
146 bool display1 = 0;
147 bool display2 = 0;
148 int player = 0; // 1 or 2
149 int secondNum = 0;
150 bool player1pos = 0;
151 bool player2pos = 0;
152 bool x = 0;
153 bool y = 0;
154 bool drag = 0;
155 bool placed = 0;
156
157 // image of the card
158 sf::Texture imgTexture;
159 sf::Sprite img;
160 };
161
162 // Field Positions struct
163 struct fieldPos
164 {
165 int cardNum = 0; // The number of the card that's on this pos
166 int cardValue = 0; // The value of the card that's on this pos
167
168
169 // some properties
170 bool showPos = 0;
171 bool cardOnIt = 0;
172 int pos = 0; // 1 to 15
173 int x = 0;
174 int y = 0;
175
176
177 // image
178 sf::Texture imgTexture;
179 sf::Sprite img;
180 };
181
182
183 fieldPos fPositions[40]; // Positions for Player 1
184 fieldPos fPositions2[40]; // Positions for Player 2
185 fieldPos notCardPos[6]; // Positions for the not-card
186 card startDeck[100]; // The starting deck
187 card deck[150]; // The ready deck
188 int temp;
189 int randNum;
190 int deckI = 1;
191 int nextPage = -1;
192 int cardGet = 1;
193 int counterCards = 1;
194 int counterCards2 = 49;
195 int counterCards3 = 48;
196 int counterNotCards3 = 56;
197 int player1Cards = 0;
198 int player2Cards = 0;
199 int win = 0;
200 bool showA = 0;
201 bool showA2 = 0;
202 bool showNotA = 0;
203 bool otherNot = 0;
204 bool roundPlayed = 0;
205 bool card1Dragging = 0;
206 bool card2Dragging = 0;
207 bool card3Dragging = 0;
208 bool card4Dragging = 0;
209 bool card5Dragging = 0;
210 bool card1Dragging2 = 0;
211 bool card2Dragging2 = 0;
212 bool card3Dragging2 = 0;
213 bool card4Dragging2 = 0;
214 bool card5Dragging2 = 0;
215
216 // Cards in hand pos
217 int player1Pos1 = 0;
218 int player1Pos2 = 0;
219 int player1Pos3 = 0;
220 int player1Pos4 = 0;
221 int player1Pos5 = 0;
222 int player2Pos1 = 0;
223 int player2Pos2 = 0;
224 int player2Pos3 = 0;
225 int player2Pos4 = 0;
226 int player2Pos5 = 0;
227
228
229public:
230
231 Game(); // Constructor for initializing different values
232 ~Game(); // Deconstructor for deleting values
233
234 void pollEvents(); // Function for getting events
235 bool running(); // Function to check whether game is running
236 void start(); // Function to start game
237 void menu(sf::Window& newWindow); // Setting the game menu
238 void modes(sf::Window& newWindow); // Modes menu function
239 void rulestab(sf::Window& newWindow); // Rules
240 void optionsMenu(sf::Window& newWindow); // Options
241 void firstGamemode(sf::Window& newWindow); // Contains the first mode
242 void secondGamemode(sf::Window& newWindow); // Contains the second mode
243 void thirdGamemode(sf::Window& newWindow); // Contains the third mode
244 void fourthGamemode(sf::Window& newWindow); // Contains the fourth mode
245 void menuButtons(); // Setting the buttons
246 void modesButtons(); // Setting the buttons
247 void winScreen(sf::Window& newWindow); // Displays the victory window
248 void customCursor(); // Setting the custom cursor
249 void setTheIcon(); // Icon for the window
250 void setReady(); // Config everything before the start of the game
251 void setPlay(); // Config the game before playing
252 void setTimer(); // Setting a timer in game
253 void setBaseCards(); // Setting the positions and the type of the base cards
254 void setDeck(); // Setting a deck and cards
255 void sortDeck(); // Radomising the Deck cards
256 void setNotDeck(); // Setting a deck and cards for not-gamemode
257 void sortNotDeck(); // Radomising the Deck cards for not-gamemode
258 void cardsInHand(); // Sets the cards that the player has
259 void tableOfTruth(); // Helps table display
260 void setPlacingCards(); // Sets the default positions of the cards
261 void placingCardsPos(); // Sets the possible positions
262 void placingNotCardsPos(); // Sets the possible positions for the not-card
263 void notCardLogic(int j); // Checks if not-cards were placed and can handle them
264 void setCardImages(sf::Vector2i cursorpos); // Loads cards images
265 void setCardImages2(sf::Vector2i cursorpos); // The same function but modified for the second gamemode
266 void setNotCardImages(sf::Vector2i cursorpos); // Loads cards images for the not gamemode
267 void setNotCardImages2(sf::Vector2i cursorpos); // The same function but modified for the fourth gamemode
268 bool checkPlacedCards(int jj); // Checks if the operation is possible
269 bool getMousePos(float x, float y, int a, sf::Window& newWindow); // Getting the mouse position
270 void update(sf::Window& newWindow); // Main function to change values every iteration
271 void render(); // Main function to render objects every iteration
272 void setBackground(); // Function to display background
273};
Definition: Game.h:20
void optionsMenu(sf::Window &newWindow)
Definition: Game.cpp:778
void setBackground()
Definition: Game.cpp:434
void fourthGamemode(sf::Window &newWindow)
Definition: Game.cpp:18724
void render()
Definition: Game.cpp:442
void menuButtons()
Definition: Game.cpp:585
void menu(sf::Window &newWindow)
Definition: Game.cpp:601
void modesButtons()
Definition: Game.cpp:673
void setCardImages2(sf::Vector2i cursorpos)
Definition: Game.cpp:3874
void start()
Definition: Game.cpp:21942
bool checkPlacedCards(int jj)
Definition: Game.cpp:15688
void setTheIcon()
Definition: Game.cpp:16505
void modes(sf::Window &newWindow)
Definition: Game.cpp:689
void sortDeck()
Definition: Game.cpp:1219
void setReady()
Definition: Game.cpp:21916
void notCardLogic(int j)
Definition: Game.cpp:4430
void setDeck()
Definition: Game.cpp:1166
void cardsInHand()
Definition: Game.cpp:16562
void sortNotDeck()
Definition: Game.cpp:1296
bool getMousePos(float x, float y, int a, sf::Window &newWindow)
Definition: Game.cpp:474
void placingNotCardsPos()
Definition: Game.cpp:16941
void setBaseCards()
Definition: Game.cpp:16519
void update(sf::Window &newWindow)
Definition: Game.cpp:449
void tableOfTruth()
Definition: Game.cpp:16954
void thirdGamemode(sf::Window &newWindow)
Definition: Game.cpp:18181
void setNotCardImages(sf::Vector2i cursorpos)
Definition: Game.cpp:7227
void pollEvents()
Definition: Game.cpp:15
void winScreen(sf::Window &newWindow)
Definition: Game.cpp:1123
void secondGamemode(sf::Window &newWindow)
Definition: Game.cpp:17445
void setPlay()
Definition: Game.cpp:20680
void setCardImages(sf::Vector2i cursorpos)
Definition: Game.cpp:1314
void setPlacingCards()
Definition: Game.cpp:15529
void firstGamemode(sf::Window &newWindow)
Definition: Game.cpp:17013
void setTimer()
Definition: Game.cpp:20652
Game()
Definition: Game.cpp:21928
void setNotCardImages2(sf::Vector2i cursorpos)
Definition: Game.cpp:12473
void rulestab(sf::Window &newWindow)
Definition: Game.cpp:867
~Game()
Definition: Game.cpp:21937
void placingCardsPos()
Definition: Game.cpp:16671
void setNotDeck()
Definition: Game.cpp:1237
void customCursor()
Definition: Game.cpp:16511
bool running()
Definition: Game.cpp:10
Utility class that measures the elapsed time.
Definition: Clock.hpp:42
Cursor defines the appearance of a system cursor.
Definition: Cursor.hpp:47
Defines a system event and its parameters.
Definition: Event.hpp:45
Class for loading and manipulating character fonts.
Definition: Font.hpp:51
Class for loading, manipulating and saving images.
Definition: Image.hpp:47
Specialized shape representing a rectangle.
Window that can serve as a target for 2D drawing.
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
Graphical text that can be drawn to a render target.
Definition: Text.hpp:49
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
Represents a time value.
Definition: Time.hpp:41
Utility template class for manipulating 2-dimensional vectors.
Definition: Vector2.hpp:38
Window that serves as a target for OpenGL rendering.