首页 > 代码库 > Android天天数钱游戏源码

Android天天数钱游戏源码

      天天数钱游戏Android源码,很有意思的一款游戏,废话不多说,上源码!

技术分享
技术分享
技术分享
技术分享

Android天天数钱游戏源码   

天天数钱。基于Android游戏代码

模仿Flash游戏http://www.4399.com/flash/145326_4.htm

源码下载 :http://pan.baidu.com/s/1ntn2Iwx

部分代码 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 = !play_music;
		if (play_music == false) {
 
			if (mp != null && mp.isPlaying()) {
				mp.pause();
			}
		} else {
			if (mp != null) {
				mp.reset();
				mp.release();
			}
			mp = MediaPlayer.create(mContext, R.raw.beijing);
			mp.setLooping(true);
			try {
				mp.prepare();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.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 };
	private ImageView img_1, img_2, img_3, img_4;
	private Context mContext;
	private LayoutInflater inflater;
	private Matrix matrix = new Matrix();
	private 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 };
	private 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 {
		@Override
		public void run() {
			// TODO Auto-generated method stub
			mhandler.sendEmptyMessage(-1);
 
		}
 
	}
 
	Handler mhandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
 
			try {
				if (msg.what == 1) {
					jiekou.gameOver(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.cancel(); // 将原任务从队列中移除
						}
 
						mTimerTask = new MyTimerTask(); // 新建一个任务
						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 block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.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 = http://www.mamicode.com/10;>

      源码下载 :http://pan.baidu.com/s/1ntn2Iwx

Android天天数钱游戏源码