Coverage Summary for Class: EndScreen (com.mygdx.game.UI)

Class Method, % Line, %
EndScreen 0% (0/6) 0% (0/29)
EndScreen$1 0% (0/2) 0% (0/3)
Total 0% (0/8) 0% (0/32)


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.Entitys.Player; 12 import com.mygdx.game.Managers.GameManager; 13 import com.mygdx.game.Managers.ResourceManager; 14 import com.mygdx.game.PirateGame; 15  16 import static com.mygdx.utils.Constants.VIEWPORT_HEIGHT; 17  18 /** 19  * Contains widgets defining the game end screen. 20  */ 21 public class EndScreen extends Page { 22  Label wonText; 23  Label playerStats; 24  25  /** 26  * Creates an End Screen 27  * @param game The game object this screen is viewing 28  */ 29  public EndScreen(PirateGame game) { 30  super(game); 31  } 32  33  /** 34  * Set game end screen status to report a win. 35  */ 36  public void win() { 37  wonText.setText("Congrats You Have Won"); 38  } 39  40  /** 41  * Create game end screen widgets, initialised to game loss status. 42  */ 43  @Override 44  protected void CreateActors() { 45  Table t = new Table(); 46  t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("menuBG.jpg"))); 47  48  float space = VIEWPORT_HEIGHT * 0.25f; 49  t.setFillParent(true); 50  actors.add(t); 51  wonText = new Label("Game Over", parent.skin); 52  wonText.setFontScale(2); 53  t.top(); 54  t.add(wonText).top().spaceBottom(space); 55  t.row(); 56  playerStats = new Label("Player Stats:\n", parent.skin); 57  t.add(playerStats).spaceBottom(space); 58  t.row(); 59  TextButton b = new TextButton("Exit", parent.skin); 60  b.addListener(new ChangeListener() { 61  @Override 62  public void changed(ChangeEvent event, Actor actor) { 63  Gdx.app.exit(); 64  System.exit(0); 65  } 66  }); 67  t.add(b); 68  } 69  70  /** 71  * Called Once per Frame 72  */ 73  @Override 74  protected void update() { 75  super.update(); 76  77  if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { 78  Gdx.app.exit(); 79  System.exit(0); 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  Player p = GameManager.getPlayer(); 90  String stats = String.format("Health: %s\nAmmo: %s\nPoints: %s\nPlunder: %s", p.getHealth(), p.getAmmo(), p.getPoints(), p.getPlunder()); 91  playerStats.setText(stats); 92  } 93  94  /** 95  * Resizes the viewport 96  * @param width The horizontal dimension of the viewport 97  * @param height The vertical dimension of the viewport 98  */ 99  @Override 100  public void resize(int width, int height) { 101  super.resize(width, height); 102  Table t = (Table) actors.get(0); 103  t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("menuBG.jpg"))); // prevent the bg being stretched 104  } 105 }