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

📄 foemanager.java

📁 j2me入门游戏-雷电 游戏实现了最基本的功能比如飞机移动、产生飞机、发射子弹、击中敌方、爆炸等功能。
💻 JAVA
字号:
/********************************************************************
 * 项目名称				:<b>j2me学习</b>			<br/>
 * 
 * Copyright 2005-2006 Wuhua. All rights reserved
 ********************************************************************/
package org.wuhua.battleplan;

import java.util.Random;
import java.util.Stack;

/**
 * <b>类名:FoeManager.java</b> </br> 
 * 编写日期: 2006-12-1 <br/>
 * 程序功能描述: <br/>
 * Demo: <br/>
 * Bug: <br/>
 * 
 * 程序变更日期 :<br/> 
 * 变更作者 :<br/> 
 * 变更说明 :<br/>
 * 
 * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
 */
public class FoeManager {
	private static int index;
	
	private static int resion = 0;
 
	/**
	 * 用于保存飞机
	 */
	private static java.util.Stack foes = new Stack();
	/**
	 * 随即产生飞机
	 * @return
	 */
	public static Foe genarator(){
		//因为只有3架飞机,所以就只能这样了
		if(index == 3)
			index = 0;
		
		Foe f = new Foe(Resources.FOE[index], Platform.WIDTH/2  + resion, 0);
		
		index++;
		
		randomResion();
		return f;
		
	}



	/**
	 * 可以用比较好的算法产生飞机的位置
	 *
	 */
	private static void randomResion() {
		if(index == 0){
			resion = resion + 30;
		}else if(index == 1){
			resion = resion - 70;
		}else{
			resion = resion + 40;
			if(resion > 80)
				resion = 0;
		}
	}
	
	
	
	public static void addFoe(Foe foe){
		checkFoesIsExists();
		if(foe == null)
			return;
		foes.addElement(foe);
	}
	public static Stack getFoes(){
		return foes;
	}
	
	/**
	 * 清除无用子弹
	 *
	 */
	public static void clearFoesIsOut(){
		checkFoesIsExists();
		
		for(int i = 0; i < foes.size(); i ++){
			Foe foe = (Foe) foes.elementAt(i);
			if(foe.getX()<=0 
					||foe.getX()>=Platform.WIDTH
					|| foe.getY()>Platform.HEIGHT)
				foes.removeElement(foe);
		}
	}

	
	private static void checkFoesIsExists() {
		if(foes == null){
			throw new NullPointerException("Foes is not exists");
		}
	}

	
	
}

⌨️ 快捷键说明

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