The front, the saliva words please skip directly.
Although now not much more popular than before, put on the home page is less than hundreds of of the number of clicks. Perhaps the overall level of the blog Park is also in the direction of water development. Do not talk about those, elder brother has also had a glorious day thousands of clicks, elder brother has also had fans, was called the Great God to guide the problem, although the great God water a bit heavy.
People have vanity is precisely because this motivates me to continue to learn technology, to explore. I have the power to keep publishing technical posts. I'm writing about my own real notional. Experience with technology is not purely control using demo or commercial database projects that kind of code farm-style. There's a little bit of arithmetic or technical skills that belong to my own preference but most IQ levels also in primary school, on the image processing that the number of algorithms used in the principle of more than junior high school IQ level.
From four years forward Crooked Medical film company The post of Tetris has been a constant motivator for me, and I have recorded everything. Do not say to click on the volume to write a novel is also rich.
text, to the blog Park from the writing C # Tetris, probably some friends have forgotten it. So we're going to write Tetris again, but this time it's Android version. Maybe it's the end, maybe it's a new beginning.
The main code in the original C # based on the change basically not how to move, if you have seen the original version at a glance to understand the few classes. The development of the Android platform itself in a few days do not spray.
Game main logic class three games Gamearea shape, there's a point here because C # has a value type for positioning point, not in Java so we'll manually define one for him so that other logic code is not changed.
First of all, the game class, the new game () is not only the initialization of a games, the previous C # version of the game data directly in the form through GDI redraw, game data show to the user this is the most basic. So I let the game class become a custom control inherited from view I can put it in the main interface in this way and the game data changes need to be redrawn when it can be redrawn by the self-brought function.
Other basic code aspects of C # and Java slightly different, such as
Defining a two-dimensional array
C#
1 BOOL [,] gameareaarray;
Java
1 boolean [] gameareaarray;
And in Java, switch seems to only judge the number, I changed the switch code to the IF else if it is fortunately not many.
Android Add event is Setonclicklistener and then put a lot of things in that function inside, this I also not accustomed to familiar with the good.
The interface and controls under Android are configured in an XML tree structure, and all controls that correspond to the code inherit from view. Just from this design idea, he is the same as WPF, the interface to the right of the XML interface on the left. Using this concept to see WinForm or MFC Interface, WinForm or MFC interface that way is like caveman people. WPF also does not have to double-click through hard-coded to add button events like WinForm, personally feel that by hard-coded add button to deal with many drawbacks. WinForm What a beautiful point of the interface to OnPaint what a beautiful point of the interface OnPaint can not be arbitrary design interface. show that the Times are the development of the society is the progress of new things have to learn ah.
Android under the wood has MessageBox.Show () Let me this kind of big old-fashioned sentiment why. The most common is toast.
Block constantly falling original in WinForm with Timeer control, on Android platform temporarily I did not find the Timer control all I used multithreading. Also on the internet probably aimed at the next Java multithreading method and then according to their own requirements to copy a paragraph code.
1 Thread TTT;2TTT =NewThread (NewRunnable () {3 @Override4 Public voidrun () {5 while(true) {6 if(Gg.isover ()) {7 return;8}Else {9 //"Move Down" the game logic (specifically down to where, for example )Ten //These logic is all in the game class inside the judgment operation) One Meksound (Gg.go ()); A } - Try { -Thread.Sleep (1000); the}Catch(interruptedexception e) { - e.printstacktrace (); - } - + } - } + }); ATtt.start ();
But there is a small problem, carefully read the code is aware that the data model behind the Tetris game is a two-dimensional array, where a new thread is opened to perform a "drop" operation of the data. And the interface main thread of the button at the same time to move around the same data or deformation operations, I control the code logic in the game itself will not error but there will be some very magical things such as the block fell into the pit and the like. It's all very clear. The so-called inter-thread data synchronization is required. The parents should fix it themselves.
About audio processing, scoring or anything, it's gotta be a little jingle or something. Otherwise lifeless, especially now this eyeball economy time does not presentation to die faster.
Audio processing I am using the online recommended MediaPlayer for me to be enough. For different types such as scoring what I give different sound effects, the only thing to pay attention to is to return the function before playing after the completion of the collection of resources, or a few of your program can not afford the I tried.
Audio processing:
1 Public voidMeksound (inttype) {2 3 Switch(type) {4 Case1:5M_sound = Mediaplayer.create ( This, R.raw.money);6 M_sound.start ();7M_sound.setoncompletionlistener (NewOncompletionlistener () {8 9 @OverrideTen Public voidoncompletion (MediaPlayer arg0) { One //TODO auto-generated Method Stub A m_sound.release (); - } - }); the Break; - default: - Break; - } + -}
Remember to always take the user as the premise, the score when the sound of gold coins can make the brain disabled users feel happy.
For another little thing, usually the Android app presses the return key instead of prompting "press back to exit the program again". This is actually very simple, press the first record time press the second record time again if the difference is less than two seconds to exit, otherwise give toast prompt "press the return key again exit":
1 Private BooleanM_flagexit =false;2Date Backtime =NewDate ("1900/1/1");3 4 @Override5 Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {6 //TODO auto-generated Method Stub7 if(KeyCode = =keyevent.keycode_back) {8Date Nowtime =NewDate ();9 if(backtime.getyear () = =nowtime.getyear ()Ten&& backtime.getmonth () = =Nowtime.getmonth () One&& backtime.getdate () = =nowtime.getdate () A&& backtime.gethours () = =nowtime.gethours () -&& backtime.getminutes () = =nowtime.getminutes () -&& nowtime.getseconds ()-Backtime.getseconds () <= 2 ) { the return Super. OnKeyDown (KeyCode, event); -}Else { -Backtime =Nowtime; -Toast.maketext ( This, "Press the back key again to exit the game", 500). Show (); + return false; - } + } A return false; at}
Program design as long as you think about the context of this thing, then you can make it successful.
Besides, I also drew a few icons myself with Photoshop, though a little ugly.
The following is the full project code:
Click here to download
Here is an app that can be installed directly:
Click here to download
Who said that C # development can not do Java development. Java is just an egg. Just another set of development platforms are familiar, but ultimately tools.
The phone can also be used with the socket can also be IO various file stream Network flow operation can also think how to draw how to draw, and development interface is also very convenient. This is his mother's computer. When still immersed in the old generation of PC programmer era of the so-called mobile internet era has come to our side old did not keep up with the footsteps of the times to defy AH.
Now leave Crooked Medical film company, is a farewell bar. The quality of the things that may be sent later is gradually worse, or the hair is less. I forgive you, brother.
Please do not delete the administrator
In addition, if the younger brother now wants to change a job 8k/month Chengdu this side can find not, for a four or five-year program ape requirements should not be high bar.