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

📄 game.java

📁 自己做的一个JAVA射击小游戏!可以上真机玩的!
💻 JAVA
字号:
import java.util.Random;
import java.util.Vector;

import javax.microedition.lcdui.*;



public class Game  {
	int x=0,y=0;
    int width=30,height=32;
    Random ran=new Random();
    int num=0,numTotal;
   int[] monstery={10},monstery2=null,monstery3=null,monstery4=null,monstery5=null;
    int[] monster1x={20,40,60,80,100,120,140,160,180,200};
    int[]monster2x={20,40,60,80,100,120,140,160,180,200};
    int[]monster3x={20,40,60,80,100,120,140,160,180,200};
    int[]monster4x={20,40,60,80,100,120,140,160,180,200};
    int[]monster5x={20,40,60,80,100,120,140,160,180,200};
    int[] monsterx={83};
    AcCV ac=null;
    int[] heightx={-250,-240,-230,-210,-200};
    public static boolean play = false;
    Image plane2=null;
    Image boss=null;
    int bossx=0,bossy=0;
     public Game(AcCV ac){
    	 
    	 this.ac=ac;
    	  
    	 
    	 try
 		{   
    		 plane2=Image.createImage("/ps.png");
    		 boss=Image.createImage("/boss1.png");
 			
 		}
 		catch(Exception e)
 		{
 			System.out.println("game图片错误");
 			e.printStackTrace();
 		}
     }
    
	protected void paint(Graphics g) {
	    
	if(play=true){
		
	switch (ac.level) {
	case 1:
		
		for(int i=0;i<10;i++){
			
			g.setClip(ac.monsterx[i], ac.monstery[0], 15, 10);
			g.drawImage(plane2,ac.monsterx[i],ac.monstery[0], 0);	
		}
		
		for(int i=0;i<10;i++){
			g.setClip(ac.monsterx2[i], ac.monstery[1], 15, 10);
			g.drawImage(plane2,ac.monsterx2[i],ac.monstery[0], 0);	
		}
		for(int i=0;i<10;i++){
			g.setClip(ac.monsterx3[i],ac.monstery[2], 15, 10);
			g.drawImage(plane2,ac.monsterx3[i], ac.monstery[0], 0);	
		}
		for(int i=0;i<10;i++){
			
			g.setClip(ac.monsterx4[i],ac.monstery[3], 15, 10);
			g.drawImage(plane2,ac.monsterx4[i], ac.monstery[0], 0);
			
			}
			for(int i=0;i<10;i++){
				g.setClip(ac.monsterx5[i], ac.monstery[4], 15, 12);
				g.drawImage(plane2,ac.monsterx5[i],ac.monstery[0], 0);	
			}
			
	

		break;
    case 2:
    for(int i=0;i<10;i++){
			
			g.setClip(monster1x[i], ac.monstery[0], 15, 10);
			g.drawImage(plane2,monster1x[i],9, 0);	
		}
		
		for(int i=0;i<10;i++){
			g.setClip(monster2x[i], ac.monstery[1], 15, 10);
			g.drawImage(plane2,monster2x[i],9, 0);	
		}
		for(int i=0;i<10;i++){
			g.setClip(monster3x[i],ac.monstery[2], 15, 10);
			g.drawImage(plane2,monster3x[i],9, 0);	
		}
		for(int i=0;i<10;i++){
			
			g.setClip(monster4x[i],ac.monstery[3], 15, 10);
			g.drawImage(plane2,monster4x[i],9, 0);
			
			}
			for(int i=0;i<10;i++){
				g.setClip(monster5x[i], ac.monstery[4], 15, 12);
				g.drawImage(plane2,monster5x[i],9, 0);	
			}
		
		break;
    case 3:
    	 for(int i=10;i<20;i++){
 			   
 			g.setClip(ac.monsterx[i], ac.monstery[0], 15, 10);
 			g.drawImage(plane2,ac.monsterx[i],0, 0);	
 		}
 		
 		for(int i=10;i<20;i++){
 			g.setClip(ac.monsterx2[i], ac.monstery[1], 15, 10);
 			g.drawImage(plane2,ac.monsterx2[i],0, 0);	
 		}
 		for(int i=10;i<20;i++){
 			g.setClip(ac.monsterx3[i],ac.monstery[2], 15, 10);
 			g.drawImage(plane2,ac.monsterx3[i],0, 0);	
 		}
 		for(int i=10;i<20;i++){
 			
 			g.setClip(ac.monsterx4[i],ac.monstery[3], 15, 10);
 			g.drawImage(plane2,ac.monsterx4[i],0, 0);
 			
 			}
 			for(int i=10;i<20;i++){
 				g.setClip(ac.monsterx5[i], ac.monstery[4], 15, 12);
 				g.drawImage(plane2,ac.monsterx5[i],0, 0);	
 			}
			
		break;
    case 4:
    	g.setClip(monsterx[0], 10, 65, 50);
		g.drawImage(boss,bossx-51, ac.boss[1], 0); 
		break;
	
	}
	
		}
	}
	
	public void processEvent() 
	{   
	    
	
		recycleRes();
	  
	}
	
	public void recycleRes() 
	{  
		
		plane2=null;
		ac=null;
	}  
}

⌨️ 快捷键说明

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