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

📄 xmain.java

📁 初学者的佳音 初学者的佳音 初学者的佳音
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

		case STATE_LOGO_ONE:
		case STATE_LOGO_TWO:
			enterLogo();
			break;

		case STATE_TITLE:
			enterTitle();
			break;

		case STATE_MENU_MAIN:
		case STATE_MENU_HELP:
			enterMenu();
			break;

		case STATE_OPTIONS:
			enterOptions();
			break;

		case STATE_MESSAGE:
			enterMessage();
			break;

		case STATE_GAME_START:
			enterGame();
			break;
		}
	}

	protected void stateLeave() {
		switch (state) {
		case STATE_GAME_END:
			leaveGame();
			break;
		}
	}

	protected void gameInput() {
		switch (state) {
		case STATE_LOGO_ONE:
		case STATE_LOGO_TWO:
			inputLogo();
			break;

		case STATE_TITLE:
			inputTitle();
			break;

		case STATE_MENU_MAIN:
		case STATE_MENU_HELP:
			inputMenu();
			break;

		case STATE_OPTIONS:
			inputOptions();
			break;

		case STATE_MESSAGE:
			inputMessage();
			break;
		}
	}

	protected void gameLogic() {
		switch (state) {
		case STATE_START:
			logicStart();
			break;

		case STATE_LOGO_ONE:
		case STATE_LOGO_TWO:
			logicLogo();
			break;

		case STATE_TITLE:
			logicTitle();
			break;

		case STATE_MENU_MAIN:
		case STATE_MENU_HELP:
			logicMenu();
			break;

		case STATE_OPTIONS:
			logicOptions();
			break;

		case STATE_MESSAGE:
			logicMessage();
			break;

		case STATE_GAME_START:
		case STATE_GAME_END:
			logicGame();
			break;
		}
	}

	protected void gamePaint(Graphics g) {
		switch (statePaint) {
		case STATE_START:
			paintStart(g);
			break;

		case STATE_LOGO_ONE:
		case STATE_LOGO_TWO:
			paintLogo(g);
			break;

		case STATE_TITLE:
			paintTitle(g);
			break;

		case STATE_MENU_MAIN:
		case STATE_MENU_HELP:
			paintMenu(g);
			break;

		case STATE_OPTIONS:
			paintOptions(g);
			break;

		case STATE_MESSAGE:
			paintMessage(g);
			break;
		}
	}

	// ************************************
	// game
	// ************************************

	protected int counter; // game loop counter

	private Random random;

	protected final int random(int range) {
		if (range <= 0) {
			return 0;
		}

		return Math.abs(random.nextInt()) % range;
	}

	protected final void randomSeed(long seed) {
		random.setSeed(seed);
	}

	// ************************************
	// state: start
	// ************************************

	private void enterStart() {
		counter = 0;
	}

	private void logicStart() {
		random = new Random();

		setState(STATE_LOGO_ONE);
	}

	private void paintStart(Graphics g) {
		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, width, height);
	}

	// ************************************
	// state: logo
	// ************************************

	protected void enterLogo() {
		counter = 0;

		switch (state) {
		case STATE_LOGO_ONE:
			// create options
			int numOptions = 0;

			String[][] tempOptions = createOptions();
			if (tempOptions != null) {
				numOptions = tempOptions.length;
			}

			#if((${ant.handset_music}!="none")||(${ant.handset_sound}!="none"))
			numOptions++;
			#end

			if (numOptions == 0) {
				options = null;
			} else {
				options = new String[numOptions][];
				if (tempOptions != null) {
					for (int i = 0; i < tempOptions.length; i++) {
						options[i] = tempOptions[i];
					}
				}

				#if((${ant.handset_music}!="none")||(${ant.handset_sound}!="none"))
				options[numOptions - 1] = SOUND_OPTIONS;
				#end
			}

			// create records
			int numRecords = 0;

			byte[][] tempRecords = recordInitialData();
			if (tempRecords != null) {
				numRecords = tempRecords.length;
			}

			if (numOptions > 0) {
				numRecords++;
			}

			recordData = new byte[numRecords][];
			if (tempRecords != null) {
				for (int i = 0; i < tempRecords.length; i++) {
					recordData[i] = tempRecords[i];
				}
			}

			if (numOptions > 0) {
				recordData[numRecords - 1] = new byte[numOptions];
				for (int i = 0; i < numOptions; i++) {
					recordData[numRecords - 1][i] = 0;
				}
			}

			// load options
			if (numOptions > 0) {
				byte[][] temp = new byte[1][];
				recordLoad(temp, recordData.length - 1);
				optionSelected = temp[0];
			}
			break;

		case STATE_LOGO_TWO:
			dataLoad();
			break;
		}
	}

	protected void inputLogo() {
		if (inputPressed != INPUT_NONE) {
			counter = 20;
		}
	}

	protected void logicLogo() {
		if (counter >= 20) {
			switch (state) {
			case STATE_LOGO_ONE:
				setState(STATE_LOGO_TWO);
				break;

			case STATE_LOGO_TWO:
				setState(STATE_TITLE);
				break;
			}
		}
		
	}

	protected void paintLogo(Graphics g) {
		switch (state) {
		case STATE_LOGO_ONE:
			g.setColor(0xFFFFFF);
			break;

		case STATE_LOGO_TWO:
			g.setColor(0x000000);
			break;
		}

		g.fillRect(0, 0, width, height);
	}

	// ************************************
	// state: title
	// ************************************

	protected void enterTitle() {
		counter = 0;
	}

	protected void inputTitle() {
		if (inputPressed != INPUT_NONE) {
			counter = 20;
		}
	}

	protected void logicTitle() {
		if (counter >= 20) {
			setState(STATE_MENU_MAIN);
		}
	}

	protected void paintTitle(Graphics g) {
		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, width, height);
	}

	// ************************************
	// state: menu
	// ************************************

	protected int menuX;

	protected int menuY;

	protected int menuW;

	protected int menuH;

	protected int menuItemHeight;

	protected int menuItemSelected;

	protected String[] menuItemName;

	protected boolean[] menuItemVisible;

	protected void enterMenu() {
		menuItemName = null;
		menuItemVisible = null;

		createMenu();

		if (menuItemName == null) {
			menuItemName = new String[0];
		}

		if (menuItemVisible == null) {
			int length = menuItemName.length;

			menuItemVisible = new boolean[length];
			for (int i = 0; i < length; i++) {
				menuItemVisible[i] = true;
			}
		}

		if (state == STATE_MENU_MAIN) {
			int length = menuItemName.length + 3;

			String[] tempName = new String[length];
			boolean[] tempVisible = new boolean[length];

			for (int i = 0; i < length - 3; i++) {
				tempName[i] = menuItemName[i];
				tempVisible[i] = menuItemVisible[i];
			}

			tempName[length - 3] = "@MENU_MAIN_OPTION@";
			tempName[length - 2] = "@MENU_MAIN_HELP@";
			tempName[length - 1] = "@MENU_MAIN_QUIT@";
			tempVisible[length - 3] = (options != null);
			tempVisible[length - 2] = true;
			tempVisible[length - 1] = true;

			menuItemName = tempName;
			menuItemVisible = tempVisible;
		}

		menuItemSelected = -1;
		menuDown();

		if (state == STATE_MENU_MAIN) {
			setSoftkey(SOFTKEY_OK, SOFTKEY_NONE);
		} else {
			setSoftkey(SOFTKEY_OK, SOFTKEY_BACK);
		}
	}

	protected void inputMenu() {
		switch (inputPressed) {
		case INPUT_UP:
			menuUp();
			repaint = true;
			break;

		case INPUT_DOWN:
			menuDown();
			repaint = true;
			break;

		case INPUT_OK:
		case INPUT_FIRE:
			actionMenu();
			break;

		case INPUT_CANCEL:
			if (state == STATE_MENU_HELP) {
				setState(STATE_MENU_MAIN);
			}
			break;
		}
	}

	protected void logicMenu() {

	}

	protected void paintMenu(Graphics g) {
		drawMenuBackground(g);

		int total = 0;
		for (int i = 0; i < menuItemVisible.length; i++) {
			if (menuItemVisible[i]) {
				total++;
			}
		}

		int n = menuH / menuItemHeight;
		if (n > total) {
			n = total;
		}

		int space = (menuH - menuItemHeight * n) / (n + 1);

		int start = menuItemSelected - (n - 1) / 2;
		if (start < 0) {
			start = 0;
		}
		if (start > total - n) {
			start = total - n;
		}

		int y = menuY + space;
		int temp = 0;
		for (int i = 0; i < menuItemVisible.length; i++) {
			if (menuItemVisible[i]) {
				if (temp >= start) {
					drawMenuItem(g, i, menuX, y);

					if ((state == STATE_OPTIONS) && (i == menuItemSelected)
							&& (objectArrow >= 0)) {
						int tempY = y + menuItemHeight / 2;

						drawObject(g, objectArrow, 2, counter, menuX, tempY);
						drawObject(g, objectArrow, 3, counter, menuX + menuW,
								tempY);
					}

					y += menuItemHeight + space;
				}

				temp++;

				if (temp >= start + n) {
					break;
				}
			}
		}

		if (objectArrow >= 0) {
			if (start > 0) {
				drawObject(g, objectArrow, 0, counter, menuX + menuW / 2, menuY);
			}

			if (start < total - n) {
				drawObject(g, objectArrow, 1, counter, menuX + menuW / 2, menuY
						+ menuH);
			}
		}
	}

	protected void createMenu() {
		menuX = 0;
		menuY = 0;
		menuW = width;
		menuH = height;

		menuItemHeight = fontHeight + 2;
	}

	protected void actionMenu() {
		if (state == STATE_MENU_MAIN) {
			switch (menuItemName.length - menuItemSelected) {
			case 3:
				setState(STATE_OPTIONS);
				break;

			case 2:
				setState(STATE_MENU_HELP);
				break;

			case 1:
				destroy();
				break;
			}
		}
	}

	protected void drawMenuBackground(Graphics g) {
		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, width, height);
	}

	protected void drawMenuItem(Graphics g, int item, int x, int y) {
		if (item == menuItemSelected) {
			g.setColor(0xFF0000);
		} else {
			g.setColor(0x000000);
		}

		g.drawString(menuItemName[item], x, y, TOP_LEFT);
	}

	private void menuUp() {
		int temp = menuItemSelected - 1;
        
		while ((temp >= 0) && (!menuItemVisible[temp])) {
			temp--;
		}

		if (temp >= 0) {
			menuItemSelected = temp;
		}
	}

	private void menuDown() {
		int temp = menuItemSelected + 1;

		while ((temp < menuItemVisible.length) && (!menuItemVisible[temp])) {
			temp++;
		}

		if (temp < menuItemVisible.length) {
			menuItemSelected = temp;
		}
	}

	// ************************************
	// state: options
	// ************************************

	private String[][] options;

	protected byte[] optionSelected;

	protected void enterOptions() {
		int numOptions = options.length;

		menuItemName = new String[numOptions];
		menuItemVisible = new boolean[numOptions];
		for (int i = 0; i < numOptions; i++) {
			menuItemName[i] = options[i][optionSelected[i]];
			menuItemVisible[i] = true;
		}

		menuItemSelected = -1;
		menuDown();

		setSoftkey(SOFTKEY_OK, SOFTKEY_BACK);
	}

	protected void inputOptions() {
		switch (inputPressed) {
		case INPUT_UP:
		case INPUT_DOWN:
			inputMenu();
			break;

		case INPUT_LEFT:
		case INPUT_RIGHT:
			int temp = optionSelected[menuItemSelected];

			if (inputPressed == INPUT_LEFT) {

⌨️ 快捷键说明

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