J2ME Game Development Instance Explanation (Date: 2003-10-10 Hits: 1541) [Comments on this article]? [Programmer Forum] [Save article to hard disk]? [Print article] Borland Development Discussion Zone Microsoft Development Discussion District C / C discussion district newcomer entry Zone J2ME reappears Huaisai Road. The preamble yesterday wandering online, found an article that explained Delphi to realize the game of Huaying Road, quite inspired. Thus, the impulse that transplant the Huadiang Road game to the phone is generated. Now the mobile game is dazzling, and it is not very enough. There are also many implementations of Huaying Road. Soon, the author had a hard work to J2ME, I just want to borrow this opportunity. There is another reason for using J2ME as a development language. It is currently the development of Java. The unlimited proliferation business is developing rapidly. J2ME's application is getting active, and I hope that my article can be able to promote J2ME knowledge and development team. . Due to the long-term influence of the ISO specification, I also intend to comply with software engineering requirements and take the waterfall development model to plan project, and I hope to take this opportunity to introduce readers who have no opportunities to participate in official project development. Software development process. ???? Here we first define the personnel system of the project group (in fact only me alone): Technical research, demand analysis, summary design, detailed design, code, test, one person, Steals online ready-made pictures, then use ACDSEE to convert it from BMP into PNG format (I don't make commercial applications for lectures, it should not be infringed); as for the release of OTA servers, this work is not Do (but I will introduce how to do this). Next, we plan to plan the schedule of the project, with my personal experience, imagine the following: technical research 2 days (this part of the feasibility and major technical issues of the project, the length of time), demand analysis Used for a long time (after all, there is a ready-made Dongdong to refer, as long as it is clear, there are still many previously used design patterns and write code), the summary design is used for half a day (with demand, the summary is not enough Take a piece of medicine, detailed design is 2 days (this step will be clear, but also to accurately describe as much as possible), 2 days (in fact, 1 day is enough, technology is not a problem, more Plan a day to deal with emergencies), 2 days of testing (test should account for at least one quarter of all projects, but this project is just a demo, too simple), release it for half a day (although we don't go Really publish it, but I have to take some time to figure out how to do it), and finally the project summary and open conference (time to be determined).
Second. Take the "Exquisiteness of Excellence, Be Take Press", the first step before the project is the previous survey. The Dongdong Road we have to do is visible everywhere, and we have to invest two aspects: 1. The content of the game: The game itself is very simple, that is, there are several plaids, Cao Cao occupies one of the larger plaids, then surrounded by several plaids, these plaid shapes are not necessarily the same, but blocking the direction of Cao Cao Mobile. The player needs to move these plaids, eventually moving Cao Cao to a designated location. More specifically, we discussed in later demand analysis and summary design. 2. Technical Reserve: Talking about technology, here is a brief introduction to J2me.java has three versions, respectively, J2ME (micro version) .j2se (Standard Edition) .j2ee (Enterprise Edition). J2ME is a standard with a 3-layer structure design. The lowest layer is the configuration layer, which is the device layer, which is a profile (Application) .MIDP is a brief watch of mobile information equipment, current mainstream mobile phone supports MIDP1.0, the latest is MIDP2.0, which adds support for games than the previous version, providing some classes in the javax.microedition.lcdui.game package to handle technologies in the game, such as the Sprite class that we will use later, it is used To flip the picture. Quele off again, the author decided to use MIDP2.0 to develop. First, you need to install a J2ME simulator, we use Sun's WTK2.0, I think Sun's things are most authoritative. Of course, you can also use Nokia.siemens or other simulators such as MoTolora, but their JDK is not the same, and the transplant written is more troublesome. Sun's WTK2.0 can go to http: // here / download, of course, the premise to successfully download is that you must first register a member of Sun (it is actually beneficial to you). The next step is to install one step by step. After installed, we start your J2ME journey with a "Hello World" program. We launched the KToolbar in the WTK 2.0 tool set, then click the New Project button, enter Project Name for HelloWorld, MIDlet Class Name to Hello, then click Create Project to start the generated project, and then click Create Project to start the project, the tool will pop up MIDP configuration brief watch Here, here is generated by default (you can modify later) Click OK, Tool Tips We put your write Java source program below the [Wtk_home] / Apps / HelloWorld / src directory. We edit the following code and save it under the above directory, the file is named hello.javaimport javax.microedition.midlet. *; Import javax.microedition.lcdui. *; Public class hello extends MIDlet {private display; public hello () {Display = display.getdisplay (this);} public void startapp () {textbox t = new textbox ("
Hello "," Hello ", 256, 0); Display.SetCurrent (T);} public void pointapp () {} public void design {}} After you are saved, click the build button, the tool will be for you. Compiler, if there is no accident, click the Run button, will pop up a mobile phone interface, do not have me to teach if you leave (click on the mouse to click on the mobile phone). Oh, your first J2ME program has OK. What? You still don't understand it, it is very powerful, you can write a J2ME program. It is really a master). This is mainly introduced to the WTK2.0 tool, the program is not the purpose, don't understand the back There will be a detailed explanation, just take you on the road. What? You don't understand Java! That is nothing to do, then I will tell you more. Skip J2ME, let's talk about the theory of games. Specific to Huaying Road This game, mainly three aspects, map. Game operation. Logic judgment. Talking here, other two aspects are put in a summary design and detailed design. The so-called map, in fact, the picture, is to display the graphics Output a pair of pictures, if you involve an animation, you can use Timertask.Thread or Rannable technology, which can be prepared in advance or temporary processing. There is an Image in J2ME. Class, specifically for managing pictures, it has a createImage () method, you can directly read image files (J2ME only supports pictures of PNG formats), or take a part of existing images (so we can put a lot of pictures Then, one piece is cut, the advantage is to save storage space and document reading time, all of which are performance bottlenecks for mobile phones). J2ME also has a Graphics class, specifically for drawing, it has DrawImage () The method can display a picture in the specified location, it also has a DrawRect () method and setColor () method. These two methods will be used after we play the game operation, here is here. The picture and the method of drawing, you need to know who to draw pictures, J2ME provides a Canvas class, literally means to canvas, it has a Paint () method for refreshing the page, and a repaint () method is used to call Paint () method. Listening to some confused, don't tighten, I will explain the specific procedures. For the convenience of future programming, we create two types of images and draw, images are used to save some constant values and pictures, which mainly is mainly For drawing, the source code of these two classes is as follows.
The source code of the Image Class is as follows: package huarongroad; import javax.microedition.lcdui. *; Import javax.microedition.lcdui.game. *; Public class images {// save constant // Drawing position constant public static firm int unit = 32 ; // Square length PUBLIC Static Final INT LEFT = 10; // The left boundary vertex PUBLIC Static Final INT TOP = 9; // Draw the upper boundary vertex // Map position constant public static final int width = 4; // Map Width Public Static Final INT Height = 5; // Map The Height // Map Mark Marks Blue Public Static Final Byte Caocao = (Byte) 'A'; File: // Cao Cao's map markup public static final byte machao = (Byte) 'b'; // Horse Chamgram Markup Public Static Final Byte Huangzhong = (Byte) 'C'; // Huang Zhong's Map Mark Public Static Final Byte Guanyu = (Byte) 'D'; // Guan Yu Map Mark Public Static Final Byte Zhangfei = (Byte) 'E'; // Zhang Fei's Map Mark Public Static Final Byte Zhaoyun = (Byte) 'F'; // Zhao Yun's Map Mark Public Static Final Byte Zu = (Byte) 'g'; // Stroke Map mark PUBLIC Static Final Byte Blank = (byte) 'h'; // Blank map mark ???? public static final byte cursor = (byte) 'i'; // cursor Map tag // Map combination marker constant public static factory byte DLEFT = (byte) '1'; file: // Combined graphic left mark public static final byte dup = (byte) '2'; ?? File: // Combined graphics Last mark PUB Lic Static Final Byte Dleftup = (Byte) '3'; File: // Combined Graphical Left Tag ???? // Picture Constant Public Static Image Image_Base; // Basic Picture Public Static Image Image_zhaoyun; // Zhao Yun Pictures Public Static Image image_Caocao; // Cao Cao's picture public static Image image_Huangzhong; // photo Huang public static Image image_Machao; // Ma Chao's picture public static Image image_Guanyu; // Guan Yu's picture public static Image image_Zhangfei; // Zhang's picture Public static image image_zu; // Stroke picture public static image image_blank; // Blank picture public static image image_frame; // Picture of the game frame PUBLIC images () {// Constructor} public static boolean init () {//// Picture used in the initialization game try {image_base =
Image.createImage ("/ huarongroad / bitback.png"); image_frame = image.createImage (image_base, 126, 0, 145, 177, sprite.trans_none); // Sprite class is used to flip the picture, is MIDP2.0 New newly added support game features image_zhaoyun = image.createImage (image_base, 0, 0, unit, 2 * unit, ?? sprite.trans_none); image_caocao = image.createImage (image_base, unit, 0, 2 * unit ,? 2 * UNIT, Sprite.TRANS_NONE);? image_Huangzhong = Image.createImage (image_base, 3 * UNIT, 0, UNIT, 2 * UNIT, Sprite.TRANS_NONE);? image_Machao = Image.createImage (image_base, 0, 2 * UNIT, ? UNIT, 2 * UNIT, Sprite.TRANS_NONE);? image_Guanyu = Image.createImage (image_base, UNIT, 2 * UNIT, 2 * UNIT, UNIT, Sprite.TRANS_NONE);?? image_Zhangfei = Image.createImage (image_base, 3 * Unit, 2 * Unit, ??? unit, 2 * unit, ??? sprite.trans_none; image_zu = image.createImage (image_base, 0, 4 * unit, unit, unit,? Sprite.trans_none); image_blank = image .createImage (image_base, 1 * unit, 4 * unit, unit, ??? Unit, ??? sprite.trans_none); return true;} catch (exception ex) {return false;}}} DRAW class source code as follows : Package huarongro Ad; import javax.microedition.lcdui. *; PUBLIC CLASS DRAW {// Draw Image Pictures PUBLIC DRAW (CANVAS CANVAS)} PUBLIC STATIC Boolean Paint (Graphics G, Byte Img, Int x, int y ) {// Draw the image of the image in the map Try {Paint (G, IMG, X, Y, IMAGES.Unit); // transform the map x, Y point into the absolute coordinate of the canvas, draw Return True;} catch (Exception EX) {Return False;}} public static boolean Paint (Graphics G, Byte Img, Int x, int y, int unit) {try {switch (img) {case images.caocao: // Cao Cao / / becomes an absolute coordinate, and adjust G.DrawImage (images.top x * unit, images.top y * unit, graphics.top | graphics.Left); Break; Cases.guanyu : // Painting G. DrawImage (images.image_guanyu, images.teft x * Unit, images.top
Y * Unit, graphics.top | graphics.Left); Break; Cases.huangzhong: // Painted Huangzhong G.DrawImage (images.top x * Unit, images.top y * Unit, graphics .Top | graphics.Left); Break; Cases.machao: // Painted horse super g.drawImage (images.top y * unit, graphics.top | graphics.top | graphics.top | graphics.top | graphics.top | graphics.top | Break; Case Image.zhangfei: // Draw G.DrawImage (images.top y * unit, images.top | graphics.Lraphics.top | graphics.LRAK; CASE Images.zhaoyun: // Draw Zhao Yun g.drawimage (images.top | graphics.top | graphics.top | graphics.Top | graphics.Top | graphics.LAK; Cases.zu: // Painting the pawl.drawImage (images.top y * unit, images.top y * unit, graphics.top | graphics.left); Break; Case Images.blank: // Draw blank g.drawimage Images.image_blank, images.top y * unit, graphics.top | graphics.left; Break; ?????????????????????????????????????????????????????????.. Cursor: // Painted cursor g.drawRect (images.top y * unit, images.Unit, images.Unit); BRE AK;} Return True;} catch (Exception EX) {RETURN FALSE;}}} where images are drawing position constants (that is, adjust the length of each lattice and relative coordinate original position when drawing), Map location constant (long, width), map marker regular (mark corresponding to the character), map combination marking regular quantity (later, the picture constant (Picture of the character); the Draw class is mainly responsible for drawing Character picture. Let me talk about the map mark constant and map combination marking in the image of the image. In order to be able to arrange the layout of each situation, we decided to store the information of the game layout in the external file, and then read it in after the program starts. This way we have set a set of code for storage pictures, which is the map mark, as the CAOCAO (Cao Cao) defined in the images class above is represented, when the program reads A characters, it can convert it into Cao Cao corresponding The picture is displayed at the location where the A character is read. However, from the actual observation we found that all pictures are not unified, some account for 4 landsters, some of them account for 2 landsters, and there are 1 lattice, and even if they are two plaids. Horizontal, vertical.
In view of this, we introduced the map combination mark, that is, when encountering multiple plaids, the value 1 (iMages.Left) indicates that its left is a real map mark, value 2 (iMages) .UP) indicates that it is a real map mark, value 1 (i.e., iMages.Leftup) means that its left side is a real map mark. The map combination mark constant is actually used, and is not related to the actual display. When we will go back to move, it will then analyze the use of the combination mark. The Draw class is mainly used to draw graphics on the canvas, which has two PAINT methods, which is a very common function overload. However, only the PAINT method of 4 parameters is actually used, which directly obtains the relative coordinate location information to draw pictures, and then call the PAINT method of 5 parameters. The PAINT method of the 5 parameters converts the relative coordinate position information into an absolute position, and actually calls the graphics.drawimage () method, draw pictures in the image in the image. The advantage of this implementation method is flexible and easy to expand, but you need to draw the location of the drawing, you can call 5 parameters of Paint methods when you correspond to the relative coordinate position in the lattice, without having to modify this Class; however, when you add a new picture, you can add a handle with the corresponding constant in Images and then add a handle to the 5 parameters of the DRAW. ???? Write here, the time two days is complete. Third, demand analysis ???? This part is called demand analysis, it sounds scary, in fact, it is to figure out what we have to do, what to do, those do not do. Below I lead to you together to complete this step. First of all, we have to be a grooming game. The story of Huaying Road is no longer described here, but the characters are limited here, as defined above, our version only provides Cao Cao (Caocao), Guan Yu ( ZHANGFEI (ZHAOYUN), Huangzhong, Ma Chao (Machao) and Strun (ZU). We also define the operation method of the game here: First, you must select a zone to move by the arrow keys (just a picture), and the selected area is in black square box; after selecting the Fire button (就 是 确) This area is selected, and the selected area is in the green square box; then select the area you want to move. At this point, use the red square box to selection area; select the area where the Fire button will move after selecting the area you want to move. (Picture) Move to the area you want to move and remove the green and red box. Here you need to emphasize the concept of the selection area, the selected area, the area you want to move and the area you want to move, these four concepts, please pay attention to distinguish, of course, this part should be recorded in the data dictionary. In order to achieve the focus of the article (introduce how to make a J2ME collection game), we define some content that is not related to this topic. No implementation: After passing the animation (to use the Timertask or Thread class when implementing, the subsequent series In the article, I will introduce the knowledge of animation in detail), the switching between the places (it is very simple, when you have completed the task, then do one while again), suspend and save, etc. (there are many more information on this part, I also I can't write any new stuff, I will inevitably copy it, so this is away from it). ???? Demand analysis is basically completed, there is another time from the afternoon, immediately use ACDSEE to adjust the BMP file from the Internet, adjust its size 271 * 177 (my picture is part of the two parts, so Save as PNG format than the actual screen of the phone). It is just a short time, not only knowing the Dongdong to do, but also prepare the picture you want to use. Fourth, profile design ???? Summary design is a bridge and link from demand analysis to a detailed design, which we determine the implementation method of the project and the division of the module.
We decided to divide the entire project into five parts, namely Images, Draw, and Map and DisplayAble1 and MIDlet1. Images and Draw class feature simple, structural fixed, so many projects we all use these two classes, which can be used directly, and it has been introduced, and it has been introduced. The MAP class is used to read the map from the external file, then save it in an array, this part of the content is our focus on this phase. Displayable1 is a canvas that inherits the Canvas class. It is used to handle the primary control logic and a part of the control logic. The main function should include the Paint () function used to draw, using keypressed () Function, used to control the setRANGE () function of the selection area to control the setmoveRAnge () function to be moved to the area, use the MOVE () function of the selected area and the win () function that determines whether the task is completed, more specific Analysis, we put it in the detailed design to refine. MIDlet1 is actually a control program that controls the entire J2ME application. It is actually a special, it is similar to the "Hello World" program introduced earlier, and it will not start here, and it will post its code. . ???? Map class mainly has a two-dimensional array of grid [] [] to store the map of Huadai Road, and there should be a read_map () function to fill the GRID data structure from the external file. Another is to have a DRAW_MAP () function to convert the map contents of the GRID data structure into a picture (of course to call the DRAW class's PAINT method). Speaking of reading external documents, the author knows having two ways: one is a traditional definition of an inputStream object, then use getClass (). GetResourceSstream () method to get the input stream, and then obtain the content of the external file from the input stream, For example INPUTSTREAM IS = GetClass (). GetResourceceAsStream ("/ filename"); if (is! = Null) {???? byte a = (byte) is.read ();} Here you note the root path in the file name It is positioned relative to the place where the Class file is placed instead of the source file (Java). The second method is to use the OnNector.openInputStream method, then the protocol that is opened is resource, but this method author repeatedly does not stop, the reported error is the lack of the Resource protocol, estimated that some of the J2ME Extended class packages, no longer Since I have done some of the similar Huatai Road like this, the Map class code is given directly, and the Map class is no longer explained in detail so that we can concentrate on processing logic in DisplayAble1.
The code of the MAP class is as follows: package huarongroad; import java.io.inputstream; import javax.microedition.lcdui. *; Public class map {// Handling the game's map, responsible for loading map data from external files, store map data, and follows Map Data Drawing Map Public Byte Grid [] []; // Store Map Data PUBLIC MAP () {// Constructor, responsible for initializing the storage structure of map data this.grid = new byte [images.Height] [images.width] ; // store map data with a two-dimensional array, pay attention to the first dimension is vertical coordinates, the second dimension is horizontal coordinate} public int [] read_map (int i) {???????? file: // The external file loads the map data and stores in the storage structure, the return value is the position of the cursor point // parameter is the level of the map file ???????? Int [] a = new int [2]; // The position of the cursor point, 0 is horizontal position, 1 is vertical position try {inputStream is = getClass (). GetResourceSstream ("/ huarongroad / level" .concat (String.Valueof (i))); if (is! = Null ) {for (int K = 0; K ) {for (int J = 0; j Look at time, just have a long time. Rest, take a break, see you tomorrow. V. Detailed design ????? Detailed design is a crucial part of the process development process, so we have built some of the tools needed in the previous stages, now we only need to concentrate this stage. Energy design is logic in DisplayAble1. (Two days of course, don't just do this, you have to modify other classes) ???? DISPLAYABLE1 This class is responsible for handling the control logic of the program. First, it needs to have a variable LOC that represents the currently surface, indicating the variable LOC of the current cursor position, indicating the variable Selectarea to move the area, indicating the variable MoveArea of the area to be moved, indicating whether there is area to be selected and ready to move. Variable SELECTED and MAP class instance mymap. Then, we will implement different messages according to different keys, we must implement the keypressed () function, in the function, we handle the upper and lower left and lower and select (fire), the processing needs me to speak, behind I will quickly expand this part. Next, it is to implement a Paint () function. We intend to repeat the background, map and selection area in this section. This function must handle the color of the brush color after the area being selected, and the specifically is not selected. When you use a black brush, use a green brush when electing an important movement area, and use a red brush when you choose to move to the area (of course, an additional flowchart is essential). The setRange () function and setmoveRange () function you want to implement will then set it to set the area where you want to move and the area you want to move. My idea is to use the map combination marking of maps over the Image Class. When moving to the map combination marking constant, find a reverse transformation in accordance with the value in this point, find the corresponding map mark, then set the corresponding LOC, SELECTAREA, and MOVEAREA, where the setmoveRange () function also uses an auxiliary function ISINRANGE. ), isinrange () function is used to determine if a given point is within the area selected to move, if the return value of Isinrange () is false and the value at this point is not blank, indicating that the area to be moved Invaded other areas of occupied. With the setRANGE () and setmoveRAnge () functions, the Move () function is water to the stream, and the move () function moves the area to move to the area where you want to move, divided into three steps during the movement: First. Copy Move the area, second. Copy the copy to move the area to the area where you want to move (these two steps are the purpose of the two steps to prevent the area where to move off) during the replication process), third. Use isinrange2 () It is judged whether a given point is in the area where you want to move, will not be set to a blank in the area you want to move. ???? Next We detailed analysis of the keypressed () function implementation method: First, Keypressed ( Function To process the up and down left and right and selection of the button, you need to convert the key value of the button to the direction of the game when processing, so that the compatibility of the game can be improved (because different J2ME implementations, The key value of the arrow keys is not necessarily the same). Next, the four directions and selection are processed separately. When pressing up, first determine if the area you want to move (ie this.selected is true) If you do not choose to move the area, let the cursor move up, then call the setRANGE () function setting Select the area you want to move, then call the repaint () function refresh screen, otherwise, if you have already selected the area you want to move, let the cursor Move up, then call the setmoveRANGE () function to determine if the selected area can be moved up, if you can move, call the repaint () function refresh screen, if you can't move, let the cursor back to the original location. When you press When the next time, the area where you want to move, if you do not select the area you want to move, it is judge whether or not the currently located is two Gaigao, if it is the two GG, move the two grids. If it is a high level, move one, then call the setRANGE () function setting to select the area you want to move, then call the repaint () function refresh screen, otherwise, if you have already selected the area you want to move, let the cursor down Move one, then call the setmoveRANGE () function to determine if the selected area can be moved down, if you can move, call the repaint () function to refresh the screen, if you cannot move, let the cursor back to the original position. Press the left When the situation is completely similar, the situation is completely similar to the situation, so it will not be described here again. For details, please refer to the source code of the program. When selecting the hidden button, first determine if it has been selected Moving the area, if the area where you want to move, call the move () function to complete the movement of the area to be moved to the area to be moved, then call the repaint () function refresh the screen, and then set the selected tag. fly ALSE, continue to call the WIN () function to determine if the task is completed, otherwise, if there is no selected to move, it is again determined whether the currently selected area is blank, if not blank, will be selected into true, then refresh the screen. here. Introducing a trick, when the development program encounters complex logic, you can construct a print function to print out the data structure of your concern to make the debug, here we construct a printGrid () function, this function is purely for debugging Use, the effect is good. At this time, we have completed all the work before the encoding. ???? Take a look at the time, I will briefly introduce the MIDlet1 class, this class and the "Hello World" in the previous introduction Datong, look at the program code: where StartApp (). PauseApp () and DestroyApp () The three abstraction methods of the MIDlet class must be overloaded, they control the beginning of a J2ME program. Pause and end The DISPLAYABLE1 is an instance of the Displayable1 mentioned earlier, used to be responsible for displaying the user interface and control program logic. This class is generally written. ???? Two days a little rich Today you can discomfort. Six. Coding ???? The entire project has five classes, there are four classes of code already introduced, and it is the relatively mature code used in other projects. Now just need to go Displayable1 class code that implements the class .Displayable1 follows: package huarongroad; import javax.microedition.lcdui *; public class Displayable1 extends Canvas implements CommandListener {???? private int [] loc = new int [2];. File: // Current position of the cursor, 0 is horizontal position, 1 is vertical position ????? private int [] selectarea = new int [4]; // The selected area, that is, the area you want to move ?? ?? ?? private int [] movearea = new int [4]; // To move the area ???? private map mymap = new map (); // map class ???? private boolean selected; // Select the flag to move the area ???? private int level; //, before the face ???? public displayable1 () {// constructor try {???? jbinit (); // jbuilder definition initialization Function} Catch (Exception E) {???? E.PrintStackTrace ();} ????} ????priVate void init_game () {// Initialization game, read map, set the selection area, clear to move The area this.loc = mymap.read_map (this.LesLevel); // read the map file and returns the initial position of the cursor / 0 is horizontal, 1 is the vertical position this.Selectarea [0] = this. LOC [0]; // Initializes the selection area ???????? this.selectarea [1] = this.loc [1]; ???????? this.selectArea [2] = 1; ???????? this.selectarea [3] = 1; ???????? this.movearea [0] = -1; // Initialization to move to the area ??????? ? this.movearea [1] = -1; ???????? this.movearea [2] = 0; ???????? this.movearea [3] = 0;} ???? Private void jbinit () throws exception {// jbuilder defined initialization function ???????? file: // initialization instance variable ???????? this.selected = false; // set is not selected To move zone this.level = 1; ???????? Images.init (); // Initialize picture constant init_game (); // Initialize the game, read map, set the selection area, clear to move to Region setcomma ndlistener (this); // Add command monitor, this is the disc example of Displayable, addcommand (New Command ("EXIT", Command.exit, 1)); // Add "Exit" button ????} ???? Public void command (Command Command, Displayable Displayable) {// Command Processing Function IF (Command.getCommandType () == Command.exit) {// Processing "Exit" ???? MIDlet1.quitApp ();} ??? ?} ???? Protected Void Paint (Graphics G) {// drawing function, is used to draw the user screen, the display picture, select the zone, and the area you want to move {???? g.drawimage (images. Image_frame, 0, 0, graphics.top | graphics.Left); // Draw background ???????????? mymap.draw_map (g); // According to the map content drawing ???? ing ( This.Selected) G.SetColor (0,255,0); // If you are selected, Use green to draw the selected area ???? g.drawRect (this.selectarea [0] * images.Unit images.left, ??????????????? this.selectarea [1] * Images.Unit images.top, ??????? this.selectarea [2] * images.Unit, ??????? this.selectarea [3] * images.Unit); / / Draw a selection area, ?????????????????????????????????????????????? ????? File: // If you are selected, use green ??????????????????????????????????????????????????????? ??????????????????????? file: / / otherwise, use black ??????????? g.setColor (255, 255, 255); // Restore the brush color ???? if (this.selected) {// has been selected to move the area G.SetColor (255, 0, 255); // Change Red G.DrawRect (this.movearea [0 ] * Images.Unit images.Left, ??? this.movearea [1] * images.Unit images.top, ??? this.movearea [2] * images.Unit, ??? this.movearea [3 ] * Images.Unit); // Draw the area you want to move? ????????? G.SetColor (255, 255, 255); // Restore the brush color ????}} catch (Exception ex) {} system.out.println (Runtime.Getruntime (). FreeMemory ()); system.out.println (Runtime.Getruntime (). TOTALMEMORY ()); ????} ????priVate Void setRANGE () {// Set the location that can be selected and the current cursor position to the main location of the map, that is, the position IF of the person information (this.mymap.grid [this.loc [1]] [this. LOC [0]] == images.dleft) {???? this.loc [0] - = 1 ; // Turn left} else if (this.mymap.grid [this.loc [1]] [this.loc [0]] == images.dup) {???? this.loc [1] - = 1; // Turn up} else if (this.mymap.grid [this.loc [1]] [this.loc [0]] == images.dleftup) {???? this.loc [0] - = 1; // Tone left ???? this.loc [1] - = 1; // upset} this.selectarea [0] = this.loc [0]; // Set the horizontal position of the cursor this.Selectarea [1] = this.loc [1]; // Set the vertical position of the cursor // Set the width IF of the cursor (this.loc [0] 1 (Byte) '2' ??????? ??? 1: 2;} else {???? this.selectarea [3] = 1;} ????} ?????????????????????????????????????????????????????? ) {// Set the area to be moved, can move back TRUE, otherwise returning falsefor (int i = 0; i / / Set the cursor movement, the function moves the cursor to the main position repaint (); // re-draws ????}} else {// has selected the area you want to move ???? ing ( THISLOC [1] - 1> = 0) {// Continuously there is a mobile space this.loc [1] -; / / moving up the IF (SETMOVERANGE ()) {// can move, the function can be set Area to move to the area ???? repaint (); // re-draw} else {// can not move ???? this.loc [1] ; // returning} ????}} Break; ??????? case canvas.down: // Down If (! this.selected) {// has not selected the area you want to move ???? ife (this.loc [1] 1 ??? ???? Images.dleft) {// This image has two grid trees.loc [0] ; // Move IF to the right (this.loc [0] 1 -1 || this.moveareA [1] == -1 || ?? ???? this.selectarea [0] == -1 || this.selectarea [1] == -1) {// No selected Region} else {// The area where you want to move and you want to move ???? Byte [] [] Temp = new byte [this.selectarea [3]] [this.selectarea [2]];? ?? ???? file: // copy the area you want to move, because this area may be overwritten ???? for (int i = 0; i