[ all classes ]
[ com.mozarellabytes.kroy ]
Coverage Summary for Class: GameState (com.mozarellabytes.kroy)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
GameState | 0% (0/ 1) | 0% (0/ 9) | 0% (0/ 16) |
1 package com.mozarellabytes.kroy;
2
3 import com.mozarellabytes.kroy.Screens.GameOverScreen;
4
5 /** This class is used to keep track of the player's progress within
6 * the game. It keeps track of how many active fire trucks the user
7 * has and how many fortresses have been destroyed and causes the game
8 * to end declaring the player has having won or lost
9 */
10
11 public class GameState {
12
13 /** Number of fire trucks there are on screen */
14 private int activeFireTrucks;
15
16 /** The number of fortresses the player has destroyed */
17 private int fortressesDestroyed;
18
19 /** The number of trucks that have a fortress within their attack range */
20 private int trucksInAttackRange;
21
22 /** Constructor for GameState */
23 public GameState() {
24 this.activeFireTrucks = 0;
25 this.fortressesDestroyed = 0;
26 }
27
28 /** Adds one to activeFireTrucks, called when a firetruck is spawned */
29 public void addFireTruck() {
30 this.activeFireTrucks++;
31 }
32
33 /** Removes one from activeFireTrucks, called when a firetruck
34 * is destroyed */
35 public void removeFireTruck() {
36 this.activeFireTrucks--;
37 }
38
39 /** Adds one to fortressesDestroyed when a user has destroyed a
40 * fortress */
41 public void addFortress() {
42 this.fortressesDestroyed++;
43 }
44
45 /** Determines whether the game has ended either when a certain
46 * number of fortresses have been destroyed or when there are no
47 * fire trucks left
48 * @param game LibGDX game
49 */
50 public void hasGameEnded(Kroy game) {
51 if (fortressesDestroyed == 3) {
52 endGame(true, game);
53 } else if (this.activeFireTrucks == 0) {
54 endGame(false, game);
55 }
56 }
57
58 /** Triggers the appropriate game over screen depending
59 * on if the user has won or lost
60 * @param playerWon <code> true </code> if player has won
61 * <code> false </code> if player has lost
62 * @param game LibGDX game
63 */
64 private void endGame(Boolean playerWon, Kroy game) {
65 if (playerWon) {
66 game.setScreen(new GameOverScreen(game, true));
67 } else {
68 game.setScreen(new GameOverScreen(game, false));
69 }
70 }
71
72 public void setTrucksInAttackRange(int number){
73 trucksInAttackRange = number;
74 }
75
76 public void incrementTrucksInAttackRange(){
77 trucksInAttackRange++;
78 }
79
80 public int getTrucksInAttackRange(){
81 return trucksInAttackRange;
82 }
83
84
85 }