J2ME Submarine Wars Game Design and Implementation

xiaoxiao2021-03-06  20

This article gives a design process of aircraft shooting (submarine) game and corresponding flowcharts, and provides the Demo version of the source code download address, the game is debugged under Sun WTK V2.2.

Disclaimer: Most resources used in this game do not belong to the author, and the code is only available for non-commercial use.

The following is a few screenshots

game design

1 Game operation process:

The initial picture of the game is an Implusive List list format. After selecting New Game, you can start the game, the game is turned on in full screen, but there is still a command response function key for pause / start and exiting. In the game, the seawater and marine life will continue to be active, but the enemy submarines and all torpedoes will still be stationary, and the player's control will not work until the game is started again. Exit from the game status will return to the menu interface, and select the exit will exit the program.

The following is the overall flow chart of the game:

2 algorithm processing

The game itself is a single-state structure, which handles the screen and status currently appearing. The main display classes include main screens, game canvas, help pictures, and some assistant Alert, which is the most important of which is the game screen. The game is running in the state of MIDP 2, so the picture inherits Gamecanvas. The role layer in the game is loaded on a layer manager much greater than the screen size of the phone. When the player position moves, the layer manager synchronizes the relative position of the player and moves the display position of the current layer.

The essence of this game is to start the entire canvas as a thread after the MIDlet startup, scan the user button operation every 25ms, scans the motion state of the objects such as enemies and torons every 50ms, and inherits for a real-time response, inherits for a factful bullet KEYPRESSED method.

When scanning the player mobile operation, the key coding is incorporated into the player submarine. When scanning the enemy and torpedo, it is completed in two steps.

The first step is performed by performing a moving method of each object screen. The program does not open a new thunder for each new torpedire or an enemy, too many threads will cause the performance straight line to decline; but a vector array for each object type, whenever a new object is generated, he will be first In the array belonging to the category, then draw on the layer; when the object is eliminated, it is necessary to delete from the response array in addition to being eliminated on the layer. This forms a registration mechanism, and all the generated and elimination of all game objects need to be registered with the canvas. It has all the "list" of different types of objects, so when performing the mobile command, only the various type arrays are needed, and execute it in turn Move method for each element.

In the second step, it is the general sense of heavy painting, where flushgraphics () replaces the traditional repaint (), because the game is in the imported picture as an operation object, the image location is already executed in the first step, so it is not Reflecting pixel levels, just when the game is initialized, you need to load the layers to the new layer manager corresponding to the array of each object.

Canvas trigger flow diagram:

(Because there is no ROSE in the hand, only the draft picture of Eclipseuml is temporarily discussed, and some problems need to be discussed, and I hope that the friend who is good at not refreshing.

Type 3 structure

The following list is listed below, and a class associative map is listed in the game can be listed.

Controller: Control class to control which DisplayAble class is displayed in the current screen.

SubObject: Interface type. Player submarines, enemy submarines, and removable layer types such as torpedo are extended to this interface.

Sub: Player Submarine. Contains a member variable such as location, health, and mobile, fire, and other methods.

Enemysub, MoveAblesprite, Tinfish: enemy submarines, marine life, torpedo. They are all movable layer types, once the generation is registered in the canvas, and maintains their motion and life status by the time trigger. SUBCANVAS: Game main creation. Store game map information, game status, player information, synchronously maintains the movement and survival of enemy submarines, torpedoes, marine organisms.

SUBCANVAS association class diagram:

4 source code

The source code of this program, including JAD, confused JAR and a RAR file, all can be downloaded on http://www.hyweb.net/browsefiles.aspx?folder=public/my project, the code is included. More detailed comments. This program is just a Demo version, there are some legacy issues (player's health display, performance optimization) also need further improvement, there is any good suggestion, please contact me. ^ _ ^

Disclaimer: Most resources used in this game do not belong to the author, and the code is only available for non-commercial use.

The following is a few screenshots

game design

1 Game operation process:

The initial picture of the game is an Implusive List list format. After selecting New Game, you can start the game, the game is turned on in full screen, but there is still a command response function key for pause / start and exiting. In the game, the seawater and marine life will continue to be active, but the enemy submarines and all torpedoes will still be stationary, and the player's control will not work until the game is started again. Exit from the game status will return to the menu interface, and select the exit will exit the program.

The following is the overall flow chart of the game:

2 algorithm processing

The game itself is a single-state structure, which handles the screen and status currently appearing. The main display classes include main screens, game canvas, help pictures, and some assistant Alert, which is the most important of which is the game screen. The game is running in the state of MIDP 2, so the picture inherits Gamecanvas. The role layer in the game is loaded on a layer manager much greater than the screen size of the phone. When the player position moves, the layer manager synchronizes the relative position of the player and moves the display position of the current layer.

The essence of this game is to start the entire canvas as a thread after the MIDlet startup, scan the user button operation every 25ms, scans the motion state of the objects such as enemies and torons every 50ms, and inherits for a real-time response, inherits for a factful bullet KEYPRESSED method.

When scanning the player mobile operation, the key coding is incorporated into the player submarine. When scanning the enemy and torpedo, it is completed in two steps.

The first step is performed by performing a moving method of each object screen. The program does not open a new thunder for each new torpedire or an enemy, too many threads will cause the performance straight line to decline; but a vector array for each object type, whenever a new object is generated, he will be first In the array belonging to the category, then draw on the layer; when the object is eliminated, it is necessary to delete from the response array in addition to being eliminated on the layer. This forms a registration mechanism, and all the generated and elimination of all game objects need to be registered with the canvas. It has all the "list" of different types of objects, so when performing the mobile command, only the various type arrays are needed, and execute it in turn Move method for each element.

In the second step, it is the general sense of heavy painting, where flushgraphics () replaces the traditional repaint (), because the game is in the imported picture as an operation object, the image location is already executed in the first step, so it is not Reflecting pixel levels, just when the game is initialized, you need to load the layers to the new layer manager corresponding to the array of each object. Canvas trigger flow diagram:

(Because there is no ROSE in the hand, only the draft picture of Eclipseuml is temporarily discussed, and some problems need to be discussed, and I hope that the friend who is good at not refreshing.

Type 3 structure

The following list is listed below, and a class associative map is listed in the game can be listed.

Controller: Control class to control which DisplayAble class is displayed in the current screen.

SubObject: Interface type. Player submarines, enemy submarines, and removable layer types such as torpedo are extended to this interface.

Sub: Player Submarine. Contains a member variable such as location, health, and mobile, fire, and other methods.

Enemysub, MoveAblesprite, Tinfish: enemy submarines, marine life, torpedo. They are all movable layer types, once the generation is registered in the canvas, and maintains their motion and life status by the time trigger.

SUBCANVAS: Game main creation. Store game map information, game status, player information, synchronously maintains the movement and survival of enemy submarines, torpedoes, marine organisms.

SUBCANVAS association class diagram:

4 source code

The source code of this program, including JAD, confused JAR and a RAR file, all can be downloaded on http://www.hyweb.net/browsefiles.aspx?folder=public/my project, the code is included. More detailed comments. This program is just a Demo version, there are some legacy issues (player's health display, performance optimization) also need further improvement, there is any good suggestion, please contact me. ^ _ ^

转载请注明原文地址:https://www.9cbs.com/read-44544.html

New Post(0)