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

📄 leadingplanemenu.java

📁 一个J2ME的游戏,有源程序.是原创!适合S60的176*208的规格.
💻 JAVA
字号:
package src;

import java.io.IOException;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class LeadingPlaneMenu {

	KingCanvas KC;

	static Image LeadingPlane, MenuPhoto, SmallLeadingPlane1,
			SmallLeadingPlane2, SmallLeadingPlane3, SmallLeadingPlane1Icon,
			SmallLeadingPlane2Icon, SmallLeadingPlane3Icon;

	int LeadingPlaneNumber;

	boolean timeCounterInit;

	int MenuState;

	int timeCounter, ColorCounter;

	int temp, windtemp;

	int LeadingPlane_X, LeadingPlane_Y, SmallLeadingPlane_X,
			SmallLeadingPlane_Y, LeadingPlaneFrame_X, LeadingPlaneFrame_Y;

	public LeadingPlaneMenu(KingCanvas KC) {
		this.KC = KC;
		InitMenu();
	}

	/**
	 * 初始化主角飞机选择菜单相关属性及相关图片加载处理方法
	 */

	public void InitMenu() {
		LeadingPlane_X = 45;
		LeadingPlane_Y = 60;
		SmallLeadingPlane_X = 25;
		SmallLeadingPlane_Y = 165;
		LeadingPlaneFrame_X = 21;
		LeadingPlaneFrame_Y = 160;
		timeCounter = 100;
		try {
			LeadingPlane = Image.createImage("/res/picture/Menu1.png");
			MenuPhoto = Image.createImage("/res/picture/Menu3.png");
			SmallLeadingPlane1 = Image.createImage("/res/picture/Plane_1.png");
			SmallLeadingPlane2 = Image.createImage("/res/picture/Plane_2.png");
			SmallLeadingPlane3 = Image.createImage("/res/picture/Plane_3.png");
			SmallLeadingPlane1Icon = Image
					.createImage("/res/picture/PlaneIcon_1.png");
			SmallLeadingPlane2Icon = Image
					.createImage("/res/picture/PlaneIcon_2.png");
			SmallLeadingPlane3Icon = Image
					.createImage("/res/picture/PlaneIcon_3.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 主角飞机选择菜单键控处理方法
	 */

	public void MenuKeyOption() {
		switch (KC.keyCode) {
		case KingCanvas.KB_LEFT:
			if (LeadingPlaneFrame_X > 21) {
				LeadingPlaneFrame_X -= 51;
				MenuState--;
			} else {
				LeadingPlaneFrame_X = 123;
				MenuState = 2;
			}
			timeCounter = 0;
			KC.keyCode = KingCanvas.KB_NONE;
			break;
		case KingCanvas.KB_RIGHT:
			if (LeadingPlaneFrame_X < 123) {
				LeadingPlaneFrame_X += 51;
				MenuState++;
			} else {
				LeadingPlaneFrame_X = 21;
				MenuState = 0;
			}
			timeCounter = 0;
			KC.keyCode = KingCanvas.KB_NONE;
			break;
		case KingCanvas.KB_CENTER:
			switch (MenuState) {
			case 0:
				KingCanvas.imageLeadingPlane = SmallLeadingPlane1;
				KingCanvas.imageLeadingPlaneIcon = SmallLeadingPlane1Icon;
				KingCanvas.LeadingPlaneType = 0;
				KC.Stem = 4;
				windtemp = 4;
				break;
			case 1:
				KingCanvas.imageLeadingPlane = SmallLeadingPlane2;
				KingCanvas.imageLeadingPlaneIcon = SmallLeadingPlane2Icon;
				KingCanvas.LeadingPlaneType = 1;
				KC.Stem = 2;
				windtemp = 2;
				break;
			case 2:
				KingCanvas.imageLeadingPlane = SmallLeadingPlane3;
				KingCanvas.imageLeadingPlaneIcon = SmallLeadingPlane3Icon;
				KingCanvas.LeadingPlaneType = 2;
				KC.Stem = 6;
				windtemp = 6;
				break;

			}
			KC.BulletsPowerCounter = 0;
			if (KC.bFlagMusic == true) {
				KC.isMusic = false;
			} else {
				KC.isMusic = true;
				KC.MusicTest = 0;
			}
			KingCanvas.LoadplayImage();
			LeadingPlane = null;
			MenuPhoto = null;
			SmallLeadingPlane1 = null;
			SmallLeadingPlane2 = null;
			SmallLeadingPlane3 = null;
			SmallLeadingPlane1Icon = null;
			SmallLeadingPlane2Icon = null;
			SmallLeadingPlane3Icon = null;
			KC.gameState = KingCanvas.GS_PLAY;
			KC.keyCode = KingCanvas.KB_NONE;
			break;
		}
	}

	/**
	 * 主角飞机选择菜单状态处理方法
	 */

	public void MenuState() {
		switch (MenuState) {
		case 0:
			LeadingPlaneNumber = 0;
			KC.Music = "/res/audio/forest1.mid";
			break;
		case 1:
			LeadingPlaneNumber = 1;
			KC.Music = "/res/audio/gwg-modesel.mid";
			break;
		case 2:
			LeadingPlaneNumber = 2;
			KC.Music = "/res/audio/EXE1EnemyDeleted.mid";
			break;
		}
	}

	// -------------------------------------- 画笔

	/**
	 * 主角飞机选择菜单状态画笔
	 */

	public void drawMenuState(Graphics g) {
		g.setColor(255, 255, 255);
		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_SMALL));
		g.drawString("攻", 85, 10, 0);
		g.drawString("防", 85, 20, 0);
		g.drawString("移", 85, 30, 0);
		g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
				Font.SIZE_LARGE));
		switch (MenuState) {
		case 0:
			g.setColor(255, 255, 255);
			g.drawString(" P - 4 7 ", 5, 10, 0);
			if (temp == 2) {
				if (timeCounter <= 20) {
					timeCounter += 2;
					g.setColor(255, 255, 255);
					g.fillRect(100, 14, 20 + timeCounter, 5);
					g.setColor(255, 0, 0);
					g.fillRect(102, 15, 16 + timeCounter, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 24, 40, 5);
					g.setColor(0, 0, 255);
					g.fillRect(102, 25, 36, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 34, 60 - timeCounter, 5);
					g.setColor(0, 255, 0);
					g.fillRect(102, 35, 56 - timeCounter, 3);
				} else {
					drawP47(g);
					temp = MenuState;
				}
			} else {
				if (temp == 1) {
					if (timeCounter <= 20) {
						timeCounter += 2;
						g.setColor(255, 255, 255);
						g.fillRect(100, 14, 60 - timeCounter, 5);
						g.setColor(255, 0, 0);
						g.fillRect(102, 15, 56 - timeCounter, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 24, 40, 5);
						g.setColor(0, 0, 255);
						g.fillRect(102, 25, 36, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 34, 20 + timeCounter, 5);
						g.setColor(0, 255, 0);
						g.fillRect(102, 35, 16 + timeCounter, 3);
					} else {
						drawP47(g);
						temp = MenuState;
					}
				} else {
					drawP47(g);
					temp = MenuState;
				}
			}
			break;
		case 1:
			g.setColor(255, 255, 0);
			g.drawString(" T - 3 8 ", 5, 10, 0);
			if (temp == 0) {
				if (timeCounter <= 20) {
					timeCounter += 2;
					g.setColor(255, 255, 255);
					g.fillRect(100, 14, 40 + timeCounter, 5);
					g.setColor(255, 0, 0);
					g.fillRect(102, 15, 36 + timeCounter, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 24, 40, 5);
					g.setColor(0, 0, 255);
					g.fillRect(102, 25, 36, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 34, 40 - timeCounter, 5);
					g.setColor(0, 255, 0);
					g.fillRect(102, 35, 36 - timeCounter, 3);
				} else {
					drawT38(g);
					temp = MenuState;
				}
			} else {
				if (temp == 2) {
					if (timeCounter <= 40) {
						timeCounter += 2;
						g.setColor(255, 255, 255);
						g.fillRect(100, 14, 20 + timeCounter, 5);
						g.setColor(255, 0, 0);
						g.fillRect(102, 15, 16 + timeCounter, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 24, 40, 5);
						g.setColor(0, 0, 255);
						g.fillRect(102, 25, 36, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 34, 60 - timeCounter, 5);
						g.setColor(0, 255, 0);
						g.fillRect(102, 35, 56 - timeCounter, 3);
					} else {
						drawT38(g);
						temp = MenuState;
					}
				} else {
					drawT38(g);
					temp = MenuState;
				}
			}
			break;
		case 2:
			g.setColor(0, 255, 0);
			g.drawString(" B - 6 2 ", 5, 10, 0);
			if (temp == 1) {
				if (timeCounter <= 40) {
					timeCounter += 2;
					g.setColor(255, 255, 255);
					g.fillRect(100, 14, 60 - timeCounter, 5);
					g.setColor(255, 0, 0);
					g.fillRect(102, 15, 56 - timeCounter, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 24, 40, 5);
					g.setColor(0, 0, 255);
					g.fillRect(102, 25, 36, 3);
					g.setColor(255, 255, 255);
					g.fillRect(100, 34, 20 + timeCounter, 5);
					g.setColor(0, 255, 0);
					g.fillRect(102, 35, 16 + timeCounter, 3);
				} else {
					drawB62(g);
					temp = MenuState;
				}
			} else {
				if (temp == 0) {
					if (timeCounter <= 20) {
						timeCounter += 2;
						g.setColor(255, 255, 255);
						g.fillRect(100, 14, 40 - timeCounter, 5);
						g.setColor(255, 0, 0);
						g.fillRect(102, 15, 36 - timeCounter, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 24, 40, 5);
						g.setColor(0, 0, 255);
						g.fillRect(102, 25, 36, 3);
						g.setColor(255, 255, 255);
						g.fillRect(100, 34, 40 + timeCounter, 5);
						g.setColor(0, 255, 0);
						g.fillRect(102, 35, 36 + timeCounter, 3);
					} else {
						drawB62(g);
						temp = MenuState;
					}
				} else {
					drawB62(g);
					temp = MenuState;
				}
			}
			break;
		}
	}

	/**
	 * P47相关画笔
	 */

	public void drawP47(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(100, 14, 40, 5);
		g.setColor(255, 0, 0);
		g.fillRect(102, 15, 36, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 24, 40, 5);
		g.setColor(0, 0, 255);
		g.fillRect(102, 25, 36, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 34, 40, 5);
		g.setColor(0, 255, 0);
		g.fillRect(102, 35, 36, 3);
	}

	/**
	 * T38相关画笔
	 */

	public void drawT38(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(100, 14, 60, 5);
		g.setColor(255, 0, 0);
		g.fillRect(102, 15, 56, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 24, 40, 5);
		g.setColor(0, 0, 255);
		g.fillRect(102, 25, 36, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 34, 20, 5);
		g.setColor(0, 255, 0);
		g.fillRect(102, 35, 16, 3);
	}

	/**
	 * B62相关画笔
	 */

	public void drawB62(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(100, 14, 20, 5);
		g.setColor(255, 0, 0);
		g.fillRect(102, 15, 16, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 24, 40, 5);
		g.setColor(0, 0, 255);
		g.fillRect(102, 25, 36, 3);
		g.setColor(255, 255, 255);
		g.fillRect(100, 34, 60, 5);
		g.setColor(0, 255, 0);
		g.fillRect(102, 35, 56, 3);
	}

	/**
	 * 主角飞机特写图片画笔
	 */

	public void drawLeadingPlane(Graphics g) {
		KingCanvas.Brush(g, LeadingPlane, LeadingPlane_X - timeCounter,
				LeadingPlane_Y, LeadingPlane.getWidth(), LeadingPlane
						.getHeight() / 3, LeadingPlaneNumber, 0);
	}

	/**
	 * 主角飞机选择菜单背景图片画笔
	 */

	public void drawMenuPhoto(Graphics g) {
		KingCanvas.Brush(g, MenuPhoto, 0, 50, MenuPhoto.getWidth(), MenuPhoto
				.getHeight(), 0, 0);
	}

	/**
	 * 主角飞机图示图片画笔
	 */

	public void drawSmallleadingPlane(Graphics g) {
		KingCanvas.Brush(g, SmallLeadingPlane1, SmallLeadingPlane_X,
				SmallLeadingPlane_Y, SmallLeadingPlane1.getWidth(),
				SmallLeadingPlane1.getHeight() / 3, 1, 0);
		KingCanvas.Brush(g, SmallLeadingPlane2, SmallLeadingPlane_X + 51,
				SmallLeadingPlane_Y, SmallLeadingPlane2.getWidth(),
				SmallLeadingPlane2.getHeight() / 3, 1, 0);
		KingCanvas.Brush(g, SmallLeadingPlane3, SmallLeadingPlane_X + 102,
				SmallLeadingPlane_Y, SmallLeadingPlane3.getWidth(),
				SmallLeadingPlane3.getHeight() / 3, 1, 0);
	}

	/**
	 * 主角飞机选择边框画笔
	 */

	public void drawLeandingPlaneFrame(Graphics g) {
		g.setColor(ColorCounter, ColorCounter, 0);
		g.drawRect(LeadingPlaneFrame_X, LeadingPlaneFrame_Y, 31, 30);
		if (ColorCounter < 240) {
			ColorCounter += 15;
		} else {
			ColorCounter = 0;
		}
	}

	// -------------------------------------------------

	/**
	 * 主角飞机选择菜单相关处理方法
	 */

	public void LeadingPlaneMenuPacket() {
		MenuState();
		MenuKeyOption();
		KC.InitBullets();
		KC.bFlagMusic();
	}

	/**
	 * 主角飞机选择菜单相关画笔
	 */

	public void drawLeadingPlaneMenu(Graphics g) {
		drawMenuPhoto(g);
		drawMenuState(g);
		if (timeCounterInit == true) {
			timeCounter = 0;
			timeCounterInit = false;
		}
		if (timeCounter > 100) {
			timeCounter++;
			drawLeadingPlane(g);
		} else {
			drawLeadingPlane(g);
		}
		drawSmallleadingPlane(g);
		drawLeandingPlaneFrame(g);
	}
}

⌨️ 快捷键说明

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