-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.h
More file actions
142 lines (119 loc) · 3.49 KB
/
Game.h
File metadata and controls
142 lines (119 loc) · 3.49 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
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
/*
Game.h
Author: [Your Name]
Roll Number: [Your Roll Number]
Project Title: Xonix Game - DSA Project
Description:
This file contains the Game class which encapsulates the core game logic.
*/
#ifndef GAME_H
#define GAME_H
#include <SFML/Graphics.hpp>
#include <string>
#include "Player.h"
#include "Enemy.h"
#include "GameSave.h"
using namespace sf;
// Game states
enum class GameState {
PLAYING,
GAME_OVER,
WIN,
PAUSED
};
class Game {
private:
// Game dimensions
static const int M = 25;
static const int N = 40;
static const int ts = 18; // tile size
// Game grid
int grid[M][N];
// Game state
bool isRunning;
int score;
int highScore;
bool isMultiplayer;
bool returnToMenu;
GameState gameState;
std::string winReason; // Store the reason for winning
std::string currentUsername; // Current player's username
// SFML objects
RenderWindow* window;
Texture tileTexture;
Texture gameoverTexture;
Texture enemyTexture;
Sprite tileSprite;
Sprite gameoverSprite;
Sprite enemySprite;
Font font;
// Game entities
static const int maxEnemies = 10;
int enemyCount;
Enemy enemies[maxEnemies];
Player player;
Player player2; // Second player for multiplayer
// Game clock
Clock gameClock;
float timer;
float delay;
int bonusCounter; // Tracks how many times bonus points were earned
int bonusThreshold; // Current threshold for bonus points (starts at 10)
int bonusMultiplier; // Current multiplier for bonus points (starts at 2)
// Save game functionality
GameSave* gameSave;
bool showSaveMenu;
bool showLoadMenu;
LinkedList<std::string> savesList;
int selectedSaveIndex;
// Notification message
std::string notificationMessage;
float notificationTimer;
// Helper functions
void initializeGrid();
void resetGame();
void processInput();
void update(float deltaTime);
void draw();
void fillArea(int y, int x, int tempGrid[][N], bool& containsEnemy);
void drop(int y, int x);
void updateScore(int points);
void checkCollisions();
void updatePlayer1();
void updatePlayer2();
void updateEnemy(Enemy& enemy);
bool isTrailConnectedToBorder();
void activatePowerup();
// Save/Load menu functions
void drawSaveMenu();
void drawLoadMenu();
void processMenuInput(Event& event);
void processPauseMenuInput(Event& event);
public:
// Constructor
Game();
// Destructor
~Game();
// Main game functions
void initialize();
void initializeMultiplayer(const std::string& player1Name, const std::string& player2Name);
void run();
void pause();
void resume();
void end();
int getFinalScore() const; // Add this method
// Save/Load methods
bool saveGame(const std::string& username);
bool loadGame(const std::string& saveID, const std::string& username);
LinkedList<std::string> getSaves(const std::string& username);
void setCurrentUsername(const std::string& username);
// Getters
int getScore() const;
int getHighScore() const;
bool getIsRunning() const;
RenderWindow* getWindow();
bool shouldReturnToMenu() const;
// Add a new getter for gameSave
GameSave* getGameSave() const { return gameSave; }
};
#endif // GAME_H