📄 gameengine.java
字号:
/*
* @(#)GameEngine.java, 1.7
*
* Copyright (c) 2001-2004 Sony Ericsson Mobile Communication AB (SEMC).
*
* German Branch
* Heisenbergbogen 1, Aschheim 85609, Munich, Germany.
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* SEMC. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with SEMC.
*
* @author venkat
* @version 1.7, 10/10/2003
*/
package com.sonyericsson.erix;
import javax.microedition.lcdui.Canvas;
/**
* The GameEngine class encapsulates most of the functionality of the actual
* game. It contains the game loop, and controls the Erix, Enemy object(s)
*
*/
public class GameEngine implements Runnable {
/**
* The reference to the GameCanvas object.
*/
private GameCanvas m_objCanvas;
/**
* The reference to the ErixMidlet object.
*/
private ErixMIDlet m_objMidlet;
/**
* The reference to the GameEffects object.
*/
private GameEffects m_objEffects;
/**
* Normal working mode of Engine.
*/
public static final int NORMAL_MODE = 1;
/**
* Paused mode of Engine.
*/
public static final int PAUSED_MODE = 2;
/**
* Game win mode.
*/
public static final int GAME_WIN_MODE = 3;
/**
* Mode set immediately before GAME_WIN_MODE,
* to do some neccessary processing.
*/
public static final int PRE_GAME_WIN_MODE = 3 + 50;
/**
* Game Lose mode.
*/
public static final int GAME_OVER_MODE = 4;
/**
* Life lose mode.
*/
public static final int LIFE_LOSE_MODE = 5;
/**
* Area Calculation mode of Engine.
*/
public static final int AREA_CALCULATE_MODE = 6;
/**
* Mode set immediately when player completes a level,
* but before the engine switches to the LEVEL_COMPLETE_MODE.
* The processing of level completion is done in two steps,
* defined as two modes.
*/
public static final int PRE_LEVEL_COMPLETE_MODE = 7;
/**
* The mode entered immediately after the PRE_LEVEL_COMPLETE_MODE.
* This is the second stage of processing of a level completion.
*/
public static final int LEVEL_COMPLETE_MODE = 8;
/**
* The mode entered before a level is started. This mode is used to
* display the "Level #" String at the start of each level.
*/
public static final int LEVEL_START_MODE = 9;
/**
* This mode is set when the level is initialized due to loss of life.
*/
public static final int LEVEL_INITIALIZE_MODE = 10;
/**
* The variable which stores the current mode of the Engine.
*/
public int m_nEngineMode;
/**
* The variable which stores the mode in which Engine was before pausing so
* that it can resume to the mode it was at the time of pausing.
*/
public int m_nPrevEngineMode;
/**
* Maximum logical X coordinate of the Playfield, + 2.
*/
public static final int X_MAX = 48;
/**
* Maximum number of columns in the Path data structure.
*/
public int m_nColMax;
/**
* Maximum Y coordinate of the Playfield.
* This has to be an odd number, because Erix moves in increments of two
* points (0, 2, 4 ... etc.).
* When Y_MAX is odd, Erix stops at Y_MAX-1.
* Otherwise (the way the movement logic is coded), Erix would reach Y_MAX,
* and an ArrayIndexOutOfBoundsException will be thrown (because the rows
* of the playfield are numbered 0 to Y_MAX-1).
*/
public static final int Y_MAX = 109;
/**
* The Erix object.
*/
public Erix m_objErix;
/**
* The array of Enemy objects.
*/
public Enemy[] m_objEnemy;
/**
* Count of Enemy objects for a particular level.
*/
public int m_nNumberOfEnemies;
/**
* Maximum number of enemies possible in any level.
*/
private final int MAX_NUMBER_OF_ENEMIES = 6;
/**
* The maximum number of iterations to be skipped by the enemies in a level
* before they move again. The actual number of iterations skipped
* by the enemies in any level dictate the speed of the enemies
* in that level.
*/
private final int MAX_ENEMY_DELAY = 1;
/**
* The maximum number of iterations to be skipped by erix before it moves
* again. The actual number of iterations skipped by Erix in any level
* dictates the speed of Erix.
*/
private final int MAX_ERIX_DELAY = 2;
/**
* Indicates the type of enemy for each level.
*/
public byte m_arrLevelEnemyType[][] = {
{1,1,1,1,1,1}, {2,1,1,1,1,1}, {3,1,1,1,1,1}, {4,1,1,1,1,1},
{1,2,1,1,1,1}, {2,3,1,1,1,1}, {3,4,1,1,1,1}, {4,1,1,1,1,1},
{1,1,2,1,1,1}, {2,2,3,1,1,1}, {3,3,4,1,1,1}, {4,4,1,1,1,1},
{1,1,2,2,1,1}, {2,2,3,3,1,1}, {3,3,4,4,1,1}, {4,4,1,1,1,1},
{1,1,2,2,3,1}, {2,2,3,3,4,1}, {3,3,4,4,1,1}, {4,4,1,1,2,1},
{1,1,2,2,3,4}, {2,2,3,3,4,1}, {3,3,4,4,1,2}, {4,4,1,1,2,3}
};
/**
* The array that contains information as to which enemies are in Region 1
* after move completion.
*/
private byte m_arrEnemyRegion1[];
/**
* The count of enemies in Region 1 after move completion.
*/
private int m_nEnemyRegion1Count;
/**
* The array that contains information as to which enemies are in Region 2
* after move completion.
*/
private byte m_arrEnemyRegion2[];
/**
* The count of enemies in Region 2 after move completion.
*/
private int m_nEnemyRegion2Count;
/**
* Indicates enemies of which region have to be relocated.
* Its value indicates either Region 1 or Region 2.
*/
private int m_nEnemiesToRelocate;
/**
* Indicates the Level that is in progress.
*/
public byte m_bytLevelNumber;
/**
* The type of game chosen by the player (Easy, Medium or Hard)
*/
public byte m_bytGameType;
/**
* The maximum possible score attainable by the player.
*/
private final long MAX_SCORE = 99999999;
/**
* The total score attained by the player.
*/
public long m_lTotalScore;
/**
* The score of the player at the start of a level.
*/
// public long m_lScoreAtLevelStart;
/**
* The number of chances(life) left for the player.
*/
public byte m_bytLifeCount;
/**
* The number of chances(life) of the player at the start of a level.
*/
//public byte m_bytLifeCountAtLevelStart;
/**
* The score after which life bonus has to be awarded to the player. It is
* initially 10000 and during the progress of the game it is incremented to
* 20000, 30000 and so on.
*/
private long m_lLifeBonus;
/**
* The player is awarded a life bonus everytime the player achieves
* "LIFE_BONUS_SCORE". In this case since its 10000, the player will be
* awarded a life bonus after 10000, 20000, 30000 and so on.
*/
private final int LIFE_BONUS_SCORE = 10000;
/**
* The total area of the playfield.
*/
private int m_nTotalArea;
/**
* The remaining unselected area left after area calculations.
* This keeps decrementing after completion of each move.
*/
private int m_nUnSelectedArea;
/**
* The percentage of total area secured by the player.
*/
public int m_nPercentAreaSecured;
/**
* The percentage of area to be secured by the player in the current level.
*/
public int m_nPercentAreaToSecure;
/**
* The amount of area secured after a move is complete.
*/
private int m_nAreaSecured;
/**
* The number of moves taken by the player to complete one level.
*/
private int m_nNumberOfMoves;
/**
* The bitmap of the entire playfield with the secured region marked.
*/
public byte[][] m_arrSecuredRegionBmp;
/**
* Indication of collision of an Enemy with the boundary of the playfield.
*/
private final int ENEMY_BOUNDARY_COLLISION = 11;
/**
* Indication of collision of an Enemy with Erix.
*/
private final int ENEMY_ERIX_COLLISION = 12;
/**
* A data structure for representing one of the regions after the completion
* of Erix's move.
*/
private short m_arrRegion1[][];
/**
* Indicates the number of points in Region1.
*/
private int m_nRegion1Points;
/**
* A data structure for representing the other region after the completion
* of Erix's move.
*/
private short m_arrRegion2[][];
/**
* Indicates the number of points in Region2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -