Android Open Source - diploma-assignment Player Menu






From Project

Back to project page diploma-assignment.

License

The source code is released under:

MIT License

If you think the Android project diploma-assignment listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.me.openingscreen;
//w  w  w  .  ja  va  2 s  . c om
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.me.battlescreen.MyButton;
import com.me.battlescreen.MyLabel;

public class PlayerMenu extends AbstractMenu{

  MyButton toBattleScreen;
  MyButton toUpgradeScreen;
  MyButton toStatisticsScreen;
  MyButton toFirstMenu;
  MyLabel gold;
  MyLabel level;
  BitmapFont font;
  
  public PlayerMenu(OpeningScreen s, Stage st) {
    super(s, st);
    // TODO Auto-generated constructor stub
    
    font=new BitmapFont(Gdx.files.internal("data/myFont.fnt"),Gdx.files.internal("data/myFont.png"),false);
    font.setUseIntegerPositions(false);
    font.setScale(s.getHeight()*0.10f/font.getLineHeight());
    
    gold=new MyLabel(screen,"123456",font,new int[]{0,screen.getHeight()});
    gold.setTouchable(Touchable.disabled);
    updateGold();
    level=new MyLabel(screen,"Level:"+screen.game.getPlayer().getLevel(),font,new int[]{(int)(screen.getWidth()*0.7f),screen.getHeight()});
    level.setTouchable(Touchable.disabled);
    stage.addActor(gold);
    stage.addActor(level);
    
    createButtons();
    
    addListeners();
  }
  
  @Override
  protected void createButtons() {
    Texture t=new Texture(Gdx.files.internal("data/menus/battle.png"));
    toBattleScreen=new MyButton(t);
    createButton(toBattleScreen,7,t,1);
    
    t=new Texture(Gdx.files.internal("data/menus/upgrade.png"));
    toUpgradeScreen=new MyButton(t);
    createButton(toUpgradeScreen,5,t,1);
    
    t=new Texture(Gdx.files.internal("data/menus/statistics.png"));
    toStatisticsScreen=new MyButton(t);
    createButton(toStatisticsScreen,3,t,1);
    
    t=new Texture(Gdx.files.internal("data/menus/return.png"));
    toFirstMenu=new MyButton(t);
    createButton(toFirstMenu,1,t,1);
  }

  @Override
  protected void addListeners() {
    
    addToBattleListener();
    
    addToUpgradeListener();
    
    addToStatisticsListener();
    
    addToFirstMenuListener();
    
  }
  
  private void addToBattleListener() {
    // TODO Auto-generated method stub
    toBattleScreen.addListener(new InputListener(){
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        toBattleScreen.setPressed(true);
                return true;
      }
        
      public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
        toBattleScreen.setPressed(false);
        screen.game.battle();
      }
    });
  }
  
  private void addToUpgradeListener() {
    // TODO Auto-generated method stub
    toUpgradeScreen.addListener(new InputListener(){
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        toUpgradeScreen.setPressed(true);
                return true;
      }
        
      public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
        toUpgradeScreen.setPressed(false);
        screen.setMenu(new UpgradeMenu(screen,stage));
          }
    });
  }
  
  private void addToStatisticsListener() {
    // TODO Auto-generated method stub
    toStatisticsScreen.addListener(new InputListener(){
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        toStatisticsScreen.setPressed(true);
                return true;
      }
        
      public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
        toStatisticsScreen.setPressed(false);
        screen.setMenu(new StatisticsMenu(screen,stage));
          }
    });
  }

  private void addToFirstMenuListener() {
    // TODO Auto-generated method stub
    toFirstMenu.addListener(new InputListener(){
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        toFirstMenu.setPressed(true);
                return true;
      }
        
      public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
        toFirstMenu.setPressed(false);
        screen.setMenu(new FirstMenu(screen,stage));
          }
    });
  }
  
  public void updateGold() {
    // TODO Auto-generated method stub
    long temp=screen.game.getPlayer().getGold();
    if(temp==0)
      temp=1;
    int count=0;
    while(temp>0){
      temp/=10;
      count++;
    }
    String s="";
    for(int i=0;i<8-count;i++){
      s=s+" ";
    }
    gold.setText("Gold:"+s+screen.game.getPlayer().getGold());
  }

}




Java Source Code List

com.me.battlescreen.BallistaArrow.java
com.me.battlescreen.Ballista.java
com.me.battlescreen.BattlePlayer.java
com.me.battlescreen.BattleScreen.java
com.me.battlescreen.Bot.java
com.me.battlescreen.Castle.java
com.me.battlescreen.CleanBackground.java
com.me.battlescreen.ComputerPlayer.java
com.me.battlescreen.Constants.java
com.me.battlescreen.HumanPlayer.java
com.me.battlescreen.Monster.java
com.me.battlescreen.MyButton.java
com.me.battlescreen.MyLabel.java
com.me.battlescreen.OpponentMonster.java
com.me.battlescreen.PlayerMonster.java
com.me.battlescreen.TimeLabel.java
com.me.battlescreen.UnitButton.java
com.me.battlescreen.getTextures.java
com.me.battlescreen.iAttacking.java
com.me.battlescreen.iHittable.java
com.me.battlescreen.iUpdateable.java
com.me.main.MyGame.java
com.me.main.Player.java
com.me.mygdxgame.MainActivity.java
com.me.openingscreen.AbstractMenu.java
com.me.openingscreen.Constants.java
com.me.openingscreen.FirstMenu.java
com.me.openingscreen.FloatingBackground.java
com.me.openingscreen.OpeningScreen.java
com.me.openingscreen.PlayerMenu.java
com.me.openingscreen.ResetMenu.java
com.me.openingscreen.StatisticsMenu.java
com.me.openingscreen.UpgradeButton.java
com.me.openingscreen.UpgradeMenu.java