A link to the practice of hellope's Android project-design

Source: Internet
Author: User

This article isThis seriesArticleThe first article only aims to write down the design and implementation process of the android sub-item. This article will first introduce the design of the Connected View project, as well as the relevant content and the project requirements.Algorithm.

This series of articles only adds the practical experience of the android project and applies the learned knowledge to the corresponding project development. First, we will briefly introduce the architecture and technologies used in the Link View Project in Android. The framework is basically as shown in:

BenProgramThere are two main modules: (1) Presentation Layer module; (2) Background logic module;

WherePresentation Layer ModuleIt can be understood as the game UI and some game auxiliary effects. In the presentation layer module, it is important to implement the layout map of the game. In the project implementation, the layout of the game is implemented by creating a custom view on the screen. The menu module and the selected dialog only provide users with some common options, such as re-playing, pass-through, and sound switch. In order to have a better user interaction environment, the implementation of dialog will use the custom dialog method. The game sound effects are played by mediaplayer in different State scenarios.

WhileBackground logic module, Real-time program computing implementation and monitoring of various program states will be the basis for the entire program running. This module monitors and processes the remaining time limit of the game and the game status. Listening for the remaining time of the game will enable separate threads for processing, so as not to affect the running of the main program logic; monitoring and processing of the game status, the two connected icons (updating the game interface) will be eliminated, the game's winning or losing listening judgment will be made, and the game will be suspended or not (the remaining time needs to be paused at the same time, the time listening thread needs to know the status, which is closely related to the two ).The most important thing in this program is the implementation of the Core Algorithm Module in the program.In the game, the main algorithm is to determine whether two selected Icons can be connected, and the other two algorithms also rely on this algorithm. The following describes the connection algorithms:

Before introducing the connection algorithm, let's briefly introduceLayout AlgorithmFor the sake of simplicity, we use the 4*4 chessboard. Assume there are four types of pawns:

First, when the program is initialized, we first draw the picture to be loaded on the board in order,Note that every icon needs to be drawn twice at a time.In this way, the number of icons to be re-drawn is an even number. Assume that, for example, (1 ):

Figure (1) initial drawing (2) Board after replacement

In this way, we will perform a traversal to randomly change the icons in the Board (instead of the icons in the current Board ). As shown in (2), the initialization of the board is completed. Of course, no icon is added to the outermost layer of the Board, in order that we can draw lines at the outermost layer when connecting lines without passing through the icon, the chessboard is as follows:

Now lookConnection AlgorithmPrinciple:

First, the two icons can be connected by the following conditions: (1) The two icons are the same; (2) there is a link between the two icons, there is no other icon in the "road". (3) there cannot be more than two corners on this road. If the three conditions are met, the two icons are considered to be connected; in the connectivity judgment, there are three types of icon Connectivity:

(1) Straight Line: This is to judge the horizontal or vertical direction. In this case, it is easiest to judge, as long as there are no other icons between the two;

(2) one fold: in fact, draw a rectangle on the two diagonal vertices identified by the two selected icons. If any of the other two vertices can be connected to both selected icons with a "straight" pattern, the two selected Icons can be connected. The following example shows how the two red icons are connected:

One-fold instance

(3) Secondary model: it is important to judge the secondary model. The secondary model is used for scanning in two directions, that is, horizontal scanning and vertical scanning:

First, horizontal scanning:

Two red icons to be determined for horizontal scaling. Two of them can meet the requirements of linear connections.

In horizontal scanning: first, scale out the two comparison icons to be judged. The expansion rule is to scale out without any other icons, when other icons or edges of this row are displayed, X indicates in the extended vertex. If the extended vertex type can have two points that meet the connectivity of the linear type, it can be determined that the two icons can be connected, and the connected draw lines are also connected based on the two auxiliary points;

Similarly, for Vertical Scanning:

Two red icons to be determined for vertical expansion and expansion. Two points can meet the "linear" requirement.

Even the connection algorithm is complete. As for the help algorithm of the hint, the algorithms that determine whether there is any solution on the current Board depend on the secondary algorithm.

In this project, the next step is to implement each function module and algorithm step by step. The reason why I wrote this series of articles is to record the experiences of small Android projects, increase practical capabilities, and make a summary. Not just to make a novel project, but also to learn from many netizens!

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.