Introduction to the j2-pseudo-Master Pioneer-design of the mine clearance game

Source: Internet
Author: User
Tags inheritance
Introduction to the j2-pseudo-Master Pioneer-design of the mine clearance game

First, I want to pretend to analyze the system a little like a master.
Generally, according to the java development mode, this program is generally divided into three modules for development.
There are three:
The main file operated by a program, that is, the inheritance of a midlet;
An interface represents a class, that is, the inheritance of a canvas. There should be some menus on the interface, such as new and exit, implements should be a commandListener message listening class (you can think of java message listening as a thread, and you have always looked at what is pleasing to the eye like a hacker, of course, this refers to the messages that he can reach. When receiving a message, an abstract function public void commandAction (Command c, Displayable d) is called ), this abstract function allows us to process the received message, that is, the message response, through its implementation)
The last one is of course the logic unit unrelated to the interface. Here we define the logic of the entire game to separate the logic from the interface. This is my biggest achievement in Learning java.
First, let's officially start the first lecture: <logic of the mine clearance game>
My idea is that the mine clearance map is generally a rectangle, because the mobile phone on the circular screen looks abnormal and there is no need to accommodate him, I can use a two-dimensional array of a * B to represent the whole map.
After a map is available, some of the class content in the map will naturally represent mines. In this case, it would be better to do this <nonsense, do not learn>
/**
* 20 indicates that the location is mine.
* <= 10 indicates the number of unopened blocks and surrounding mines.
*> = 10 indicates the number of opened blocks and surrounding mines.
**/
The representation method comes out, and the logic is clear.
I want to open a block. I just need to add 10 to it.
The first step in Java programming is, of course, class first.
Package games;
Import java. util. Random;
Import java. lang. Math;
Class gamelogic {
/** Indicates a 10*10 board */
Private int [] [] pan = new int;
Private Random random; // A Random variable, mainly used to specify which locations are mines
Private int BombNum = 0; // count the total number of mines
/** Whether the game is over */
Private boolean GameOver;
The next step is to initialize the map. First, we need to put a Ray on it. Otherwise, how can we call it mine clearance? After the mine is thrown, we will traverse the map (we are very kind, we have to tell the mine clearance comrade how many mines there are at a certain position, such as: "mines are in the middle of 01, 01, and 12, and chickens are in the middle, at two o'clock, there will be Dongfeng and the like ").

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.