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

📄 game.java

📁 thq 发布的《worms》 motorola 源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

import java.util.Random;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class Game extends Canvas implements CommandListener {

	public static int screenWidth = 176;

	public static int screenHeight = 183;

	/*
	 * public static Player sound_THEMETUNE;
	 * 
	 * public static Player sound_EXPLOSION;
	 * 
	 * public static Player sound_VICTORY;
	 * 
	 * public static Player sound_BYEBYE;
	 */

	public static Sound sound;

	public static int currentWormActiveWeapon = 0;

	public static int currentWormAmmoCount = 0;

	private int tag_cx;

	private int tag_cy;

	private int tag_cw;

	private int tag_ch;

	private boolean running;

	private int state;

	private static final int GAME = 0;

	private static final int RED_TEAM = 0;

	private static final int BLUE_TEAM = 1;

	public static int curFrame;

	private boolean initialized;

	private Landscape landscape;

	private ParticleSystem particleSystem;

	protected Team teams[];

	private int activeTeam;

	private Random random;

	public static Imp windIconRed;

	public static Imp windIconBlue;

	public static int windFactor;

	public static Imp water;

	private int cloudStartX[];

	private int cloudX[];

	private int cloudY[];

	public static Imp cloud;

	private Image windIndicatorI;

	private Graphics windIndicatorG;

	protected int timeLeft;

	protected boolean endTurn;

	private long endTurnTime;

	private boolean endTurnPause;

	public long LastGetTime;

	public static Imp icons;

	public static Imp surrender;

	private int surrenderFrame;

	private int surrenderFrameDirection;

	public static Imp player;

	private int keypressed;

	private long startTurnTime;

	public static boolean paused;

	private int pauseMenuItem;

	public static int pauseLostTeam;

	private boolean isShown;

	int counter;

	public static int OPAQUE = 0;

	public static int ALPHA = 15;
	
	//public static boolean isPlay = true;//返回或暂停时是否播放背景音

	public static short vectorTable[] = { 0, 23040, 23040, 23040, 23040, 23040,
			23040, 23040, 23040, 23040, 23040, 23040, 23040, 23040, 23040,
			23040, 23040, 23040, 23040, 23040, 0, 11520, 16239, 18321, 19447,
			20145, 20618, 20959, 21216, 21417, 21578, 21710, 21821, 21914,
			21994, 22064, 22124, 22178, 22226, 22269, 0, 6801, 11520, 14415,
			16239, 17459, 18321, 18958, 19447, 19833, 20145, 20402, 20618,
			20801, 20959, 21096, 21216, 21322, 21417, 21502, 0, 4719, 8625,
			11520, 13601, 15113, 16239, 17101, 17778, 18321, 18765, 19135,
			19447, 19713, 19944, 20145, 20321, 20478, 20618, 20743, 0, 3593,
			6801, 9439, 11520, 13143, 14415, 15425, 16239, 16906, 17459, 17924,
			18321, 18662, 18958, 19218, 19447, 19650, 19833, 19997, 0, 2895,
			5581, 7927, 9897, 11520, 12850, 13942, 14847, 15602, 16239, 16782,
			17249, 17654, 18009, 18321, 18597, 18844, 19066, 19266, 0, 2422,
			4719, 6801, 8625, 10190, 11520, 12646, 13601, 14415, 15113, 15716,
			16239, 16698, 17101, 17459, 17778, 18063, 18321, 18553, 0, 2081,
			4082, 5939, 7615, 9098, 10394, 11520, 12496, 13344, 14082, 14727,
			15294, 15795, 16239, 16636, 16991, 17311, 17600, 17862, 0, 1824,
			3593, 5262, 6801, 8193, 9439, 10544, 11520, 12382, 13143, 13817,
			14415, 14948, 15425, 15853, 16239, 16589, 16906, 17195, 0, 1623,
			3207, 4719, 6134, 7438, 8625, 9696, 10658, 11520, 12291, 12982,
			13601, 14158, 14660, 15113, 15524, 15898, 16239, 16551, 0, 1462,
			2895, 4275, 5581, 6801, 7927, 8958, 9897, 10749, 11520, 12218,
			12850, 13422, 13942, 14415, 14847, 15241, 15602, 15934, 0, 1330,
			2638, 3905, 5116, 6258, 7324, 8313, 9223, 10058, 10822, 11520,
			12157, 12739, 13272, 13759, 14206, 14616, 14994, 15342, 0, 1219,
			2422, 3593, 4719, 5791, 6801, 7746, 8625, 9439, 10190, 10883,
			11520, 12106, 12646, 13143, 13601, 14024, 14415, 14777, 0, 1126,
			2239, 3327, 4378, 5386, 6342, 7245, 8092, 8882, 9618, 10301, 10934,
			11520, 12063, 12566, 13032, 13464, 13866, 14239, 0, 1046, 2081,
			3096, 4082, 5031, 5939, 6801, 7615, 8380, 9098, 9768, 10394, 10977,
			11520, 12026, 12496, 12935, 13344, 13726, 0, 976, 1944, 2895, 3822,
			4719, 5581, 6404, 7187, 7927, 8625, 9281, 9897, 10474, 11014,
			11520, 11993, 12436, 12850, 13238, 0, 916, 1824, 2719, 3593, 4443,
			5262, 6049, 6801, 7516, 8193, 8834, 9439, 10008, 10544, 11047,
			11520, 11964, 12382, 12774, 0, 862, 1718, 2562, 3390, 4196, 4977,
			5729, 6451, 7142, 7799, 8424, 9016, 9576, 10105, 10604, 11076,
			11520, 11939, 12334, 0, 814, 1623, 2422, 3207, 3974, 4719, 5440,
			6134, 6801, 7438, 8046, 8625, 9174, 9696, 10190, 10658, 11101,
			11520, 11916, 0, 771, 1538, 2297, 3043, 3774, 4487, 5178, 5845,
			6489, 7106, 7698, 8263, 8801, 9314, 9802, 10266, 10706, 11124,
			11520 };

	public static short table[] = { 0, 4, 8, 13, 17, 22, 26, 31, 35, 39, 44,
			48, 53, 57, 61, 65, 70, 74, 78, 83, 87, 91, 95, 99, 103, 107, 111,
			115, 119, 123, 127, 131, 135, 138, 142, 146, 149, 153, 156, 160,
			163, 167, 170, 173, 177, 180, 183, 186, 189, 192, 195, 198, 200,
			203, 206, 208, 211, 213, 216, 218, 220, 223, 225, 227, 229, 231,
			232, 234, 236, 238, 239, 241, 242, 243, 245, 246, 247, 248, 249,
			250, 251, 251, 252, 253, 253, 254, 254, 254, 254, 254, 255, 254,
			254, 254, 254, 254, 253, 253, 252, 251, 251, 250, 249, 248, 247,
			246, 245, 243, 242, 241, 239, 238, 236, 234, 232, 231, 229, 227,
			225, 223, 220, 218, 216, 213, 211, 208, 206, 203, 200, 198, 195,
			192, 189, 186, 183, 180, 177, 173, 170, 167, 163, 160, 156, 153,
			149, 146, 142, 138, 135, 131, 127, 123, 119, 115, 111, 107, 103,
			99, 95, 91, 87, 83, 78, 74, 70, 65, 61, 57, 53, 48, 44, 39, 35, 31,
			26, 22, 17, 13, 8, 4, 0, -4, -8, -13, -17, -22, -26, -31, -35, -39,
			-44, -48, -53, -57, -61, -65, -70, -74, -78, -83, -87, -91, -95,
			-99, -103, -107, -111, -115, -119, -123, -127, -131, -135, -138,
			-142, -146, -149, -153, -156, -160, -163, -167, -170, -173, -177,
			-180, -183, -186, -189, -192, -195, -198, -200, -203, -206, -208,
			-211, -213, -216, -218, -220, -223, -225, -227, -229, -231, -232,
			-234, -236, -238, -239, -241, -242, -243, -245, -246, -247, -248,
			-249, -250, -251, -251, -252, -253, -253, -254, -254, -254, -254,
			-254, -255, -254, -254, -254, -254, -254, -253, -253, -252, -251,
			-251, -250, -249, -248, -247, -246, -245, -243, -242, -241, -239,
			-238, -236, -234, -232, -231, -229, -227, -225, -223, -220, -218,
			-216, -213, -211, -208, -206, -203, -200, -198, -195, -192, -189,
			-186, -183, -180, -177, -173, -170, -167, -163, -160, -156, -153,
			-149, -146, -142, -138, -135, -131, -127, -123, -119, -115, -111,
			-107, -103, -99, -95, -91, -87, -83, -78, -74, -70, -65, -61, -57,
			-53, -48, -44, -39, -35, -31, -26, -22, -17, -13, -8, -4 };

	private Command GX10Command_LEFT;

	private Command GX10Command_RIGHT;

	private Command GX10Command_BACK = new Command("返回", 4, 1);;

	//新加
	int runCount = 0;
	//
	int[][] run = { { 1, -2, 61 }, { 0, -1, 65 }, { 1, -1, 85 },
			{ 0, -1, 95 }, { 1, -5, 117 }, { 0, -5, 171 }, { 1, -1, 399 },
			{ 0, -1, 403 }, { 1, -5, 439 }, { 0, -5, 485 },{1,-4,641},{0,-4,717},
			{1,-3,741},{0,-3,747},{1,-2,795},{0,-2,801},{1,-1,825},{0,-1,833},
			{1,-5,861},{0,-5,921},{1,-2,1131},{0,-2,1135},{1,-1,1161},{0,-1,1167},
			{1,-5,1185},{0,-5,1231},{1,-2,1417},{0,-2,1421},{1,-1,1451},{0,-1,1457},
			{1,-5,1477},{0,-5,1525},{1,-1,1769},{0,-1,1775},{1,-5,1817},{0,-5,1867},
			{1,-2,2117},{0,-2,2123},{1,-5,2163},{0,-5,2217}};

	static boolean press = false;

	Font font = null;

	public Game() {
		//isPlay = true;
		font = Font.getDefaultFont();
		initialized = false;
		teams = new Team[2];
		activeTeam = 0;
		random = new Random();
		pauseMenuItem = 0;
		counter = 1;
		cloudX = new int[3];
		cloudStartX = new int[cloudX.length];
		cloudY = new int[cloudX.length];
		for (int i = 0; i < cloudX.length; i++) {
			cloudStartX[i] = Math.abs(random.nextInt()) % 300;
			cloudY[i] = -25 + Math.abs(random.nextInt()) % 40;
		}

		windIndicatorI = Image.createImage(30, 6);
		landscape = new Landscape();
		int j = 0;
		teams[j] = new Team(true, j, 2);
		teams[j ^ 0x1] = new Team(false, j ^ 0x1, 2);
		Weapon.init();
	}

	public void keyReleased(int i) {
		if (press) {
			//System.out.println("====keyReleased===j==" + i);
			//System.out.println("======keyPressed===runCount=" + runCount);
			//System.out.println("======keyPressed===cha="+(runCount-startRun));
			if (Weapon.isActive())
				return;
			if (!Weapon.isActive() && !paused)
				teams[activeTeam].keyReleased(i);
		}
	}

	public void keyPressed(int i) {
		if (press) {
			System.out.println("===game=====keyPressed===i==" + i);
			//System.out.println("======keyPressed===runCount=" + runCount);
			//System.out.println("======keyPressed===cha="+(runCount-startRun));
			keypressed = i;
			if (Worms.checkKey(i, Worms.KEY_RIGHT_SOFTKEY)) {
				System.out.println("==game====keyPressed===KEY_RIGHT_SOFTKEY====");
				//isPlay = false;
				paused = true;
				running = false;
				Worms.loadTimes = 1;
				pauseLostTeam = -2;
				Worms.pauseStartTime = Worms.getTime();
				//System.out.println("===Worms.pauseStartTime==="+Worms.pauseStartTime);
				return;
			}
			/*
			 * if(paused) { System.out.println("===keyPressed===191====");
			 * if(Worms.checkKey(i, Worms.KEY_ENTER) || Worms.checkKey(i,
			 * Worms.KEY_LEFT_SOFTKEY)) {
			 * System.out.println("===keyPressed===194===="); if(pauseMenuItem ==
			 * 0) { System.out.println("===keyPressed===197===="); running =
			 * false; if(teams[activeTeam].getActiveWorm().redTeam)
			 * pauseLostTeam = 1; else pauseLostTeam = 0; } if(pauseMenuItem ==
			 * 1) { System.out.println("===keyPressed===206===="); paused =
			 * false; Worms.pauseDeltaTime += Worms.getTime() -
			 * Worms.pauseStartTime; } } if(Worms.checkKey(i, Worms.KEY_RIGHT) &&
			 * pauseMenuItem < 1){
			 * System.out.println("===keyPressed===212===="); pauseMenuItem++; }
			 * if(Worms.checkKey(i, Worms.KEY_LEFT) && pauseMenuItem > 0) {
			 * System.out.println("===keyPressed===216===="); pauseMenuItem--; }
			 * return; }
			 */
			//System.out.println("===game===Weapon.state===294===="+Weapon.s);
			if (Weapon.isActive()) {
				System.out.println("===game===keyPressed===295====");
				return;
			}
			if (!paused && teams[activeTeam].humanTeam && !endTurn) {
				System.out.println("===game===keyPressed===299====");
				teams[activeTeam].keyPressed(i);
			}
		}
	}

	public void endTurn(boolean flag) {
		if (!endTurn) {
			endTurnPause = flag;
			endTurn = true;
			endTurnTime = -1L;
		}
	}

	public void reset(boolean flag) {
		initialized = false;
		pauseLostTeam = -1;
		pauseMenuItem = 1;
		paused = false;
		landscape.generate(teams);
		particleSystem = new ParticleSystem(landscape);
		endTurn = false;
		teams[0].reset(this, landscape, flag);
		teams[1].reset(this, landscape, true);
		activeTeam = Math.abs(random.nextInt()) % teams.length;
		teams[activeTeam].activateNextWorm();
		windFactor = Math.abs(random.nextInt()) % 512 - 256;
		particleSystem.setWind(windFactor);
		Weapon.reset();
		setCommandListener(this);
		if (Worms.runTimes == 0) {
			System.out.println("===reset==command==1===");
			this.removeCommand(GX10Command_LEFT);
			this.removeCommand(GX10Command_RIGHT);
			this.addCommand(GX10Command_BACK);
		} else {
			System.out.println("===reset==command===2==");	
			this.removeCommand(GX10Command_BACK);
			addGX10Softkeys(Menu.softkeyLabelWeapon, "暂停");
		}
	}

	/*
	 * public static void vibrationON() { //
	 * DeviceControl.getDefaultDeviceControl().setDeviceActive(4, // true);//yue
	 * add 1 }
	 * 
	 * public static void vibrationOFF() { //
	 * DeviceControl.getDefaultDeviceControl().setDeviceActive(4, //
	 * false);//yue add 1 }
	 */

	int m = 0;

	public void run() {

		state = 0;
		running = true;

		//if (Menu.soundEnabled())
		//sound_THEMETUNE.stop();

		Worms.WormsDisplay.setCurrent(this);
		//        DeviceControl.getDefaultDeviceControl().setDeviceActive(5,
		// true);//yue add 1
		if (Worms.loadTimes == 0) {
			startTurnTime = Worms.getTime();
			LastGetTime = startTurnTime;
			isShown = true;
		} else {
			//        	Worms.pauseDeltaTime += Worms.getTime() - Worms.pauseStartTime;
			//Worms.loadTimes = 0;
//			this.removeCommand(GX10Command_BACK);
//			this.addCommand(GX10Command_LEFT);
//			this.addCommand(GX10Command_RIGHT);		
			pauseLostTeam = -1;
			paused = false;
			Worms.loadTimes = 0;

⌨️ 快捷键说明

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