Android Elite Biography-Jigsaw puzzles puzzle-6 dot spit groove

Source: Internet
Author: User

First, Reason
Often write articles, mixed with some C currency. Recently in-depth study of Android application development, from the mall bought a copy of the "Android Heroes."
The content of this book is not a purely introductory one, divided into several chapters, focusing on activity, animation, etc.
The last chapter is an example of 2 small games, of which 1 are puzzle games.
Careful study of the next author's code, there is no place to disagree, deliberately spit a few sentences.


second, game-related information
Game Name: Jigsaw puzzles, mobile puzzles, sliding puzzles, Pullze
In the search process, found "Huarong" and "Digital push disk game."

Digital Push Game (N-puzzle) is a kind of intelligence game, the common type has 15 digital push disk game and eight digital push disk game and so on. There are also push-plate games that take pictures instead of numbers. Perhaps Noyes Palmer Chapman invented the 15 digital push in 1874, but Sam Loyd also claimed it was invented in 1891.
The eight digital push (aka Reflow Nine) may have been invented by Henry Ernest Dudeney, and Martin Gardner is seeking faster answers in the scientific people. Some people think that rearrangement of nine is a traditional Chinese game, from Luo Book, and the ancestor of Huarong Tao.


Game rules: Players want to move the blocks on the board, so that all the squares in the order of numbers.

After reading the introduction of "Digital Push Game", I found that "puzzle game" is the essence of "digital push disk game."

We designed the picture push game, behind the expression is "digital", "emissions in order."


Three, 6 point spit Groove
1. The core design of the game, very pit.

Asked the next author, he is based on his understanding of the design of this game.
I seriously doubt that he has not played "physical version" of the "mobile jigsaw game", anyway I have played.
So I deliberately seriously spit down his game design.


The game design does not give the force, causes the technical design and the realization, very lets the person be anxious.
Without too much of a problem, I'm going to revamp the standard "mobile jigsaw game" and then share it.


His game interface

N*n a lattice, of which 1 are "empty", in fact, just "pictures" did not show, not strictly the "empty lattice."



Physical version of the game interface
N*n+1 a lattice, there is a lattice specifically "empty", used to exchange, teng position.


2. The variable naming method is not mainstream.
Private View Mpopupview;
Like the Hungarian naming act.
Java and Android development, not all "hump-named" it?
Popupview can do it.

In addition, the Popupview also conforms to the "Convention better than the configuration", Android automatically prompt also more comfortable.

3. Function naming is not accurate.
      public static Displaymetrics Getscreensize (context context) {        Displaymetrics metrics = new Displaymetrics ();        WindowManager WindowManager = (windowmanager) context.getsystemservice (                context.window_service);        Display display = Windowmanager.getdefaultdisplay ();        Display.getmetrics (metrics);        return metrics;    }


The return is Displaymetrics, which contains more than the "size of the screen".
Therefore, you either customize 1 entity classes to wrap the screen size.
Either, it's better to use Getdisplaymetrics.


In contrast, another way of code-like "Get device density" is a bit more accurate and returns float instead of Displaymetrics.
  /**     * Get screen density (density)     *     * @param context     * @return density screen density *     /public    static Float getdevicedensity (Context context) {        Displaymetrics metrics = new Displaymetrics ();        WindowManager WindowManager = (windowmanager) context.getsystemservice (                context.window_service);        Windowmanager.getdefaultdisplay (). Getmetrics (metrics);        return metrics.density;    }



This is a bit more accurate.


Imageutil, there's a way.
public void createinitbitmaps (int type, Bitmap photoselected,context Context);

From the name of the function, it is possible to think that the return is 1 objects, but the result is void. The direct name Initbitmaps better, initialize the object.
In addition, Imageutil is a tool class, and "Bitmap photoselected" This naming method, embodies the business scene, but in fact, purely tool methods, even "Business tools approach" does not count,
Why is it so named?
function is named and function, and is not related to the business, it is easier to use in other projects, in order to play the role of "tool function."

4. Code duplication
Or the above code, the first 3 lines of the Getdevicedensity code and the first 4 lines of the Getscreensize function are the same.
And, from "Windowmanager.getdefaultdisplay (). Getmetrics (metrics);" As can be seen here, the 2nd function is not "copy-paste" modified.

Here, I have a question about getting the Displaymetrics object, why is it passing in a new object instead of getmetrics inside new object and then returning it?

After refactoring the code:
   /**     * Get screen-related parameters     *     * @param context     * @return displaymetrics screen height    */public static Displaymetrics Getdisplaymetrics (Context context) {        Displaymetrics metrics = new Displaymetrics ();        WindowManager WindowManager = (windowmanager) context.getsystemservice (                context.window_service);        Display display = Windowmanager.getdefaultdisplay ();        Display.getmetrics (metrics);        return metrics;    }    /**     * Get screen density (density)     *     * @param context     * @return density screen density    */Public Static float Getdevicedensity (context context) {        Displaymetrics Metrics =getdisplaymetrics (context);        return metrics.density;    }



5. Variable scope is too large.
public class Imageutil {
Public GridItem GridItem;
}
1 public fields are defined, in effect this field is only a local variable of "a function" and is not accessed by other classes.
Therefore, you should not define a separate field, nor should it be public.


In addition, Imageutil is a tool class, since there is no need to define instance fields, it is better to define the method directly as static.
Instead of new Imageutil (). method ();


6. The same string, not extracted into a constant.
Select default Picture Intent intent = new Intent (Mainactivity.this,puzzlemain.class); Intent.putextra ("Picselectedid", mrespicid[ Position]); Intent.putextra ("Mtype", Mtype); startactivity (intent);


There are at least 2 places that use "Picselectedid". It is easy to maintain with constant representation.


More places, do not spit groove ~


Four, the code
A. My own initial refactoring-
Https://git.oschina.net/fansunion/puzzle

B.android-Original Puzzle game
HTTPS://GITHUB.COM/XUYISHENG/ANDROIDHEROES/TREE/MASTER/13. Instance Improvement/xpuzzle

C. Change the game design, add 1 lattice, a large revision, and temporarily still in the study ~ follow-up public ~

Five, written in the last
Many people have read the blogger's "Jigsaw Puzzle series", and some have read the blogger's "Android Heroes" book.
Although in-depth study of Android soon, as a person with many years of programming experience, I still spit groove some better.
Bad is not good, the reasons are placed there.
The author of the Android elite, also need to add oil ~
Related people, look to do ~ (*^__^*)

References

Digital push Disc Game
Http://baike.baidu.com/link?url=qO5ShCCBQavlEn35RepADpAAl_OZ8CuNjYul6QK_v23hB2XtnFXfSoaHvO043ruLY8hzWedi8lLiH1EaOA_P0K

Book "Android Heroes Biography", author blog: Http://blog.csdn.net/eclipsexys

Author's jigsaw column: http://blog.csdn.net/column/details/android-puzzle.html

Android Elite Biography-Jigsaw puzzles puzzle-6 dot spit groove

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.