Coverage Summary for Class: EndScreen (com.mygdx.game.UI)
| Class | Method, % | Line, % |
|---|---|---|
| EndScreen | 0% (0/7) | 0% (0/47) |
| EndScreen$1 | 0% (0/2) | 0% (0/3) |
| Total | 0% (0/9) | 0% (0/50) |
1 package com.mygdx.game.UI; 2 3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Input; 5 import com.badlogic.gdx.scenes.scene2d.Actor; 6 import com.badlogic.gdx.scenes.scene2d.ui.Label; 7 import com.badlogic.gdx.scenes.scene2d.ui.Table; 8 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 9 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 10 import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 11 import com.mygdx.game.Components.Pirate; 12 import com.mygdx.game.Entitys.Player; 13 import com.mygdx.game.Managers.DifficultyManager; 14 import com.mygdx.game.Managers.GameManager; 15 import com.mygdx.game.Managers.QuestManager; 16 import com.mygdx.game.Managers.ResourceManager; 17 import com.mygdx.game.PirateGame; 18 19 import static com.mygdx.utils.Constants.VIEWPORT_HEIGHT; 20 21 /** 22 * Contains widgets defining the game end screen. 23 */ 24 public class EndScreen extends Page { 25 Label wonText; 26 Label playerStats; 27 28 Integer questsNeeded ; 29 Integer pointsNeeded; 30 31 public EndScreen(PirateGame game) { 32 super(game); 33 } 34 35 /** 36 * Set game end screen status to report a win. 37 */ 38 public void win() { 39 wonText.setText("Congrats You Have Won"); 40 } 41 42 /** 43 * Create game end screen widgets, initialised to game loss status. 44 */ 45 @Override 46 protected void CreateActors() { 47 Table t = new Table(); 48 t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("menuBG.jpg"))); 49 50 float space = VIEWPORT_HEIGHT * 0.25f; 51 t.setFillParent(true); 52 actors.add(t); 53 wonText = new Label("You have lost", parent.skin); 54 wonText.setFontScale(2); 55 t.top(); 56 t.add(wonText).top().spaceBottom(space); 57 t.row(); 58 playerStats = new Label("Player Stats:\n", parent.skin); 59 t.add(playerStats).spaceBottom(space); 60 t.row(); 61 TextButton b = new TextButton("Exit", parent.skin); 62 b.addListener(new ChangeListener() { 63 @Override 64 public void changed(ChangeEvent event, Actor actor) { 65 Gdx.app.exit(); 66 System.exit(0); 67 } 68 }); 69 t.add(b); 70 } 71 72 @Override 73 protected void update() { 74 super.update(); 75 76 if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { 77 Gdx.app.exit(); 78 System.exit(0); 79 } 80 81 } 82 83 /** 84 * Get player stats such as plunder etc. and display game end screen. 85 */ 86 @Override 87 public void show() { 88 super.show(); 89 if(WinCheck()){ 90 win(); 91 } 92 Player p = GameManager.getPlayer(); 93 String stats = String.format("Health: %s\nAmmo: %s\nPlunder: %s\nPoints: %s/%s\nQuests Completed: %s/%s", p.getHealth(), p.getAmmo(), p.getPlunder(),p.getComponent(Pirate.class).getPoints(),pointsNeeded,QuestManager.numCompleted,questsNeeded); 94 playerStats.setText(stats); 95 96 97 } 98 99 /**NEW 100 * Checks if the player meets the win conditions based on the difficulty level 101 * @return A Boolean based on whether the player has won 102 */ 103 private boolean WinCheck(){ 104 Boolean result = false; 105 questsNeeded = 0; 106 pointsNeeded = 0; 107 switch (DifficultyManager.getDifficulty()){ 108 case "e": 109 questsNeeded =1; 110 pointsNeeded = 100; 111 break; 112 113 case "n": 114 questsNeeded = 3; 115 pointsNeeded = 500; 116 break; 117 118 119 case "h": 120 questsNeeded = 5; 121 pointsNeeded = 1000; 122 break; 123 124 } 125 if(QuestManager.numCompleted>=questsNeeded){ 126 if(GameManager.getPlayer().getComponent(Pirate.class).getPoints()>pointsNeeded){ 127 result = true; 128 } 129 } 130 return result; 131 132 } 133 134 135 /** 136 * @param width new dim x 137 * @param height new dom y 138 */ 139 @Override 140 public void resize(int width, int height) { 141 super.resize(width, height); 142 Table t = (Table) actors.get(0); 143 t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("menuBG.jpg"))); // prevent the bg being stretched 144 } 145 }