TheCOSCGameProject  1.0
minigames.h
Go to the documentation of this file.
1 
9 #ifndef MINIGAMES_H
10 #define MINIGAMES_H
11 
12 #include "../lib/toolkit.h"
13 #include "../lib/dependencies.h"
14 #include <vector>
15 #include <string>
16 #include <iostream>
17 #include <random>
18 #include <iomanip>
19 #include <chrono>
20 #include <algorithm>
21 
28 class Game
29 {
30 public:
36  virtual bool start() = 0;
37 
41  virtual ~Game() {}
42 
47  virtual std::string getGameName() = 0;
48 };
49 
55 class TicTacToe : public Game
56 {
57 private:
58  char squares[3][3] = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
59 
60 public:
64  void printBoard();
65 
72  char getSquare(int row, int col) const;
73 
79  void playerMove(int row, int col);
80 
84  void computerTurn();
85 
90  bool checkForWin();
91 
96  bool start() override;
97 
98  bool handlePlayerTurn();
99 
100  bool getPlayerMove(int &row, int &col);
101 
102  bool isValidMove(int row, int col);
103 
104  void makeMove(int row, int col, char symbol);
105 
106  bool isGameOver(int moveCount);
107 
108  bool processComputerTurn();
109 
110  void setBoard(char newBoard[3][3]);
111 
112  void delayTurn();
113 
118  std::string getGameName() override;
119 };
120 
126 class CodeGuesser : public Game
127 {
128 private:
129  std::vector<std::string> words;
130  std::vector<std::string> guesses;
131  int index;
132 
138  static int generateRandomIndex(size_t size);
139 
140 public:
145  CodeGuesser();
146 
151  bool start() override;
152 
157  bool addGuess();
158 
162  void printGuesses();
163 
167  void printWords();
168 
173  int getWordLength() const;
174 
179  int getGuessCount() const;
180 
185  std::string getLastGuess() const;
186 
191  std::string getGameName() override;
192 };
193 
199 class BlackJack : public Game
200 {
201 private:
202  std::vector<int> cards;
203  int dealer[2];
204  std::vector<int> playersCards;
205  int bid;
206 
210  void initDecks();
211 
215  void newGame();
216 
217 public:
222  BlackJack();
223 
229  int evaluate(bool hit);
230 
235  void displayState(bool printAll);
236 
241  const int *getDealer() const;
242 
247  void setDealer(const int newDealer[2]);
248 
253  const std::vector<int> &getPlayerCards() const;
254 
259  void setPlayerCards(const std::vector<int> &newPlayerCards);
260 
265  bool start() override;
266 
271  std::string getGameName() override;
272 
277  int initializeGame();
278 
283  bool handlePlayerTurn();
284 
289  void updateGameState(bool won, int rounds, int totalWins, int maxRounds, bool wasHit);
290 
296  bool endGame(bool won);
297 };
298 
299 #endif // MINIGAMES_H
Implements the BlackJack mini-game.
Definition: minigames.h:199
virtual std::string getGameName()=0
Gets the name of the game.
Implements the CodeGuesser mini-game.
Definition: minigames.h:126
Abstract base class for mini-games.
Definition: minigames.h:28
virtual bool start()=0
Starts the game.
virtual ~Game()
Virtual destructor for proper cleanup of derived classes.
Definition: minigames.h:41
Implements the TicTacToe mini-game.
Definition: minigames.h:55