Or the android version of Tetris, And the android version of Tetris.

Source: Internet
Author: User

Or the android version of Tetris, And the android version of Tetris.

Skip the previous step.

Although it is no longer popular than before, there are less than a few hundred clicks on the home page. Maybe the overall level of the blog Park is also in the direction of water. If you don't talk about those things, you will have a brilliant experience with thousands of clicks a day, and you will also have fans. Even though this is a little bit of water, you will be called a great God by your younger sister.

People are vanity because it inspires me to continue learning technology and explore it. This gives me the motivation to continue posting technical blog posts. I have written my own practical experience on technology, not just code farming like demo or commercial database projects. There are a little bit of algorithms or technical skills that belong to my own preferences, but most of my IQ levels are elementary, and the algorithm principles used in image processing are a little higher than junior high school IQ.

Since four years ago, medical film company's blog post on Tetris has been continually inspiring me, And I have recorded everything. If you don't talk about the clicks, you have to write a novel and there is still money.

 

From the beginning of Writing c # Tetris in the blog garden, some friends may have forgotten it. Then we will write about tetris, but this time it is for android. It may be the end, or a new start.

The main code is basically not changed based on the original c #. If you have seen the original version, you will understand the several classes. For android platform development, you should not read the book for a few days.

The main logic of the game is three game gamearea shapes. Here there are multiple points because c # contains the value type point for positioning, if java does not exist, we can manually define a logic code for it to avoid modifying other logic code.

First, let's talk about the game class. new game () indicates that a game is initialized. In the previous c # version, game data is directly re-painted in the form through gdi, which is the most basic for displaying game data to users. So I changed the game class to a custom control to inherit from the view. In this way, I can put it on the main interface. When game data is changed and needs to be re-painted, I can re-paint it using the built-in function.

In other basic code aspects, c # is slightly different from java, for example

Define a two-dimensional array

C #

1 bool[,] gameAreaArray;

Java

1 boolean [][] gameAreaArray;

In addition, the switch in java seems to only be able to judge numbers. I changed the switch code to if else if. Fortunately, there are not many.

In android, setonClickListener is used to add events and write a bunch of things in that function. I am not familiar with this yet.

The interfaces and controls in android are configured in the xml tree structure, and all controls corresponding to the Code are inherited from the view. From the perspective of this design philosophy, it is the same as that of wpf. The Code interface on the right of the xml interface on the left is shown. Use this idea to look at the winform or mfc interface. The winform or mfc interface is like a hacker. Unlike winform, wpf must double-click to add button events by hard encoding. In my opinion, adding buttons by hard encoding has many drawbacks. Winform has a nice UI. onPaint has a nice UI. onPaint cannot be designed as needed. It means that the times are a developing society and new things of progress.

Messagebox. show () is available in the lower part of android, which makes me feel awkward. The most commonly used is toast.

The box keeps falling. I used the timeer control in winform. On the android platform, I didn't find all the timer controls, so I used multiple threads. I also probably aimed at java's multi-thread processing method on the Internet and copied the code segment according to my own requirements.

1 Thread ttt; 2 ttt = new Thread (new Runnable () {3 @ Override 4 public void run () {5 while (true) {6 if (gg. isOver () {7 return; 8} else {9 // perform the "Move Down" Operation on the game logic (the specific move down to where, for example, and how 10 // all these logics are determined in the game class operation) 11 mekSound (gg. go (); 12} 13 try {14 Thread. sleep (1000); 15} catch (InterruptedException e) {16 e. printStackTrace (); 17} 18 19} 20} 21}); 22 ttt. start ();

But there is a small problem. I have read the code carefully and know that the data model behind this Tetris game is a two-dimensional array. Here, a new thread is opened to execute the "Drop" Operation on the data. The buttons of the main thread on the interface also need to move or deform the same data, my code logic controls that the game itself won't report errors, but there will be some amazing things, such as falling into the trap. All of them clearly understand the need for so-called inter-thread data synchronization. please fix it yourself.

 

When it comes to audio processing, You have to jingle The score or something, or else it will be dead, especially in this eye-catching economy era.

I use the built-in Mediaplayer recommended for audio processing. It is sufficient for me. For different types of sound effects, such as scores, the only note is that resources are reclaimed after the function is played back before playback, otherwise, you may not be able to get started with your program. I tried it.
Audio Processing:

 1 public void mekSound(int type) { 2  3         switch (type) { 4                 case 1: 5             m_sound = MediaPlayer.create(this, R.raw.money); 6             m_sound.start(); 7             m_sound.setOnCompletionListener(new OnCompletionListener() { 8  9                 @Override10                 public void onCompletion(MediaPlayer arg0) {11                     // TODO Auto-generated method stub12                     m_sound.release();13                 }14             });15             break;16         default:17             break;18         }19 20     }

Remember to always take the user as the premise. The voice of the gold coins obtained at a time can make the users with brains feel happy.


About another small item, generally, when the android program presses the return key, doesn't the system prompt "re-Press return to exit the program. This is actually very simple. Press the record time at the first record time and the second record time to exit if the time difference is less than two seconds. Otherwise, the toast prompts "press the return key again ":

1 private boolean m_flagExit = false; 2 Date backTime = new Date ("1900/1/1"); 3 4 @ Override 5 public boolean onKeyDown (int keyCode, KeyEvent event) {6 // TODO Auto-generated method stub 7 if (keyCode = KeyEvent. KEYCODE_BACK) {8 Date nowTime = new Date (); 9 if (backTime. getYear () = nowTime. getYear () 10 & backTime. getMonth () = nowTime. getMonth () 11 & backTime. getDate () = nowTime. getDate () 12 & backTime. getHours () = nowTime. getHours () 13 & backTime. getMinutes () = nowTime. getMinutes () 14 & nowTime. getSeconds ()-backTime. getSeconds () <= 2) {15 return super. onKeyDown (keyCode, event); 16} else {17 backTime = nowTime; 18 Toast. makeText (this, "re-Press the return key to exit the game", 500 ). show (); 19 return false; 20} 21} 22 return false; 23}


In programming, as long as you carefully think about the ins and outs of this task, you can make it successful.

In addition, I used photoshop to draw Several icons, although a little ugly.

The complete project code is as follows:
Click here to download

Here is the app that can be directly installed:

Click here to download

Who said that c # development won't be able to do java development. Java is just another development platform, but it is just a tool.

On the mobile phone, you can also use socket or I/O for various file stream network flow operations. You can also think about how to plot and Develop interfaces conveniently. This is the computer. When we are still immersed in the era of PC programmers of the old generation, the so-called mobile Internet era has come to our side and we are not satisfied with the pace of the times.

Now the company that leaves medical film is saying goodbye. It is possible that the quality of the items to be sent in the future is gradually poor, or the number of items to be sent is relatively small. Thank you!


Where is there a fun and interesting Russian box game for children? Android supports full screen touch.

Cool? I remember playing a game called "Children's so" in Le 'an, which is suitable for children and some piano and painting software.
 
Which version of Tetris is the most fun?

Classic drop, I personally think this should be the best.

Www.baidu.com/..?b0=e6

Find it by yourself.

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.