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

📄 gamefigh.java

📁 个人开发的第一个手机RPG游戏
💻 JAVA
字号:
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;

public class GameFigh extends GameFrame 
{
	GameView gv;
	static boolean act=true;
	static int count=0;
	static int herored=25;
	static int enemyred=25;
	Font f;
	
	
	
	public GameFigh(GameView gv)
	{
		this.gv=gv;
	}
	

	
		public void cf()
		{
			
			int mapdata3[][]={
				{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 16, 1, 16, 1, 16, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 1, 1, 1, 1, 1, 1, 1, 1, 10 },
				{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }
				};
		
		for(int i=0;i<14;i++)
			for(int j=0;j<10;j++)
			{
				gv.mapf.setCell(j, i,mapdata3[i][j] );
			}
			
		}
		
		public void draw()
		{
			
			int x=100,y=220;
			
			gv.g.setColor(0xffffff);
			gv.g.fillRect(0, 0, gv.getWidth(), gv.getHeight());
			gv.enemy.setRefPixelPosition(Enemy.x, Enemy.y);
			
			gv.hero.nextFrame();
			gv.hero.setPosition(x, y);
			
			gv.lm2.paint(gv.g, 0, 0);
			gv.g.setColor(0x8b0000);
			gv.g.fillRect(x, y-5, herored,6 );
			gv.g.setColor(0x8b0000);
			gv.g.fillRect(Enemy.x, Enemy.y-5, enemyred,6 );
       
			gv.flushGraphics();
		} 
		public void keyevent()
		{
			int keycode;
			keycode=gv.getKeyStates();
			if((keycode&gv.UP_PRESSED)!=0)
			{
				if(GameView.lg==false)
				{
					GameLogo.cg=8;
					Enemy.hp=Enemy.hp-Hero.at;
					GameFigh.enemyred=GameFigh.enemyred/2;
					GameFigh.act=false;
					
					
				}
				else
				{
					GameLogo.cg=7;
					
				}
				
			}
			else if((keycode&gv.DOWN_PRESSED)!=0)
			{
				if(GameView.lg==false)
				{
					GameView.lg=true;
				}
				else
				{
					GameLogo.cg=7;
					
				}
				
				
			}
			else if((keycode&gv.LEFT_PRESSED)!=0)
			{
				
				
			}
			else if((keycode&gv.RIGHT_PRESSED)!=0)
			{
				
				
			}
			else if((keycode&gv.FIRE_PRESSED)!=0)
			{
				if(GameView.lg==false)
				{
					if(Hero.mp!=0)
					{
						GameLogo.cg=9;
						Enemy.hp=Enemy.hp-500;
						GameFigh.enemyred=0;
						
						GameFigh.act=false;
						Hero.mp--;
					}
					
					
				}
				else
				{
					GameLogo.cg=7;
					
				}
				
					
				
			}
			
			
		}
		public void draw2()
		{
		
			
				int x1=110,x2=105,x3=115,y1=210,y2=215,y3=215;
				
				gv.g.setColor(0xff0000);
				while(y1>130)
				{
					gv.g.fillTriangle(x1, y1-=2, x2, y2-=2, x3, y3-=2);
					gv.flushGraphics();
				}
				
					GameLogo.cg=1;
				
	
		} 
		public void draw3()
		{
			
			int x1=110,x2=105,x3=115,y1=210,y2=215,y3=215;
			int xx1=90,xx2=85,xx3=95,yy1=210,yy2=215,yy3=215;
			int xxx1=120,xxx2=125,xxx3=130,yyy1=210,yyy2=215,yyy3=215;
			
			gv.g.setColor(0xff0000);
			while(y1>130)
			{
				gv.g.fillTriangle(x1, y1-=2, x2, y2-=2, x3, y3-=2);
				gv.g.fillTriangle(xx1, yy1-=2, xx2, yy2-=2, xx3, yy3-=2);
				gv.g.fillTriangle(xxx1, yyy1-=2, xxx2, yyy2-=2, xxx3, yyy3-=2);
				gv.flushGraphics();
			}
			
				GameLogo.cg=1;
			
			
		}
		/*int b2=90;
		public void draw4()
		{
			
			gv.g.setColor(0xffffff);
			gv.g.fillRect(0, 0, 100, 100);
			f=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_LARGE);
			gv.g.setFont(f);
			gv.g.setColor(0);
			gv.g.drawString("敌人进攻", 0,b2-=2 , Graphics.BOTTOM|Graphics.HCENTER);
			if(b2<0)
				{
				GameLogo.cg=1;
				
				}
			
			gv.flushGraphics();
		}*/
		
		
		public void enemyattact()
		{
			if(!act)
			{
				
				Hero.hp=Hero.hp-Enemy.at;
				herored=(3*herored)/4;
				act=true;
				
			}
			
		}
		public void define()
		{
			
			if(Enemy.hp<=0)
				
				{
				GameView.lg=true;
				Enemy.hp=500;
				enemyred=25;
				count++;
				
				}
			
		         
			 if(Hero.hp<=0)
			{
				// gv.lm2.insert(gv.gameover, 2);
			       gv.lm2.remove(gv.hero);
				   gv.lm2.remove(gv.enemy);
				    gv.lm2.remove(gv.mapf);
				    gv.lm2.append(gv.gameover);
			}
		
		}
		public void shengji()
		{
			switch(count)
			{
			case 3: Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			case 8: Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			case 14:Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			case 25:Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			case 45:Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			case 80:Hero.sp++;Hero.hp+=200;Hero.mp+=2;herored=25;break;
			
			}
			
		}
		


}

⌨️ 快捷键说明

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