Android game development-my little game 2-the basic module design of the connected Game 1

Source: Internet
Author: User

In fact, there is not much to talk about in the connected video games. The most important thing is the connected video games.AlgorithmA little more complicated. In fact, there are not many difficulties. First, let's take a look at what kind of effects our game will achieve. Because I like July May very much, I use idol pictures for the background.

Without considering algorithms, the most important thing here is the processing of the connected classes. One is the piece class, which mainly represents the object of each square area in the Link View, the second is the piecemanager class. From the name of this class, we can see that this class is used to process all operations on the square, such as how to obtain and arrange images, the last question is about how to know which image we click. Here we use a two-dimensional array to represent all the images in it, and the image ID to represent each image, the same image ID is the same.

BelowCode

 
Public class piece {private context; // width and height of each image private int id = 0; Public piece (context, int ID) {This. context = context; this. id = ID;} public int GETID () {return ID;} public bitmap getimage () {return bitmapfactory. decoderesource (context. getresources (), GETID ();} public int getwidth () {return getimage (). getwidth ();} public int getheight () {return getimage (). getheight ();}}
// Management method of each small square public class piecemanager {private activity context; Private piece [] [] pieces = new piece [8] [8]; private partition list <piece> partition list = new partition list <piece> (); int id = 0; Public piecemanager (context) {This. context = (mainactivity) context; // obtain the height and width of an image by obtaining the ID of an image. getresources (). getidentifier ("image0", "drawable", context. getpackagename ();} public piece [] [] getimage () {for (INT I = 0; I <16; I ++) {int id = context. getresources (). getidentifier ("image" + I, "drawable", context. getpackagename (); // because 64 images are required and paired with each other, you only need to select 32 images. In order to make the selected images look even, we first retrieve none of the images in it, and then randomly retrieve the random list if it is not enough. add (new piece (context, ID); items list. add (new piece (context, ID);} // Changes to 64 member lists. addall (collections list); // randomly arrange the images in the collection list. shuffle (sort list); For (INT I = 0; I <8; I ++) {for (Int J = 0; j <8; j ++) {pieces [I] [J] = names list. get (I * 8 + J) ;}} return pieces;} public int getpiecewidth () {return new piece (context, ID ). getwidth ();} public int getpieceheight () {return new piece (context, ID ). getheight ();}}

Related Article

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.