My Project
UML Lab
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Game Class Reference

Represents the main game logic and interaction. More...

#include <gameloop.h>

Public Member Functions

 Game (sf::RenderWindow &window, Player &humanPlayer, Player &computerPlayer)
 Constructs a Game object.
 
void run ()
 Runs the main game loop.
 

Private Attributes

Board board
 Instance of the Board class, representing the game board.
 
PlayerhumanPlayer
 Reference to the Player object representing the human player.
 
PlayercomputerPlayer
 Reference to the Player object representing the computer player.
 
sf::RenderWindow & window
 Reference to the SFML RenderWindow for displaying the game.
 

Detailed Description

Represents the main game logic and interaction.

This class manages the core gameplay loop, including drawing the board, handling input, and facilitating turns between the human and computer players. It holds references to the game window, the board, and the player objects.

Constructor & Destructor Documentation

◆ Game()

Game::Game ( sf::RenderWindow & window,
Player & humanPlayer,
Player & computerPlayer )

Constructs a Game object.

Initializes a Game instance with references to the necessary components: the game window, human player, computer player, and the board (which is created internally).

Parameters
windowReference to the SFML RenderWindow used for rendering.
humanPlayerReference to the Player object representing the human player.
computerPlayerReference to the Player object representing the computer player.

Initializes a Game instance, associating it with a RenderWindow, two Player objects (human and computer), and a Board to manage the game state.

Parameters
windowThe SFML RenderWindow used for rendering the game.
humanPlayerThe Player object representing the human player.
computerPlayerThe Player object representing the computer player.

Member Function Documentation

◆ run()

void Game::run ( )

Runs the main game loop.

This function initiates the core game loop. It continuously:

  1. Clears the window.
  2. Draws the current state of the board.
  3. Handles player input (from both human and computer players).
  4. Updates the game state accordingly.
  5. Displays the updated game state on the screen.

The loop continues until the game window is closed.

This function handles the continuous cycle of the game:

  1. Clears the window to prepare for rendering.
  2. Draws the current state of the board onto the window.
  3. Collects input from the player through the window.
  4. Displays the updated window contents on the screen.

The loop continues until the window is closed.

Member Data Documentation

◆ board

Board Game::board
private

Instance of the Board class, representing the game board.

◆ computerPlayer

Player& Game::computerPlayer
private

Reference to the Player object representing the computer player.

◆ humanPlayer

Player& Game::humanPlayer
private

Reference to the Player object representing the human player.

◆ window

sf::RenderWindow& Game::window
private

Reference to the SFML RenderWindow for displaying the game.


The documentation for this class was generated from the following files: