⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 character.java

📁 j2me 手机游戏
💻 JAVA
字号:
import java.util.Vector;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;//--------------------------------------------------------------------------------------------------------//游戏名称: 仙剑奇侠传//作者: 张卫国//E-mail: weiguo2000@hotmail.com//创建于:2006/7/18--2006/8/3  by Weiguo////--------------------------------------------------------------------------------------------------------public class Character{				public String name = "";			//人物名称			public boolean bDead = false; 		//是否死亡		public int x     = 20;		public int y     = 50;				//人物的XY坐标值					private int dir  = 0;				//0 up 1 right 2 down 3 left		public int speed = 3; 				//速度		public int HP,MP; 					//目前的HP,MP		public int MaxHP,MaxMP; 			//最大HP和MP		public int Level = 100; 				//目前的等级		public int Exp; 					//目前的经验		public int MaxExp; 					//升级的经验		public int wu; 						//武力		public int ling; 					//灵力		public int shen; 					//身法		public int ti; 						//体质		public int ji; 						//吉运		public int money=10000;					//携带的金钱		public Vector goodsList   = null; 	//角色所携带的物品	    public String magicList[] = null; 	//角色拥有的技能	    public Item weaClList[]   = null;   //角色所穿武器装备	    									//0 头戴,1 衣服,2 武器,3 鞋子	  	    public Vector petsList	  = null;	//角色所携带的宠物,最多3个	    	    private Image[] currentImage = null;	    private int frameID;	    	    public int DecreaseHP = 0;	    		public Character(String name) {			this.name=name;			this.frameID=1;			this.currentImage=XianJianImage.imgPlayerr;			this.HP=68;			this.MP=30;			this.MaxExp=8;			this.MaxHP=68;			this.MaxMP=30;			this.wu=25;			this.ling=10;			this.shen=10;			this.ti=17;			this.ji=10;				this.money=500;			this.magicList=new String[2];			magicList[0]="剑术1";			magicList[1]="剑术2";			this.goodsList=new Vector();				this.weaClList = new Item[4];			for(int i=0;i<this.weaClList.length;i++){				this.weaClList[i] = null;			}			this.petsList = new Vector();			Animal pet1 = new Animal(0);			Animal pet2 = new Animal(1);			this.petsList.addElement(pet1);			this.petsList.addElement(pet2);					}						public void addGoods(Item item){			int i=0;			for(;i<goodsList.size();i++){					if (goodsList.elementAt(i) instanceof ItemManager) {										if(((ItemManager) goodsList.elementAt(i)).getItem().getID()==item.getID())					{										((ItemManager) goodsList.elementAt(i)).addItemNum();						break;					}				}							}			if(i>=goodsList.size()){				ItemManager kindsgoods=new ItemManager(item,1);				goodsList.addElement(kindsgoods);			}		}				public void useGoods(int i){			switch(((ItemManager) goodsList.elementAt(i)).getItem().getID()/1000){			case 1:				HP+=((ItemManager) goodsList.elementAt(i)).getItem().getAddHp();				MP+=((ItemManager) goodsList.elementAt(i)).getItem().getAddMp();				if(HP>MaxHP){					HP=MaxHP;				}				if(MP>MaxMP){					MP=MaxMP;				}				((ItemManager) goodsList.elementAt(i)).decreaseNum();				if(((ItemManager) goodsList.elementAt(i)).getItemNum()==0){					goodsList.removeElementAt(i);				}				break;			case 2:				addWeaCl(((ItemManager) goodsList.elementAt(i)).getItem());				((ItemManager) goodsList.elementAt(i)).decreaseNum();				if(((ItemManager) goodsList.elementAt(i)).getItemNum()==0){					goodsList.removeElementAt(i);				}				break;			default:				break;							}					}		public void saleGoods(int i){			this.money += ((ItemManager) goodsList.elementAt(i)).getItem().getPrice()/2;			((ItemManager) goodsList.elementAt(i)).decreaseNum();						if(((ItemManager) goodsList.elementAt(i)).getItemNum()==0){				goodsList.removeElementAt(i);			}					}		public void buyGoods(Item item){			if(money>item.getPrice()){				addGoods(item);								money -= item.getPrice();			}					}				public void addWeaCl(Item wea){			if(weaClList[wea.getID()%1000/100]==null){				weaClList[wea.getID()%1000/100]=wea;			}			else{											removeWeaCl(wea.getID()%1000/100);				weaClList[wea.getID()%1000/100] = wea;			}									this.MaxHP += wea.getAddMaxHP();			this.MaxMP += wea.getAddMaxMP();			this.wu    += wea.getAddWu();			this.ti	   += wea.getAddTi();			this.ling  += wea.getAddLing();											if(HP>MaxHP){				HP=MaxHP;			}			if(MP>MaxMP){				MP=MaxMP;			}		}				public void removeWeaCl(int i){			if(weaClList[i]!=null){				addGoods(weaClList[i]);				this.MaxHP -= this.weaClList[i].getAddMaxHP();				this.MaxMP -= this.weaClList[i].getAddMaxMP();				this.wu    -= this.weaClList[i].getAddWu();				this.ti	   -= this.weaClList[i].getAddTi();				this.ling  -= this.weaClList[i].getAddLing();								weaClList[i] = null;			}			if(HP>MaxHP){				HP=MaxHP;			}			if(MP>MaxMP){				MP=MaxMP;			}		}				public void setPosition(int x,int y){			this.x=x;			this.y=y;		}				public void updateState(){			for(int i = 0;i<weaClList.length;i++){				if(weaClList[i]!=null){					this.MaxHP += weaClList[i].getAddMaxHP();					this.MaxMP += weaClList[i].getAddMaxMP();					this.wu    += weaClList[i].getAddWu();					this.ti	   += weaClList[i].getAddTi();					this.ling  += weaClList[i].getAddLing();				}			}						HP=MaxHP;			MP=MaxMP;					}				public void levelUp(){			this.Level++;			switch(Level){			case 0:				this.MaxExp=8;								this.MaxHP=68;				this.HP=68;				this.MaxMP=30;				this.MP=30;				this.wu=25;				this.ling=10;				this.shen=10;				this.ti=17;				this.ji=10;								break;			case 1:				this.MaxExp=15;				this.MaxHP=72;				this.MaxMP=33;				this.HP=72;				this.MP=33;				this.wu=26;				this.ling=11;				this.shen=11;				this.ti=18;				this.ji=11;				this.magicList=new String[2];				magicList[0]="剑术1";				magicList[1]="剑术2";				break;			case 2:				this.MaxExp=22;				this.MaxHP=80;				this.MaxMP=39;				this.HP=80;				this.MP=39;				this.wu=28;				this.ling=13;				this.shen=13;				this.ti=20;				this.ji=13;				this.magicList=new String[2];				magicList[0]="剑术1";				magicList[1]="剑术2";				break;			case 3:				this.MaxExp=29;				this.MaxHP=84;				this.MaxMP=42;				this.HP=84;				this.MP=42;				this.wu=29;				this.ling=14;				this.shen=14;				this.ti=21;				this.ji=14;				this.magicList=new String[2];				magicList[0]="剑术1";				magicList[1]="剑术2";				break;			case 4:				this.MaxExp=36;				this.MaxHP=92;				this.MaxMP=48;				this.HP=92;				this.MP=48;				this.wu=31;				this.ling=15;				this.shen=15;				this.ti=22;				this.ji=15;				this.magicList=new String[2];				magicList[0]="剑术1";				magicList[1]="剑术2";				break;			default:				break;			}			updateState();		}		public void changeDir(int dir){			this.dir=dir;			switch(dir){			case 0: //上				this.currentImage=XianJianImage.imgPlayeru;				break;			case 1: //右				this.currentImage=XianJianImage.imgPlayerr;				break;			case 2:  //下				this.currentImage=XianJianImage.imgPlayerd;				break;			case 3:  //左				this.currentImage=XianJianImage.imgPlayerl;				break;			default:				break;				}					}				public void nextFrame(){			frameID++;			frameID%=currentImage.length;		}		public int getDir(){			return dir;		}						public void move(){			switch(dir){			case 0://上				x+=speed*2;				y+=-speed;											break;			case 1://右				x+=speed*2;				y+=speed;								break;			case 2://下				x+=-speed*2;				y+=speed;								break;			case 3://左				x+=-speed*2;				y+=-speed;							break;			}			nextFrame();		}		public void moveback(){			switch(dir){			case 0:				x+=-speed*2;				y+=speed;								break;			case 1:				x+=-speed*2;				y+=-speed;								break;			case 2:				x+=speed*2;				y+=-speed;								break;			case 3:				x+=speed*2;				y+=speed;								break;			}			nextFrame();		}  public void draw(int xtmp,int ytmp,Graphics g) {       g.drawImage(currentImage[frameID],xtmp+x-6,ytmp+y-19,Graphics.TOP | Graphics.LEFT);     }    public String getName() {    return this.name;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -