This section provides you with a knowledge of the physics game and explains the writing of a simple round freefall demo. Java Code PackageCom.himi; ImportJava.util.Random; ImportJava.util.Vector; ImportAndroid.content.Context; ImportAndroid.graphics.Canvas; ImportAndroid.graphics.Color; ImportAndroid.graphics.Paint; ImportAndroid.util.Log; Importandroid.view.KeyEvent; ImportAndroid.view.SurfaceHolder; ImportAndroid.view.SurfaceView; ImportAndroid.view.SurfaceHolder.Callback; Public classMysurfacevieeextendsSurfaceviewImplementsCallback, Runnable {PrivateThread th; PrivateSurfaceholder SFH; PrivateCanvas Canvas; PrivatePaint paint; Private BooleanFlag; Public Static intScreenw, Screenh; PrivateVector<myarc> VC;//this defines the container for our custom circular PrivateRandom ran;//The library is immediately PublicMysurfaceviee (Context context) {Super(context); This. Setkeepscreenon (true); VC=NewVector<myarc>(); Ran=NewRandom ();//Remark 1SFH = This. Getholder (); Sfh.addcallback ( This); Paint=NewPaint (); Paint.setantialias (true); Setfocusable (true); } Public voidsurfacecreated (Surfaceholder holder) {flag=true;//here is the last one just said ... th =NewThread ( This); Screenw= This. getwidth (); Screenh= This. GetHeight (); Th.start (); } Public voidDraw () {Try{Canvas=Sfh.lockcanvas (); Canvas.drawcolor (Color.Black); if(VC! =NULL) {//when the container is not empty, iterate through all the circular drawing methods in the container for(inti = 0; I < vc.size (); i++) {Vc.elementat (i). Drawmyarc (canvas, paint); } } } Catch(Exception e) {//Todo:handle Exception}finally { Try { if(Canvas! =NULL) sfh.unlockcanvasandpost (canvas); } Catch(Exception E2) {}}} Private voidLogic () {//Master Logic if(VC! =NULL) {//when the container is not empty, traverse all the circular logic in the container for(inti = 0; I < vc.size (); i++) {Vc.elementat (i). logic (); } }} @Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) { //when the key event responds, we still have our circle instance in the containerVc.addelement (NewMyarc (Ran.nextint ( This. GetWidth ()), Ran.nextint (+), Ran.nextint (50))); return true; } Public voidrun () {//TODO auto-generated Method Stub while(flag) {logic (); Draw (); Try{Thread.Sleep (100); } Catch(Exception ex) {}}} Public voidSurfacechanged (Surfaceholder holder,intFormatintWidthintheight) {LOG.V ("Himi", "surfacechanged"); } Public voidsurfacedestroyed (Surfaceholder holder) {flag=false; }} OK, the code is very simple, but also very clear! A little bit: like Myarc inside there are similar to Mysurfaceview in the same way logic () and draw (), so that we can better manage our code structure, clear thinking, do their duty, to avoid confusion.