every day count Money game Android source code, very interesting a game, nonsense not much to say, on the source!
Android Daily count Money game source
Count the money every day. Based on Android game code
Imitate Flash game http://www.4399.com/flash/145326_4.htm
Source Download: http://pan.baidu.com/s/1ntn2Iwx
Section Code Gameview.java
<span style= "FONT-FAMILY:ARIAL;FONT-SIZE:14PX;" >package Com.sx.view; Import Java.io.ioexception;import java.text.decimalformat;import java.util.arraylist;import java.util.Random; Import Java.util.timer;import Java.util.TimerTask; Import Android.annotation.suppresslint;import Android.content.context;import Android.graphics.bitmap;import Android.graphics.matrix;import Android.graphics.drawable.bitmapdrawable;import Android.media.MediaPlayer;import Android.os.handler;import Android.os.message;import Android.util.attributeset;import Android.view.LayoutInflater; Import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.imageview;import Android.widget.relativelayout;import Android.widget.TextView; Import Com.daimajia.androidanimations.library.techniques;import Com.daimajia.androidanimations.library.YoYo; Import COM.SX.TTSQIAN.R; public class Gameview extends Relativelayout implements Onclicklistener {private timeinterface jiekou;private TextView TV _addtime;pRivate Boolean play_music = true;private float usermony = 0.0F; public void Setinterface (Timeinterface _jiekou) {This.jiekou = _jiekou;} public boolean setmusicstate () {play_music =!pla Y_music;if (Play_music = = False) {if (MP! = null && mp.isplaying ()) {Mp.pause ()}}} else {if (MP! = null) {Mp.rese T (); Mp.release ();} MP = Mediaplayer.create (Mcontext, r.raw.beijing); mp.setlooping (true); try {mp.prepare ();} catch ( IllegalStateException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Auto-gene Rated catch Blocke.printstacktrace ();} Mp.start ();} return play_music;} Private techniques[] Anim = new techniques[] {techniques.zoomoutright,techniques.zoomoutleft, Techniques.zoomoutup, Techniques.zoomoutdown, Techniques.slideoutup, Techniques.fadeout,techniques.fadeoutright, Techniques.RollOut, Techniques.rotateoutdownleft, Techniques.takingoff};p rivate ImageView img_1, Img_2, Img_3, Img_4;private Context Mcontext;private Layoutinflater Inflater;privAte matrix matrix = new Matrix ();p rivate MediaPlayer mp;private MediaPlayer mp_great;private MediaPlayer mp_error;private float[] Price = new float[] {1.0F, 10.0F, 100.0F, 20.0F, 5.0f,50.0f, 0.5F, 1.0F, 0.5F, 0.1F, 0.1F, 10.0F, 0.2F, 10.0F}; Private int[] Picid = new int[] {r.drawable.kagaz_1, r.drawable.kagaz_10,r.drawable.kagaz_100, r.drawable.kagaz_20, R.drawable.kagaz_5,r.drawable.kagaz_50, R.drawable.kagaz_5mo, R.drawable.kagaz_kona_1,r.drawable.kagaz_5motatur, R.drawable.kagaz_1mo,r.drawable.kagaz_1motatur, R.drawable.kagaz_kona10,r.drawable.kagaz_2mo, R.drawable.kagaz_ 10tatur};p rivate float allprice = 0.0f;private int time = 45 * 1000; Timer Mtimer; Mytimertask mtimertask;private TextView TV1, TV2, TV3, Tv4;private ImageView Img_good; @SuppressLint ("Newapi") public Gameview (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle); this.mcontext = Context;initview ();} Public Gameview (context context, AttributeSet Attrs) {Super (context, attrs); this.mconteXT = Context;initview ();} Public Gameview (Context context) {super (context); this.mcontext = Context;initview ();} class Mytimertask extends TimerTask {@Overridepublic void Run () {//TODO auto-generated Method Stubmhandler.sendemptymessage (-1);}} Handler Mhandler = new Handler () {@Overridepublic void Handlemessage (Message msg) {try {if (msg.what = = 1) {Jiekou.gameov ER (usermony); } else {time = time-246;if (Time <= 0) {jiekou.updatetime (0); Mhandler.removemessages ( -1); Mhandler.sendemptymessage ( 1); return;} Jiekou.updatetime (time); mtimer = new Timer ();//Game over...if (Mtimer! = null) {if (mtimertask! = null) {Mtimertask.cance L (); Remove the original task from the queue} Mtimertask = new Mytimertask (); Create a new task Mtimer.schedule (Mtimertask, 246);}} catch (Exception ex) {}}}; private void Initview () {usermony = 0.0F; Layoutinflater.from (Mcontext). Inflate (R.layout.gameview, this, true); MP = Mediaplayer.create (Mcontext, r.raw.beijing); mp_great = Mediaplayer.create (Mcontext, r.raw.great); mp_error = Mediaplayer.cReate (Mcontext, R.raw.shibai); mp.setlooping (true); try {mp.prepare ();} catch (IllegalStateException e) {//TODO Auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} try {mp_great.prepare ()} catch (Exception ex) {}try {mp_error.prepare ();} catch (Exception ex) {} mp.start (); img_1 = ( ImageView) Findviewbyid (r.id.img_1) img_2 = (ImageView) Findviewbyid (r.id.img_2); img_3 = (ImageView) Findviewbyid ( R.id.img_3); img_4 = (ImageView) Findviewbyid (r.id.img_4); TV1 = (TextView) Findviewbyid (R.ID.TV1); tv2 = (TextView) Findviewbyid (R.ID.TV2); TV3 = (TextView) Findviewbyid (R.ID.TV3); TV4 = (TextView) Findviewbyid (R.ID.TV4); Tv1.setonclicklistener (This), Tv2.setonclicklistener (This), Tv3.setonclicklistener (this); Tv4.setonclicklistener ( this); Img_good = (ImageView) Findviewbyid (r.id.img_good); tv_addtime = (TextView) Findviewbyid (r.id.txt_addtime); img_ Good.setvisibility (view.invisible); tv_addtime.setvisibility (view.invisible); CreatenEwgameview (false);} public void Createnewgameview (Boolean isOk) {if (Play_music && isOk) {Mp_great.start ();} else if (Play_music & &!isok) {Mp_error.start ();} Random r = new Random (); Random r2 = new Random (), int MaxValue = 10;int index = 0;allprice = 0.0f;index = R.nextint (picid.length); Bitmap Bitmap = ((bitmapdrawable) getresources (). getdrawable (Picid[index]). Getbitmap (); Allprice + = price[index];// Set rotation angle int r2_value = R2.nextint (MaxValue); if (r2_value% 2 = = 0) {R2_value = R2_value * (-1);} Matrix.setrotate (R2_value);//redraw bitmap bitmap = Bitmap.createbitmap (bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix, True); Img_1.setimagebitmap (bitmap); index = R.nextint (picid.length); bitmap = (( bitmapdrawable) getresources (). getdrawable (Picid[index]). Getbitmap (); Allprice + = Price[index]; Set rotation Angle R2_value = R2.nextint (MaxValue), if (r2_value% 2 = = 0) {R2_value = R2_value * (-1);} Matrix.setrotate (R2_value);//Redraw Bitmapbitmap = Bitmap.createbitmap (Bitmap, 0, 0, Bitmap. GetWidth (), Bitmap.getheight (), Matrix, True); Img_2.setimagebitmap (bitmap); index = R.nextint (picid.length); bitmap = ((bitmapdrawable) getresources (). getdrawable (Picid[index])). Getbitmap (); Allprice + = price[index];//Set rotation angle R2_value = R2.nextint (MaxValue); if (r2_value% 2 = = 0) {R2_value = R2_value * (-1);} Matrix.setrotate (R2_value);//Redraw Bitmapbitmap = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix, True); Img_3.setimagebitmap (bitmap); index = R.nextint (picid.length); bitmap = (( bitmapdrawable) getresources (). getdrawable (Picid[index)). Getbitmap (); Allprice + = price[index];//Set rotation angle R2_value = R2.nextint (MaxValue); if (r2_value% 2 = = 0) {R2_value = R2_value * (-1);} Matrix.setrotate (R2_value);//Redraw Bitmapbitmap = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix, True); Img_4.setimagebitmap (bitmap); mhandler.sendemptymessagedelayed (-1, 500); SYSTEM.OUT.PRINTLN ("All Price is:" + allprice); ArrayList result = GetPrice (allprice);//ALLPRIce= (float) (Math.Round (allprice*100)/100), int tv_r_index = R2.nextint (4), if (Tv_r_index = = 0) {Tv1.settext (result.get (0) + "Yuan"), Tv2.settext (Result.get (1) + "Yuan"), Tv3.settext (Result.get (2) + "Yuan"), Tv4.settext (Result.get (3) + "Yuan");} else if (Tv_r_index = = 1) {Tv1.settext (Result.get (1) + "Yuan"), Tv2.settext (result.get (0) + "Yuan"), Tv3.settext (Result.get (2) + "Yuan"); Tv4.settext (Result.get (3) + "Yuan");} else if (Tv_r_index = = 2) {Tv1.settext (Result.get (2) + "Yuan"), Tv2.settext (Result.get (1) + "Yuan"), Tv3.settext (result.get (0) + "Yuan"); Tv4.settext (Result.get (3) + "Yuan");} else if (Tv_r_index = = 3) {Tv1.settext (Result.get (3) + "Yuan"), Tv2.settext (Result.get (1) + "Yuan"), Tv3.settext (Result.get (2) + "Yuan"); Tv4.settext (Result.get (0) + "Yuan");} Random r2=new random (); if (isOk) {img_good.setvisibility (view.visible); tv_addtime.setvisibility (view.visible); index = R2.nextint ( Anim.length); Yoyo.with (Anim[index]). Duration (+) Playon (Img_good); Tv_addtime.settext ("+1750"); Yoyo.with (Techniques.slideoutup). Duration (+). Playon (Tv_adDtime);} else {if (tv_addtime.getvisibility ()! = view.invisible) {tv_addtime.settext ("750"); Yoyo.with (Techniques.slideoutup). Duration (+) Playon (tv_addtime);}} Private ArrayList GetPrice (float price) {float Price4 = price-0.1f; ArrayList result = new ArrayList ();D ecimalformat DecimalFormat = new DecimalFormat (". 00");//The character format of the construction method if the decimal place is less than 2 bits, it will be filled with 0. String p = Decimalformat.format (price);//Format returns the string System.out.println (p); StringBuffer buf = new StringBuffer (); for (int i = 0; i < p.length (); i++) {if (P.charat (i)! = '. ' && P.charat (i)! = ' 0 ') {buf.append (P.charat (i));}} Result.add (P); String newprice = buf.tostring (); float newfloat = float.parsefloat (Newprice); if (Newfloat > 400.00F) {newfloat = Newfloat/100.0f;newprice = Decimalformat.format (newfloat);} Result.add (newprice); newprice = "", if (buf.length () = = 3) {try {newprice = buf.substring (1, 1) + buf.substring (2) + buf.sub String (0, 1) + "." + buf.substring (0, 1) + "0";} catch (Exception ex) {System.out.printlN (ex.getlocalizedmessage ());}} else if (buf.length () = = 2) {newprice = buf.substring (1) + (new Random ()). Nextint (9) + buf.substring (0, 1) + "." + buf.subs Tring (1) + "0";} else if (buf.length () = = 4) {Newprice = buf.substring (3) + buf.tostring (). SUBSTRING (2, 3) + buf.substring (0, 1) + "." + buf . substring (1, 1) + "0";} else {newprice = buf.substring (0, 1) + (new Random ()). Nextint (9) + "." + (new Random ()). Nextint (9) + "0";} Newfloat = Float.parsefloat (Newprice); if (Newfloat > 400.00F) {newfloat = Newfloat/100.0f;newprice = Decimalformat.fo Rmat (newfloat);} Result.add (Newprice); String P4 = Decimalformat.format (Price4); Result.add (p4); return result;} public void Destreyview () {try {mhandler.removemessages ( -1); if (mtimertask!=null) {mtimertask.cancel ();} if (MP! = null) {Mp.reset (); Mp.release ();} if (mp_great! = null) {mp_great.release (); mp_great = null;}} catch (Exception ex) {}} @Overridepublic void OnClick (View arg0) {DecimalFormat DecimalFormat = new DecimalFormat (". 00") ;//The character format of the constructor method here if the decimal is not2-bit, will be 0 to complement. String p = decimalformat.format (Allprice); String SelectText = ""; int id = Arg0.getid (); if (Id > 0) {switch (ID) {Case r.id.tv1:selecttext = Tv1.gettext (). Tostrin g (). Trim (). replace ("meta", ""); Break;case R.id.tv2:selecttext = Tv2.gettext (). toString (). Trim (). replace ("meta", "" "); break ; Case r.id.tv3:selecttext = Tv3.gettext (). toString (). Trim (). replace ("meta", ""); Break;case R.id.tv4:selecttext = Tv4.gettext (). toString (). Trim (). replace ("meta", ""); break;default:break;} float newfloat = float.parsefloat (selecttext), float current = Float.parsefloat (P), if (newfloat = = current) { Createnewgameview (TRUE); Time + = 1750;usermony + = Current;jiekou.updatemony (usermony);} else {Createnewgameview (false); Time-= 750;}} }} </span>
Source Download:
http://pan.baidu.com/s/1ntn2Iwx
Android Daily count Money game source