Package pacManReloaded.server
Class GameLogic
- java.lang.Object
-
- pacManReloaded.server.GameLogic
-
- All Implemented Interfaces:
INavigator
public class GameLogic extends java.lang.Object implements INavigator
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckSuperPower()checks if super power is active, while active the ghosts will get a message so they know the PacMans are able to hunt themvoidcollisionWithBallGhost(Ball o)handles the collision by a ghost with a ball, updates score and the game state, removes the ball on the mapvoidcollisionWithBallPacMan(Ball o)handles the collision by a pacman with a ball, updates score and the game state, removes the ball on the mapvoidcollisionWithPowerballGhost(PowerBall o)handles the collision by a ghost with a powerball, updates score and the game state, removes the ball on the mapvoidcollisionWithPowerballPacMan(PowerBall o)handles the collision by a pacman with a powerball, updates score and the game state, removes the ball on the mapvoidcreateBall(java.awt.geom.Point2D.Float point)creates new ball and adds it to the appropriate listvoiddetectCollisions()this method finds out of the next step of an actor is a collision with another object/wallvoiddoPlay()decides which part of the game will happens next, depending on the game statusjava.awt.geom.Point2D.FloatgetExitPosition()GameStategetGameState()"getter" for the game stateGameStatusgetGameStatus()"getter" for the game statusfloatgetMapSize()java.lang.ObjectgetObjectAtPosition(java.awt.geom.Point2D.Float position)PacMangetPacman()"getter" for the PacMansjava.awt.geom.Point2D.FloatgetPacmanPosition()booleanisDone()method which checks if the game is over/donebooleanisInSpawn(Ghost ghost)voidnextMove()allows all actors to perform their next step, in addition, calls the operation checkSuperPower() and detectCollision().voidremoveObject(Ball o)removes the object from the mapvoidsetGameStatus(GameStatus gameStatus)"setter" for the game status
-
-
-
Constructor Detail
-
GameLogic
public GameLogic(java.util.ArrayList<Player> players, Server server)
Constructor of the Class, starts a game with the players and server as parameters- Parameters:
players- the players who will be in the game as arraylistserver- the server where the game will be played on
-
GameLogic
public GameLogic()
Dummy-Constructor for Unit tests
-
-
Method Detail
-
nextMove
public void nextMove()
allows all actors to perform their next step, in addition, calls the operation checkSuperPower() and detectCollision().
-
detectCollisions
public void detectCollisions()
this method finds out of the next step of an actor is a collision with another object/wall
-
collisionWithPowerballPacMan
public void collisionWithPowerballPacMan(PowerBall o)
handles the collision by a pacman with a powerball, updates score and the game state, removes the ball on the map- Parameters:
o- the powerball on the map
-
collisionWithPowerballGhost
public void collisionWithPowerballGhost(PowerBall o)
handles the collision by a ghost with a powerball, updates score and the game state, removes the ball on the map- Parameters:
o- the powerball on the map
-
removeObject
public void removeObject(Ball o)
removes the object from the map- Parameters:
o- the object getting removed
-
collisionWithBallPacMan
public void collisionWithBallPacMan(Ball o)
handles the collision by a pacman with a ball, updates score and the game state, removes the ball on the map- Parameters:
o- the ball on the map
-
collisionWithBallGhost
public void collisionWithBallGhost(Ball o)
handles the collision by a ghost with a ball, updates score and the game state, removes the ball on the map- Parameters:
o- the ball on the map
-
getPacman
public PacMan getPacman()
"getter" for the PacMans- Returns:
- players who are PacMans
-
checkSuperPower
public void checkSuperPower()
checks if super power is active, while active the ghosts will get a message so they know the PacMans are able to hunt them
-
createBall
public void createBall(java.awt.geom.Point2D.Float point)
creates new ball and adds it to the appropriate list
-
doPlay
public void doPlay()
decides which part of the game will happens next, depending on the game status
-
isDone
public boolean isDone()
method which checks if the game is over/done- Returns:
- true: game is over; false: game not over yet
-
getGameStatus
public GameStatus getGameStatus()
"getter" for the game status- Returns:
- the actual game status
-
setGameStatus
public void setGameStatus(GameStatus gameStatus)
"setter" for the game status- Parameters:
gameStatus- the game status
-
getObjectAtPosition
public java.lang.Object getObjectAtPosition(java.awt.geom.Point2D.Float position)
- Specified by:
getObjectAtPositionin interfaceINavigator
-
getMapSize
public float getMapSize()
- Specified by:
getMapSizein interfaceINavigator
-
getPacmanPosition
public java.awt.geom.Point2D.Float getPacmanPosition()
- Specified by:
getPacmanPositionin interfaceINavigator
-
getExitPosition
public java.awt.geom.Point2D.Float getExitPosition()
- Specified by:
getExitPositionin interfaceINavigator
-
isInSpawn
public boolean isInSpawn(Ghost ghost)
- Specified by:
isInSpawnin interfaceINavigator
-
getGameState
public GameState getGameState()
"getter" for the game state- Returns:
- the current game state
-
-