Back to project page diploma-assignment.
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.
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; } } }