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

📄 thunderboltact.java

📁 java的一个源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package thunder.bolt;

import java.util.*;
import javax.microedition.lcdui.*;

public class ThunderBoltAct extends Canvas implements Runnable {
	private int TIMEOUT = 0;
	private final static int NUMERIC = 10000;         //总分
	private final static int INERRGAL = 60;          //频率
	private final static int MAXBATTLE = 3;           //最大飞机数
	private final static int MAXBALLNUM = 30;         //最多飞机子弹数
	private final static int MAXCOPTERNUM = 16;       //最大敌机数
	private final static int MAXCOPTERBALLNUM = 16;   //最多敌机子弹数
	private final static int STEP = 1;
	private final static int MINCOPTER = 2;           //最小敌机数
	
	private int kill_poing = 0;                       //打掉敌机数
	private int killAll = 5;
	private int battacount = 5;
	private int speed = 0;
	
	private int[][] ballpos;
	private int[][] copterpos;
	private int[][] bombpos;
	private int[][] copterballpos;
	private int[] coptercort;
	private int[] copterballcort;
	private int[] bombcort;	
	
	private int ballnum = 0;
	private int copternum = 0;
	private int bombnum = 0;
	private int copterballnum = 0;
	private int battarray = 0;
	private int mapposx = 0;
	private int mapposy = -100;
	
	private int screenw = 100;
    private int screenh = 100;
    private int battposx = (int)(screenw/2);
    private int battposy = 85;
    private int math = 0;
    private int romdan = 90;
	
	private Thread thread;
	private Random random;
	private Image mapImage;
	private Image copterI;
	private Image[] battleI = new Image[3];
	private Image battle_slugI;	
	private Image copter_slugI;
	private Image bombI;
	private Image bullI;
	private Image off_screen_buffer;
	private Graphics off_screen;

	
	private boolean die = true;
	private boolean up    = false,
	                down  = false,
	                left  = false,
	                right = false;
	
	public ThunderBoltAct() {
		inportImage();
        init();
        thread = new Thread(this);
        thread.start();
	}
	
	public void run() {
		while(true) {			
			try {
				this.TIMEOUT ++;
				if((isDie())&&(this.battacount > 0)&&(this.TIMEOUT<10001)) {
				    move();				    
				    repaint();
				    //System.out.print(TIMEOUT+"\n");
				}
				Thread.sleep((int)(INERRGAL-speed*25));
			}catch(InterruptedException e) { }
		}			
	}

	public void setDestroy() {
			thread = null;
	}
	
	public void setDie(boolean die) {
		this.die = die;
	}
	
	public boolean isDie() {
		return this.die;
	}
	
	protected void keyPressed(int keyCode) {
        int action = getGameAction(keyCode);
        switch(action) {
        	case UP:
        	  this.up = true;
        	  break;
        	case DOWN:
        	  this.down = true;
        	  break;
        	case LEFT:
        	  this.left = true;
        	  break;
        	case RIGHT:
        	  this.right = true;
        	  break;
        	case FIRE:
        	  sendSulg(battposx,battposy);
        	  break;
        }
        switch(keyCode) {
        	case 50:
        	  this.up = true;
        	  break;
        	case 56:
        	  this.down = true;
        	  break;
        	case 52:
        	  this.left = true;
        	  break;
        	case 54:
        	  this.right = true;
        	  break;
        	case 53:
        	  sendSulg(battposx,battposy);
        	  break;
        	case 35:
        	  killAllCopter();
        	  break;
        }
    }
    
    protected void keyReleased(int keyCode) {
        int action = getGameAction(keyCode);
        switch(action) {
        	case UP:
        	  this.up = false;
        	  break;
        	case DOWN:
        	  this.down = false;
        	  break;
        	case LEFT:
        	  this.left = false;
        	  break;
        	case RIGHT:
        	  this.right = false;
        	  break;
        	case FIRE:
        	  break;
        }
        switch(keyCode) {
        	case 50:
        	  this.up = false;
        	  break;
        	case 56:
        	  this.down = false;
        	  break;
        	case 52:
        	  this.left = false;
        	  break;
        	case 54:
        	  this.right = false;
        	  break;
        	case 53:
        	  break;
        }
    }
    
