Package Game
Class DomineeringGame
- java.lang.Object
-
- Game.DomineeringGame
-
public class DomineeringGame extends java.lang.Object
The DomineeringGame class represents the main game controller for the Domineering game. It handles the main game window, settings, saved games, and the game logic. This class uses the Singleton design pattern to ensure only one instance of the game is created.- Since:
- 2023-12-01
- Version:
- 1.0
- Author:
- Laamiri Ouail & Hajar Sadik
-
-
Field Summary
Fields Modifier and Type Field Description private Button
btnGameWithAgent
Button for starting a game with an agent.private Button
btnGameWithPerson
Button for starting a game with another person.private Button
btnMainExit
Button for exiting the main menu.private Button
btnsauvgardedGamebtn
Button for loading a saved game.private Button
btnSetting
Button for accessing game settings.private Frame
domineeringFrame
Frame for the domineering game mode.private static DomineeringGame
domineeringGameInstance
Instance of the domineering game.private Event
event
Event associated with the game (e.g., a button click).private Button
goToMainFrameButton
Button for returning to the main menu.private TextField
inputAppBackgroundColor
Text field for inputting the background color of the application.private TextField
inputBoardColor
Text field for inputting the color of the game board.private TextField
inputColumn
Text field for inputting the number of columns in the game board.private TextField
inputIntermediateColor
Text field for inputting the intermediate color.private TextField
inputPlayer1Color
Text field for inputting the color of Player 1.private TextField
inputPlayer2Color
Text field for inputting the color of Player 2.private TextField
inputRow
Text field for inputting the number of rows in the game board.private TextField
inputTitle
Text field for user input (e.g., entering a game title).private Label
labelAppBackgroundColor
Label for input related to the background color of the application.private Label
labelBoardColor
Label for input related to the color of the game board.private Label
labelColumn
Label for input related to the number of columns in the game board.private Label
labelInputSauvgarde
Label for input related to saved games.private Label
labelIntermediateColor
Label for input related to the intermediate color.private Label
labelPlayer1Color
Label for input related to the color of Player 1.private Label
labelPlayer2Color
Label for input related to the color of Player 2.private Label
labelRow
Label for input related to the number of rows in the game board.private Frame
mainFrame
Main frame of the game.private Frame
oneToOneGameFrame
Frame for one-to-one game mode.private Button
refuseSauvgarde
Button for refusing a saved game.private Button
restartGameButton
Button for restarting the game.private Button
sauvgardebtn
Button for saving the current game state.private Frame
SauvgardedFrame
Frame for displaying a saved game.private Frame
SauvgardedTableFrame
Frame for displaying a saved game table.private Frame
sauvgardeFrame
Frame for displaying saved games.private Button
saveSetting
Button for saving the updated game settings.private Frame
settingFrame
Frame for game settings.private Button
submitSauvgarde
Button for submitting a saved game.private Window
window
Represents the main window of the game.private int
windowHeight
Height of the game window.private int
windowWidth
Width of the game window.
-
Constructor Summary
Constructors Modifier Constructor Description private
DomineeringGame()
Constructs a new instance of the DomineeringGame class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
finalizeMainFrame()
Finalizes the main frame by nullifying its components.private void
finalizeOneToOneFrame()
Finalizes the one-to-one game frame by nullifying its components.private void
finalizeSauvgardedFrame()
Finalizes the frame for viewing saved games by setting all relevant components to null, clearing references, and preparing for the next frame or action.private void
finalizeSettingFrame()
Finalizes the setting frame by nullifying its components.static DomineeringGame
getInstance()
Gets the singleton instance of the DomineeringGame class.private void
loadConfigurations()
Loads configuration settings from a file and updates the Configuration class accordingly.private void
makeGameFrame()
Creates and initializes the game frame with buttons and UI elements.private void
makeMainFrame()
Creates and initializes the main frame with buttons for different game options.private void
makeSauvgardedFrame()
Creates and initializes the frame for viewing saved games.private void
makeSauvgardedTable()
Creates and initializes a table within the SauvgardedFrame to display saved game information.private void
makeSauvgardeOneGameFrame()
Creates and initializes a frame for saving a one-to-one game.private void
makeSettingFrame()
Creates and initializes a settings frame for configuring game parameters.private void
restart()
Restarts the Domineering game by resetting the game board, move counters, and message label.private void
saveSettings()
Saves the updated game settings entered by the user.private void
setAttribute()
Sets up the initial configurations for the game, including the game window, buttons, and other components.
-
-
-
Field Detail
-
window
private Window window
Represents the main window of the game.
-
mainFrame
private Frame mainFrame
Main frame of the game.
-
btnGameWithPerson
private Button btnGameWithPerson
Button for starting a game with another person.
-
btnGameWithAgent
private Button btnGameWithAgent
Button for starting a game with an agent.
-
btnMainExit
private Button btnMainExit
Button for exiting the main menu.
-
btnsauvgardedGamebtn
private Button btnsauvgardedGamebtn
Button for loading a saved game.
-
btnSetting
private Button btnSetting
Button for accessing game settings.
-
settingFrame
private Frame settingFrame
Frame for game settings.
-
oneToOneGameFrame
private Frame oneToOneGameFrame
Frame for one-to-one game mode.
-
domineeringFrame
private Frame domineeringFrame
Frame for the domineering game mode.
-
goToMainFrameButton
private Button goToMainFrameButton
Button for returning to the main menu.
-
restartGameButton
private Button restartGameButton
Button for restarting the game.
-
sauvgardebtn
private Button sauvgardebtn
Button for saving the current game state.
-
sauvgardeFrame
private Frame sauvgardeFrame
Frame for displaying saved games.
-
inputTitle
private TextField inputTitle
Text field for user input (e.g., entering a game title).
-
submitSauvgarde
private Button submitSauvgarde
Button for submitting a saved game.
-
refuseSauvgarde
private Button refuseSauvgarde
Button for refusing a saved game.
-
labelInputSauvgarde
private Label labelInputSauvgarde
Label for input related to saved games.
-
SauvgardedFrame
private Frame SauvgardedFrame
Frame for displaying a saved game.
-
SauvgardedTableFrame
private Frame SauvgardedTableFrame
Frame for displaying a saved game table.
-
labelRow
private Label labelRow
Label for input related to the number of rows in the game board.
-
inputRow
private TextField inputRow
Text field for inputting the number of rows in the game board.
-
labelColumn
private Label labelColumn
Label for input related to the number of columns in the game board.
-
inputColumn
private TextField inputColumn
Text field for inputting the number of columns in the game board.
-
labelBoardColor
private Label labelBoardColor
Label for input related to the color of the game board.
-
inputBoardColor
private TextField inputBoardColor
Text field for inputting the color of the game board.
-
labelPlayer1Color
private Label labelPlayer1Color
Label for input related to the color of Player 1.
-
inputPlayer1Color
private TextField inputPlayer1Color
Text field for inputting the color of Player 1.
-
labelPlayer2Color
private Label labelPlayer2Color
Label for input related to the color of Player 2.
-
inputPlayer2Color
private TextField inputPlayer2Color
Text field for inputting the color of Player 2.
-
labelIntermediateColor
private Label labelIntermediateColor
Label for input related to the intermediate color.
-
inputIntermediateColor
private TextField inputIntermediateColor
Text field for inputting the intermediate color.
-
labelAppBackgroundColor
private Label labelAppBackgroundColor
Label for input related to the background color of the application.
-
inputAppBackgroundColor
private TextField inputAppBackgroundColor
Text field for inputting the background color of the application.
-
saveSetting
private Button saveSetting
Button for saving the updated game settings.
-
windowHeight
private int windowHeight
Height of the game window.
-
windowWidth
private int windowWidth
Width of the game window.
-
event
private Event event
Event associated with the game (e.g., a button click).
-
domineeringGameInstance
private static DomineeringGame domineeringGameInstance
Instance of the domineering game.
-
-
Method Detail
-
setAttribute
private void setAttribute()
Sets up the initial configurations for the game, including the game window, buttons, and other components.
-
getInstance
public static DomineeringGame getInstance()
Gets the singleton instance of the DomineeringGame class.- Returns:
- The singleton instance of the DomineeringGame class.
-
loadConfigurations
private void loadConfigurations()
Loads configuration settings from a file and updates the Configuration class accordingly. This method uses the StringTableFile singleton instance to load configuration settings from a file. It retrieves an array of configurations, including row and column size, default colors for players and board, and the background color of the application. If the loaded configurations are valid (contain 7 elements), it updates the Configuration class with the new values. Note: This method is responsible for initializing the Configuration class with settings loaded from a file.
-
makeMainFrame
private void makeMainFrame()
Creates and initializes the main frame with buttons for different game options. This method sets up the main frame, including buttons for playing with a friend, playing against the laptop, accessing saved games, going to settings, and exiting the application. It associates action listeners for each button to handle the corresponding functionalities. Note: This method is responsible for creating the initial main frame layout and setting up button functionalities for various game options.
-
makeGameFrame
private void makeGameFrame()
Creates and initializes the game frame with buttons and UI elements. This method sets up the game frame, including buttons for gameplay, restart, and saving. It also associates action listeners for various buttons, such as returning to the main frame, saving the game, restarting the game, and accessing the help feature. Note: This method is responsible for creating the initial game frame layout and setting up button functionalities.
-
finalizeMainFrame
private void finalizeMainFrame()
Finalizes the main frame by nullifying its components. This method sets all components of the main frame to null, including buttons and other UI elements. It is typically called when transitioning away from the main frame to ensure that resources are released and references are cleared. Note: This method is part of the cleanup process after the main frame is no longer needed.
-
finalizeOneToOneFrame
private void finalizeOneToOneFrame()
Finalizes the one-to-one game frame by nullifying its components. This method sets all components of the one-to-one game frame to null, including buttons, labels, and other UI elements. It is typically called when transitioning away from the one-to-one game frame to ensure that resources are released and references are cleared. Note: This method is part of the cleanup process after the one-to-one game frame is no longer needed.
-
finalizeSauvgardedFrame
private void finalizeSauvgardedFrame()
Finalizes the frame for viewing saved games by setting all relevant components to null, clearing references, and preparing for the next frame or action. This method sets the `SauvgardedTableFrame`, `SauvgardedFrame`, and `goToMainFrameButton` to null, effectively releasing memory and resources associated with these components. It is typically called when transitioning to another frame or completing the interaction with the saved games frame.
-
restart
private void restart()
Restarts the Domineering game by resetting the game board, move counters, and message label. This method iterates through each button in the game board and sets its background color to the default color. Additionally, it enables all buttons and resets the move counter to zero. It hides and clears the message label. Finally, it saves the void colors configuration to the file for future reference. This method is typically called when restarting the game after completion or when needed.
-
makeSauvgardedFrame
private void makeSauvgardedFrame()
Creates and initializes the frame for viewing saved games. This method sets up the SauvgardedFrame by adding components such as buttons and tables. It creates a "Return" button to go back to the main frame and invokes the makeSauvgardedTable method to display a table of saved games. The frame is typically used to navigate and interact with saved game data. Note: The method associates an ActionListener with the "Return" button to handle the action of going back to the main frame.- See Also:
makeSauvgardedTable()
-
makeSauvgardedTable
private void makeSauvgardedTable()
Creates and initializes a table within the SauvgardedFrame to display saved game information. This method reads saved game data from a file, populates a table with columns "ID," "Description," and "Date," and associates a custom TableCellRenderer to set font size for better visibility. It also adds a ListSelectionListener to the table for handling row selection events, enabling the user to load a selected saved game. Note: The method dynamically adjusts the table's size based on the number of saved games and their information.- See Also:
makeSauvgardedFrame()
-
makeSauvgardeOneGameFrame
private void makeSauvgardeOneGameFrame()
Creates and initializes a frame for saving a one-to-one game. This method checks the existence of the one-to-one game frame and the absence of the sauvgarde frame. If conditions are met, it closes the one-to-one game frame, sets up the sauvgarde frame with input fields for a description and buttons for submitting or refusing the sauvgarde. It also handles the actions of the submit and refuse buttons, allowing the user to save or cancel the sauvgarde process. Note: The sauvgarde frame is designed to capture additional information such as a description before saving.- See Also:
makeGameFrame()
-
makeSettingFrame
private void makeSettingFrame()
Creates and initializes a settings frame for configuring game parameters. This method sets up a frame with input fields for configuring various game settings, such as the number of rows and columns, board and player colors, and background colors. It also includes buttons for returning to the main frame, submitting changes, and associated action listeners to handle these interactions. The entered settings are saved upon submission. Note: The method utilizes the window dimensions and current configuration settings to adjust the layout dynamically based on the number of columns.- See Also:
saveSettings()
,finalizeSettingFrame()
,makeMainFrame()
-
saveSettings
private void saveSettings()
Saves the updated game settings entered by the user. This method retrieves values from input fields representing various game settings, validates them, and updates the Configuration class with the new values. The settings include the number of rows and columns, board and player colors, and background colors. After updating the configurations, the method saves them to a configuration file. If any input value is not in the correct format or range, an error message is displayed. Note: The method performs input validation and updates the Configuration class accordingly.- See Also:
Configuration
-
finalizeSettingFrame
private void finalizeSettingFrame()
Finalizes the setting frame by nullifying its components. This method sets all components of the setting frame to null, including buttons, labels, and input fields. It is typically called when transitioning away from the setting frame to ensure that resources are released and references are cleared. Note: This method is part of the cleanup process after the setting frame is no longer needed.
-
-