Framework Design for Android Game Development

Source: Internet
Author: User
Before that, I want to insert an external question and write it to my friends who are just getting started. I have also been engaged in Game Development for a period of time (mainly using j2's). Although it has not been a long time, I have come up with this phenomenon in the past two years: I found that many games are based on one"State machine"I personally think this form is not very good, a lot of cases... Case... It looks messy and the Code's maintainability is not strong.

  1. Switch (state ){
  2. Case 1:
  3. Brake;
  4. Case 2:
  5. Brake;
  6. ....
  7. }

Copy code

Therefore, I propose"MVC-like" patternTo solve this problem, it is also the purpose of this post. We will share this forum with you to discuss and make progress together!Note: my approach is not the most appropriate. You are welcome to give suggestions.

What is the so-called "MVC-like" pattern ???
Thoughts:
1. Extract the "canvas" originally inherited from the view to form a uimanager. The uimanager is only responsible for managing every UI and does not contain drawing, logic processing, and other code, it is more like a container with many UIS in it, so there is a concept of "layer.

2. Define a UI interface and define the methods. Let its implementation class rewrite the plotting, logical processing, button event processing, touch processing, and so on. In this way, different UIS have their own unique implementation methods to separate them from the canvas. Avoid writing a lot of code on the canvas. You must use case to determine the game status in a traditional way.

3. The next step is to implement the UI interface for each State of the game and rewrite the corresponding method. When the game needs to display a UI, we only need to put the UI into the container of the uimanager to process the corresponding logic of the UI. This saves a lot of trouble.

Benefits:
1. Remove the game UI from the "canvas" to facilitate UI management, instead of the traditional "state machine" mechanism. If it is developed by a team, you can divide the work by functional modules to reduce mutual interference.

2. There is a "layer" concept between the UI and the UI, which makes switching easier. For example, in an RPG Game, if a role backpack is opened, the game will be returned. You only need to remove the UI at the top of the uimanager from the arraylist. to display the UI again, you can add a new UI to the uimanager. Convenient!

It is also mentioned that if you need to add some controls (edittext, button, etc.) In this mode, you need to do some special processing. Because Android UI operations are not thread-safe and must be executed in the UI thread. You can use activity. runonuithread (runnable.

Finally, I have attached my Android-based debut, job search... However, it is not 100% completed yet.

Porting Flash games-frontline laser tower-First Attack

June 12 Modification
Source code description:

1. The progress is about 60%

2. This article is written only because the demo is written as a state machine. If you are not interested, take a look.

3. Publishing the source code promotes the common progress and mutual learning.

4. Android sdks 1.5

Binfileinput. Java class modified on the 16th floor... added the decryption time test.

June 18 Modification

Because I have been busy with some graduation documents...

Failed to rush to upload resources for this game...

Now upload all resources at a time. Frontline laser tower resources (including PS files) & source images (not processed)

Welcome to all walks of life

Today, September 6.21 is very sad and heartbroken. I received a notice from the school saying that I had not chosen enough electives and delayed my graduation for one year!

It took me half a year to submit this work to the school. In addition to being sad, I don't know what else I can say ...........

10. jpg(25.46 KB)

 

11. jpg(18.45 KB)

 

1. jpg(39.75 KB)

 

2. jpg(30.25 KB)

 

3. jpg(26.96 KB)

 

4. jpg(32.23 KB)

 

5. jpg(33.41 KB)

 

6. jpg(43.5 KB)

 

7. jpg(34.45 KB)

 

8. jpg(35.24 KB)

 

9. jpg(46.34 KB)

 

Front Line. rar (2.77 MB)

 

 

Source code

Frontline.apk (1001.36 KB)

 

 

Installation Package

Frontend laser tower Resource (including psfile ).rar (5.38 MB)

 

 

Source image (unprocessed ).rar (4.56 MB)

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.