Java自己做的小游戏

源代码在线查看: prop.java

软件大小: 1443 K
上传用户: stone825
关键词: Java 小游戏
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.util.Random;
				import javax.microedition.lcdui.Graphics;
				import javax.microedition.lcdui.Image;
				public class prop //道具类
				{
					Random Rd=new Random();//产生随机数
					Image propImg=null;
					int propNum=6;//道具数量
					int which=4;//哪个道具 //0:增加球移动速度 1:减慢球移动速度 2:增加挡板长度 3:减小挡板长度 4:火焰球 5:生命
					int propW=10;//道具宽
					int propH=10;//道具高
					int speed=2;
					int propX=0;
					int propY=0;
					int rd=0;//随机数
					prop(brick Brick) 
					{
						rd=Rd.nextInt(100);
						try
						{
							propImg=Image.createImage("/propImg.png");
						}
						catch(Exception e)
						{
							System.out.println("prop 道具类图片错误");
							e.printStackTrace();
						}
						speed=Rd.nextInt(3)+1;
						if(rd>=0&&rd						{
							which=5;
						}
						else if(rd>10&&rd						{
							which=1;
						}
						else if(rd>20&&rd						{
							which=2;
						}
						else if(rd>30&&rd						{
							which=4;
						}
						else if(rd>40&&rd						{
							which=0;
						}
						else
						{
							which=3;
						}
						propX=Brick.brickX+(Brick.brickW-propW)/2-which*propW;
						propY=Brick.brickY;
					}
					public void paint(Graphics g)
					{
						g.setClip(propX+which*propW, propY, propW, propH);
						g.drawImage(propImg, propX, propY, 0);
					}
					public void move(player p)
					{
						propY+=speed;
						if(propX+which*propW>p.playerX-propW&&propX+which*propWp.playerY)
						{
							result();
							propY+=100;
						}
					}
					public void result()//效果
					{
						switch(which)
						{
						case 0://0:增加球移动速度
							if(ball.xSpeed							{
								ball.xSpeed+=ball.xSpeed/Math.abs(ball.xSpeed);
								ball.ySpeed+=ball.ySpeed/Math.abs(ball.ySpeed);
							}
							break;
						case 1://1:减慢球移动速度
							if(ball.ySpeed>1)
							{
								ball.xSpeed-=ball.xSpeed/Math.abs(ball.xSpeed);
								ball.ySpeed-=ball.ySpeed/Math.abs(ball.ySpeed);
							}
							break;
						case 2://2:增加挡板长度等级
							if(player.playerLv								player.playerLv++;
							break;
						case 3:// 3:减小挡板长度等级
							if(player.playerLv>1)
								player.playerLv--;
							break;
						case 4:// 4:火焰球
							ball.which=2;
							break;
						case 5://生命
							if(player.life							player.life++;
							else player.fraction+=66;
							break;
						}
					}
					public void recycleRes() 
					{
						propImg=null;
					}
				}			

相关资源