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

📄 battlecanvas.java

📁 游戏的故事 一款适合学习用的RPG游戏 WTK运行,内有截图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					keySeq[i]=Math.abs(rnd.nextInt()%9);
					seq.setCell(i,0,keySeq[i]+1);
				}
				seq.paint(vbuf);
				repaint();
				drawText("优希 开始攻击!",1000);
				time=System.currentTimeMillis();
				while(true){
					curState=ATK_DOING;
					while(curState==ATK_DOING){
						t=(int)(System.currentTimeMillis()-time);
						if(t>5000)break;
						vbuf.setColor(0);
						vbuf.fillRect(182-t*178/5000,81,t*178/5000,8);
						repaint(182-t*178/5000,81,t*178/5000,8);
						parent.pause(10);
					}
					if(curState==ATK_DOING) break;
					seq.setCell(curKey,0,10+keySeq[curKey++]);
					seq.paint(vbuf);
					repaint();
					curState=ATK_DOING;
					if(curKey==12) break;
				}
				curState=ATK_WAIT;
				atkCnt=atk1*atkCnt/2;
				
				drawText("完成,"+name[eID]+"损失HP "+atkCnt,3000);
				eHP-=atkCnt;
				if(eHP<=0){
					if(theGame.sound) {
						parent.sp.playSE();
						wait=true;
					}
					drawText(name[eID]+"倒下了",1000);
					drawText("得到 EXP "+enemyData[eID][6]+"点",1000);
					drawText("得到GOLD "+enemyData[eID][7],1000);
					atkCnt=Math.abs(rnd.nextInt()%20);
					if(atkCnt<4){
						theGame.item[0]+=1;
						drawText("得到一个面包.",700);
					}else if(atkCnt<6){
						theGame.item[1]+=1;
						drawText("得到药丸.",700);
					}else if(atkCnt==6){
						theGame.item[2]+=1;
						drawText("得到水.",700);
					}
					theGame.EXP+=enemyData[eID][6];
					if(theGame.checkUP()) drawText("优希的能力提升了!",700);
					while(wait);
					parent.sp.setEnable(theGame.sound);
					return 0;
				}
				drawAll();
				
				atkCnt=0;
				for(int i=0;i<12;i++){
					keySeq[i]=Math.abs(rnd.nextInt()%9);
					seq.setCell(i,0,keySeq[i]+1);
				}
				seq.paint(vbuf);
				repaint();
				drawText(name[eID]+" 开始攻击!",1000);
				for(int i=0;i<12;i++){
					if(Math.abs(rnd.nextInt()%10)<eAI){
						seq.setCell(i,0,11);
						drawText("击中!",0);
						atkCnt++;
					}else{
						seq.setCell(i,0,10);
						drawText("Miss!",0);
					}
					vbuf.setColor(0);
					vbuf.fillRect(182-i*178/11,81,i*178/11,8);
					seq.paint(vbuf);
					repaint();
					parent.pause(300);
				}
				
				atkCnt=atk2*atkCnt/2;
				theGame.HP-=atkCnt;
				drawText("优希损失HP "+atkCnt,1000);
				if(theGame.HP<=0) {
					theGame.HP=0;
					curState=EXIT;
					drawText("优希失败了!",1000);
					return 1;
				}
			}
			curState=MENU;
			drawAll();
			vbuf.setColor(0);
			vbuf.drawString("攻击",20,204,Graphics.TOP|Graphics.LEFT);
			vbuf.drawString("回复",120,204,Graphics.TOP|Graphics.LEFT);
			vbuf.drawString("撤退",20,224,Graphics.TOP|Graphics.LEFT);
			vbuf.setColor(0xff0000);
			vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
			repaint();
			break;
		case RETREAT:
			curState=EXIT;
			return -1;
		case ITEM:
			menuSel=0;
			drawAll();
			vbuf.setColor(0);
			vbuf.drawString("面包  X "+theGame.item[0],20,204,Graphics.TOP|Graphics.LEFT);
			vbuf.drawString("药丸  X "+theGame.item[1],120,204,Graphics.TOP|Graphics.LEFT);
			vbuf.drawString("水  X "+theGame.item[2],20,224,Graphics.TOP|Graphics.LEFT);
			vbuf.drawString("取消",120,224,Graphics.TOP|Graphics.LEFT);
			vbuf.setColor(0xff0000);
			vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
			repaint();
			while(curState==ITEM) parent.pause(10);
			break;
		}
		parent.pause(600);
		
		} // while(curState!=EXIT);
		return 1;
	}
	
	public void keyPressed(int keyCode){
		int gameKey=getGameAction(keyCode);
		if(curState==EXIT) return;
		switch(curState){
		case ATK_DOING:
			if(keyCode==49+keySeq[curKey]) {keySeq[curKey]=1; atkCnt++;}
			else keySeq[curKey]=0;
			curState=ATK_WAIT;
			break;
		case MENU:
			if(gameKey==UP||gameKey==LEFT){
				if(menuSel!=0) menuSel-=1;
				parent.dlgbox.paint(vbuf);
				vbuf.setColor(0);
				vbuf.drawString("攻击",20,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("回复",120,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("撤退",20,224,Graphics.TOP|Graphics.LEFT);
				vbuf.setColor(0xff0000);
				if(menuSel==0) vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==1) vbuf.drawChar('*',112,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==2) vbuf.drawChar('*',12,224,Graphics.TOP|Graphics.LEFT);
				repaint();
			}else if(gameKey==DOWN||gameKey==RIGHT){
				if(menuSel!=2) menuSel+=1;
				parent.dlgbox.paint(vbuf);
				vbuf.setColor(0);
				vbuf.drawString("攻击",20,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("回复",120,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("撤退",20,224,Graphics.TOP|Graphics.LEFT);
				vbuf.setColor(0xff0000);
				if(menuSel==0) vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==1) vbuf.drawChar('*',112,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==2) vbuf.drawChar('*',12,224,Graphics.TOP|Graphics.LEFT);
				repaint();
			}else if(gameKey==FIRE){
				if(menuSel==0) curState=ATK_WAIT;
				else if(menuSel==1) curState=ITEM;
				else if(menuSel==2) {
					if(eAGI==999){
						drawText("不能撤退!",600);
					}else{
//						drawText("Hero 准备撤退...",1000);
						if(Math.abs(rnd.nextInt()%(theGame.AGI+eAGI))<theGame.AGI){
							drawText("优希成功得撤离了!",500);
							curState=RETREAT;
						}else{
							drawText("怪物紧追不放!",500);
							curState=MENU;
						}
					}
				}
			}
			break;
		case ATK_WAIT:
			break;
		case ITEM:
			if(gameKey==UP||gameKey==LEFT){
				if(menuSel!=0) menuSel-=1;
				parent.dlgbox.paint(vbuf);
				vbuf.setColor(0);
				vbuf.drawString("面包  X "+theGame.item[0],20,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("药丸  X "+theGame.item[1],120,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("水  X "+theGame.item[2],20,224,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("取消",120,224,Graphics.TOP|Graphics.LEFT);
				vbuf.setColor(0xff0000);
				if(menuSel==0) vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==1) vbuf.drawChar('*',112,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==2) vbuf.drawChar('*',12,224,Graphics.TOP|Graphics.LEFT);
				repaint();
			}else if(gameKey==DOWN||gameKey==RIGHT){
				if(menuSel!=3) menuSel+=1;
				parent.dlgbox.paint(vbuf);
				vbuf.setColor(0);
				vbuf.drawString("面包  X "+theGame.item[0],20,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("药丸  X "+theGame.item[1],120,204,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("水  X "+theGame.item[2],20,224,Graphics.TOP|Graphics.LEFT);
				vbuf.drawString("取消",120,224,Graphics.TOP|Graphics.LEFT);
				vbuf.setColor(0xff0000);
				if(menuSel==0) vbuf.drawChar('*',12,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==1) vbuf.drawChar('*',112,204,Graphics.TOP|Graphics.LEFT);
				else if(menuSel==2) vbuf.drawChar('*',12,224,Graphics.TOP|Graphics.LEFT);
				repaint();
			}else if(gameKey==FIRE){
				if(menuSel==0&&theGame.item[0]>0){
					theGame.item[0]-=1;
					theGame.HP+=60;
					if(theGame.HP>theGame.MaxHP) theGame.HP=theGame.MaxHP;
					drawText("优希 使用了面包, HP回复了60!",0);	
				}else if(menuSel==1&&theGame.item[1]>0){
					theGame.item[1]-=1;
					theGame.HP+=(theGame.MaxHP/2);
					if(theGame.HP>theGame.MaxHP) theGame.HP=theGame.MaxHP;
					drawText("优希  使用了药丸,HP回复了"+theGame.MaxHP/2+"!",0);
				}else if(menuSel==2&&theGame.item[2]>0){
					theGame.item[2]-=1;
					theGame.HP=theGame.MaxHP;
					drawText("优希 使用了水, HP完全回复了!",0);
				}else{
					drawText("道具没有了!",0);
				}
				repaint();
				parent.pause(10);
				curState=MENU;
			}
			break;
		}
	}

	public void run() {
		startBattle(0);
	}
	private void drawText(String t,long nMillis){
		vbuf.setColor(0);
		Font font=Font.getDefaultFont();
		parent.dlgbox.setPosition(0,200);
		int p=0,l=t.length(),j;
		while(p<l){
			parent.dlgbox.paint(vbuf);
			j=1;
			while(p+j<l&&font.substringWidth(t,p,j)<parent.scrW-12) j++;
			if(p+j>l){
				vbuf.drawString(t.substring(p,l-1),5,parent.scrH-7-font.getHeight()*2,Graphics.TOP|Graphics.LEFT);
				p=l;
			}else{
				vbuf.drawString(t.substring(p,p+j),5,parent.scrH-7-font.getHeight()*2,Graphics.TOP|Graphics.LEFT);
				p+=j;
			}
			j=1;
			while(p+j<l&&font.substringWidth(t,p,j)<parent.scrW-12) j++;
			if(p!=l){
				if(p+j>l){
					vbuf.drawString(t.substring(p,l-1),5,parent.scrH-6-font.getHeight()*1,Graphics.TOP|Graphics.LEFT);
					p=l;
				}else{
					vbuf.drawString(t.substring(p,p+j),5,parent.scrH-6-font.getHeight()*1,Graphics.TOP|Graphics.LEFT);
					p+=j;
				}
			}
			repaint();
			if(nMillis==0) return;
			parent.pause(nMillis);
		}
	}

	public void playerUpdate(Player parm1, String parm2, Object parm3) {
		if(parm2.equals(END_OF_MEDIA )){
			wait=false;
		}
	}
}

⌨️ 快捷键说明

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