Package com.mygdx.game.Logic
Class GameInstance
java.lang.Object
com.mygdx.game.Logic.GameInstance
- All Implemented Interfaces:
java.io.Serializable
public class GameInstance
extends java.lang.Object
implements java.io.Serializable
The "main" class of the Game. Contains the rules and connects the Logic segment of the project together.
This is the class that gets serialized when saving the game.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GameInstance.GameInstanceListener
This interface is to be implemented by the UI in order to be notified about events that happen by the game logic -
Constructor Summary
Constructors Constructor Description GameInstance(int numberOfPlayers)
-
Method Summary
Modifier and Type Method Description void
drawCard(Card card)
Called byCardSquare
to notify the UI so that it can display a message to the userMoveCard
andJailCard
.
Objects also need to set their resulting square to the current board.void
endTurn()
To be called by the UI when the player finished his turn
Checks if the player lost or won and proceeds to the next playervoid
gameLoop(int dice)
To be called by the UI at the start of the turn.Board
getBoard()
Player
getCurrentPlayer()
GameInstance.GameInstanceListener
getListener()
int
getNumberOfPlayers()
java.util.ArrayList<Player>
getPlayers()
void
initialize()
void
setCurrentPlayer(int i)
void
setListener(GameInstance.GameInstanceListener listener)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
GameInstance
public GameInstance(int numberOfPlayers)- Parameters:
numberOfPlayers
- Number of players that play the game. Works with any possitive number but normal values are in [2,8]
-
-
Method Details
-
initialize
public void initialize() -
drawCard
Called byCardSquare
to notify the UI so that it can display a message to the userMoveCard
andJailCard
.
Objects also need to set their resulting square to the current board. It need to be at runtime because cards are constructed using csv files with no reference to the current Board- Parameters:
card
- TheCard
that has been drawn
-
gameLoop
public void gameLoop(int dice)To be called by the UI at the start of the turn.
Moves the player, runs the action of the resulting square and checks if player passed start- Parameters:
dice
- By how many squares should thePawn
move.
-
endTurn
public void endTurn()To be called by the UI when the player finished his turn
Checks if the player lost or won and proceeds to the next player -
getPlayers
-
getNumberOfPlayers
public int getNumberOfPlayers() -
getBoard
-
getCurrentPlayer
-
setCurrentPlayer
public void setCurrentPlayer(int i) -
getListener
-
setListener
-