	private void init() {
		this.screenw=getWidth();
	  	this.screenh=getHeight();
	  	this.random = new Random();
	  	this.off_screen_buffer = Image.createImage(this.screenw,this.screenh);
	  	this.off_screen = this.off_screen_buffer.getGraphics();
	  	this.ballpos        = new int[MAXBALLNUM][2];
	    this.copterpos      = new int[MAXCOPTERNUM][2];
	    this.bombpos        = new int[MAXCOPTERNUM][2];
	    this.copterballpos  = new int[MAXCOPTERBALLNUM][2];
	    this.coptercort     = new int[MAXCOPTERNUM];
	    this.copterballcort = new int[MAXCOPTERBALLNUM];
	    this.bombcort       = new int[MAXCOPTERNUM];
	}
	
	public void paint(Graphics g) {
		draw_Image();
		g.drawImage(off_screen_buffer,0,0,Graphics.LEFT|Graphics.TOP);
	}
	
	private void draw_Image() {
		off_screen.drawImage(mapImage,0,mapposx,Graphics.LEFT|Graphics.TOP);
		off_screen.drawImage(mapImage,0,mapposy,Graphics.LEFT|Graphics.TOP);
		for(int i=0;i<bombnum;i++) {
    	    off_screen.drawImage(bombI,bombpos[i][0],bombpos[i][1],Graphics.LEFT|Graphics.TOP);
    	}
    	for(int i=0;i<ballnum;i++) {
    	    off_screen.drawImage(battle_slugI,ballpos[i][0],ballpos[i][1],Graphics.LEFT|Graphics.TOP);
    	}
    	for(int i=0;i<copternum;i++) {
    	    off_screen.drawImage(copterI,copterpos[i][0],copterpos[i][1],Graphics.LEFT|Graphics.TOP);
    	}
    	for(int i=0;i<copterballnum;i++) {
    	    off_screen.drawImage(copter_slugI,copterballpos[i][0],copterballpos[i][1],Graphics.LEFT|Graphics.TOP);
    	}    	
    	
    	off_screen.drawImage(battleI[battarray],battposx,battposy,Graphics.LEFT|Graphics.TOP);
    	for(int i = 0; i < battacount; i ++) {
    	    off_screen.drawImage(bullI,(int)(i*5+1),2,Graphics.LEFT|Graphics.TOP);
        }
        off_screen.setColor(255,255,0);
        if(TIMEOUT >= 10000) {
    	    off_screen.drawString("这是测试版!",5,40,Graphics.LEFT|Graphics.TOP);
        }  
        if(battacount < 1) {
    	    off_screen.drawString("The Game Over!",5,40,Graphics.LEFT|Graphics.TOP);
        }        
    	off_screen.setFont(Font.getFont(64,2,8));
    	off_screen.drawString(kill_poing+"",80,0,Graphics.LEFT|Graphics.TOP);
	}
	
	private void move() {
		mapmove();
		copterEnemy();
		copterSulg();
		battlePlan();
		battSulg();
		bomb();
	}
	
	private void inportImage() {
		try {
			 mapImage        =  Image.createImage("/icons/map_1.png");
		 	 copterI         =  Image.createImage("/icons/enemy.png");
			 battleI[0]      =  Image.createImage("/icons/bullet_1.png");
			 battleI[2]      =  Image.createImage("/icons/bullet_left_1.png");
			 battleI[1]      =  Image.createImage("/icons/bullet_right_1.png");
			 battle_slugI    =  Image.createImage("/icons/bullet_ball.png");	
			 copter_slugI    =  Image.createImage("/icons/enemy_ball.png");
			 bombI           =  Image.createImage("/icons/bomb.png");
			 bullI           =  Image.createImage("/icons/bullet.png");
		}catch(java.io.IOException e) {}
	}
	    
    //背景图片移动
    private void mapmove() {
    	mapposx += this.STEP;
    	if(mapposx > this.screenh) mapposx = -100;
    	mapposy += this.STEP;
    	if(mapposy > this.screenh) mapposy = -100;
    }
    
    //我机移动
    private void battlePlan() {
    	if(this.up) {
    		this.battarray = 0;
			this.battposy -= (int)(this.STEP*4);
			if(this.battposy < 5) this.battposy = 5;
		}else
		if(this.down) {
			this.battarray = 0;
			this.battposy += (int)(this.STEP*4);
			if(this.battposy > (this.screenh-10)) this.battposy = (this.screenh-10);
		}else
		if(this.left) {
			this.battarray = 1;

⌨️ 快捷键说明

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