Coverage Summary for Class: ShopScreen (com.mygdx.game.UI)
| Class | Method, % | Line, % |
|---|---|---|
| ShopScreen | 0% (0/7) | 0% (0/42) |
| ShopScreen$1 | 0% (0/2) | 0% (0/4) |
| ShopScreen$2 | 0% (0/2) | 0% (0/2) |
| ShopScreen$3 | 0% (0/2) | 0% (0/2) |
| Total | 0% (0/13) | 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.Image; 7 import com.badlogic.gdx.scenes.scene2d.ui.Label; 8 import com.badlogic.gdx.scenes.scene2d.ui.Table; 9 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 10 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 11 import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; 12 import com.badlogic.gdx.utils.ScreenUtils; 13 import com.mygdx.game.Components.ComponentEvent; 14 import com.mygdx.game.Components.Pirate; 15 import com.mygdx.game.Entitys.Player; 16 import com.mygdx.game.Managers.EntityManager; 17 import com.mygdx.game.Managers.GameManager; 18 import com.mygdx.game.Managers.PhysicsManager; 19 import com.mygdx.game.Managers.ResourceManager; 20 import com.mygdx.game.PirateGame; 21 22 import static com.mygdx.utils.Constants.*; 23 import static com.mygdx.utils.Constants.PHYSICS_TIME_STEP; 24 25 /**NEW 26 * Contains widgets defining the shop screen. 27 */ 28 public class ShopScreen extends Page { 29 public ShopScreen(PirateGame parent) { 30 super(parent); 31 } 32 33 34 private float accumulator; 35 36 /** 37 * Called every frame calls all other functions that need to be called every frame by rasing events and update methods 38 * 39 * @param delta delta time 40 */ 41 @Override 42 public void render(float delta) { 43 // show game screen if ESC key is pressed 44 if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { 45 parent.setScreen(parent.game); 46 } 47 super.render(delta); 48 } 49 50 @Override 51 protected void update() { 52 super.update(); 53 Player p = GameManager.getPlayer(); 54 55 GameScreen.healthLabel.setText(String.valueOf(p.getHealth())); 56 GameScreen.dosh.setText(String.valueOf(p.getPlunder())); 57 GameScreen.ammo.setText(String.valueOf(p.getAmmo())); 58 } 59 60 61 /** 62 * Create menu widgets such as start button, labels, etc. 63 */ 64 @Override 65 protected void CreateActors() { 66 Table t = new Table(); 67 t.setFillParent(true); 68 69 float space = VIEWPORT_HEIGHT* 0.05f; // gap between rows in table 70 71 t.setBackground(new TextureRegionDrawable(ResourceManager.getTexture("shopBG.jpg"))); 72 Label l = new Label("Shop", parent.skin); 73 l.setFontScale(2); 74 t.add(l).top().spaceBottom(space * 0.5f); 75 76 t.row(); 77 TextButton buyAmmo = new TextButton("Buy Ammo", parent.skin); 78 buyAmmo.addListener(new ChangeListener() { 79 @Override 80 public void changed(ChangeEvent event, Actor actor) { 81 if(Pirate.plunder >= 10){ 82 Pirate.ammo += 10; // add 10 ammo 83 Pirate.plunder -= 10; // take away 10 coins 84 } 85 } 86 }); 87 t.add(buyAmmo).size(100, 25).top().spaceBottom(10); 88 t.row(); 89 t.add(new Label("Buy 10 cannons for 10 coins", parent.skin)).spaceBottom(10); 90 t.row(); 91 t.add(new Image(parent.skin, "ball")).top().left(); 92 t.add(new Label("10", parent.skin)).right().spaceBottom(space); 93 94 95 t.row(); 96 TextButton buyPowerups = new TextButton("Powerups", parent.skin); 97 buyPowerups.addListener(new ChangeListener() { 98 @Override 99 public void changed(ChangeEvent event, Actor actor) { 100 parent.setScreen(parent.powerup); 101 } 102 }); 103 t.add(buyPowerups).size(100, 25).top().spaceBottom(10); 104 t.row(); 105 t.add(new Label("Continue to the powerup page", parent.skin)).spaceBottom(space); 106 107 108 t.row(); 109 TextButton back = new TextButton("Return", parent.skin); 110 back.addListener(new ChangeListener() { 111 @Override 112 public void changed(ChangeEvent event, Actor actor) { 113 parent.setScreen(parent.game); 114 } 115 }); 116 t.add(back).top().size(100, 25).spaceBottom(space); 117 118 t.top(); 119 120 actors.add(t); 121 } 122 123 124 @Override 125 public void show() { 126 super.show(); 127 } 128 129 @Override 130 public void hide() { 131 super.hide(); 132 } 133 134 /** 135 * Used to resize the background texture to the correct size to fill the window 136 * @param width new dim x width of the screen 137 * @param height new dom y height of the screen 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("shopBG.jpg"))); // prevent the bg being stretched 144 } 145 }