Android Open Source - diploma-assignment Computer Player






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.battlescreen;
// w w w.  j  av  a  2  s  .c o m
import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.graphics.Texture;

public class ComputerPlayer extends BattlePlayer{
  
  private BattleScreen screen;
  private ArrayList<Texture[]> textures;
  private List<int[]> id_list;
  private List<Integer> pickList;
  private boolean waiting;
  private final int[] manaForMonsters={100,300,600,1000,1500,2100,3000};
  private int indexNext;
  private int waitTime;
  
  ComputerPlayer(BattleScreen s,int level) {
    super(0, 0,new int[]{},new int[]{});
    
    // TODO Auto-generated constructor stub
    unlockedList=Bot.getUnlocked(level);
    int[] weights=Bot.getWeights(level);
    maxMana=Bot.getMaxMana(level);
    manaReg=Bot.getManaReg(level);
    screen=s;
    textures=new ArrayList<Texture[]>();
    id_list=new ArrayList<int[]>();
    pickList=new ArrayList<Integer>();
    loadPickList(weights);
    waiting=false;
    indexNext=-1;
    waitTime=0;
  }
  
  private void loadPickList(int[] weights) {
    int i,j;
    for(i=0;i<unlockedList.length;i++)
      if(unlockedList[i]==1){
        for(j=0;j<weights[i];j++){
          pickList.add(i);
        }
      }
  }

  public void setMonsters(){
    final ArrayList<Texture> walk=new ArrayList<Texture>();
    getTextures.getWalkingNecro(walk);
    final ArrayList<Texture> die=new ArrayList<Texture>();
    getTextures.getDyingNecro(die);
    final ArrayList<Texture> fight=new ArrayList<Texture>();
    getTextures.getAttackingNecro(fight);
    for(int i=0;i<7;i++){
      textures.add(new Texture[]{walk.get(i),die.get(i),fight.get(i)});
    }
    id_list = new ArrayList<int[]>();
    getTextures.getIdItemsNecro(id_list,screen.getHeight());
  }
  
  public void checkForUnit(){
    if(waiting && currMana>=manaForMonsters[indexNext]){
        if(waitTime>0){
          waitTime--;
          return;
        }
        this.decreaseCurrMana(manaForMonsters[indexNext]);
        OpponentMonster m=new OpponentMonster(screen,
            textures.get(indexNext),id_list.get(indexNext),
            (BattlePlayer)this,manaForMonsters[indexNext]/25,indexNext);
        screen.addMonster(m);
        waiting=false;
    } else if (!waiting){
      indexNext=pickList.get((int)(Math.random()*pickList.size()));
      waitTime=(int) (Math.random()*Constants.MAX_COMPUTER_UNIT_WAIT_TIME);
      waiting=true;
    }
  }

}




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