基本信息
源码名称:android 猜扑克 洗牌小游戏 实例 附完整源码下载
源码大小:0.11M
文件格式:.zip
开发语言:Java
更新时间:2013-03-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

android 猜扑克牌游戏 猜中有鼓励 供大家学习哦



前段代码:

 

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@ id/layout1"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<TextView android:id="@ id/mText" android:layout_width="270px"
		android:layout_height="40px" android:text="@string/str_title"
		android:textSize="18sp" android:layout_x="20px" android:layout_y="32px">
	</TextView>
	<ImageView android:id="@ id/mImage01" android:layout_width="71px"
		android:layout_height="96px" android:layout_x="20px" android:layout_y="122px"
		android:src="@drawable/p04">
	</ImageView>
	<ImageView android:id="@ id/mImage02" android:layout_width="71px"
		android:layout_height="96px" android:layout_x="126px"
		android:layout_y="122px" android:src="@drawable/p04">
	</ImageView>
	<ImageView android:id="@ id/mImage03" android:layout_width="71px"
		android:layout_height="96px" android:layout_x="232px"
		android:layout_y="122px" android:src="@drawable/p04">
	</ImageView>
	<Button android:id="@ id/mButton" android:layout_width="118px"
		android:layout_height="wrap_content" android:text="@string/str_button"
		android:layout_x="100px" android:layout_y="302px">
	</Button>
</AbsoluteLayout>

后端代码:

package com.test;

/* import相关class */
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainTest extends Activity {

	private ImageView mImageView01;
	private ImageView mImageView02;
	private ImageView mImageView03;
	private Button mButton;
	private TextView mText;

	private static int[] s1 = new int[] { R.drawable.p01, R.drawable.p02,
			R.drawable.p03 };

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mText = (TextView) findViewById(R.id.mText);
		mImageView01 = (ImageView) findViewById(R.id.mImage01);
		mImageView02 = (ImageView) findViewById(R.id.mImage02);
		mImageView03 = (ImageView) findViewById(R.id.mImage03);
		mButton = (Button) findViewById(R.id.mButton);
		/* 运行洗牌程序 */
		randon();
		/* 替mImageView01添加onClickListener */
		mImageView01.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				/* 三张牌同时翻面,并将未选择的两张牌变透明 */
				mImageView01
						.setImageDrawable(getResources().getDrawable(s1[0]));
				mImageView02
						.setImageDrawable(getResources().getDrawable(s1[1]));
				mImageView03
						.setImageDrawable(getResources().getDrawable(s1[2]));
				mImageView02.setAlpha(100);
				mImageView03.setAlpha(100);
				/* 依有没有猜对来决定TextView要显示的信息 */
				if (s1[0] == R.drawable.p01) {
					Toast toast = Toast.makeText(MainTest.this, "表扬一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("哇!你猜对了喔!!拍拍手!");
				} else {
					Toast toast = Toast.makeText(MainTest.this, "批评一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("你猜错了喔!!要不要再试一次?");
				}
			}
		});

		/* 替mImageView02添加onClickListener */
		mImageView02.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				/* 三张牌同时翻面,并将未选择的两张牌变透明 */
				mImageView01
						.setImageDrawable(getResources().getDrawable(s1[0]));
				mImageView02
						.setImageDrawable(getResources().getDrawable(s1[1]));
				mImageView03
						.setImageDrawable(getResources().getDrawable(s1[2]));
				mImageView01.setAlpha(100);
				mImageView03.setAlpha(100);
				/* 依有没有猜对来决定TextView要显示的信息 */
				if (s1[1] == R.drawable.p01) {
					Toast toast = Toast.makeText(MainTest.this, "表扬一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("哇!你猜对了喔!!拍拍手!");
				} else {
					Toast toast = Toast.makeText(MainTest.this, "批评一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("你猜错了喔!!要不要再试一次?");
				}
			}
		});

		/* 替mImageView03添加onClickListener */
		mImageView03.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				/* 三张牌同时翻面,并将未选择的两张牌变透明 */
				mImageView01
						.setImageDrawable(getResources().getDrawable(s1[0]));
				mImageView02
						.setImageDrawable(getResources().getDrawable(s1[1]));
				mImageView03
						.setImageDrawable(getResources().getDrawable(s1[2]));
				mImageView01.setAlpha(100);
				mImageView02.setAlpha(100);
				/* 依有没有猜对来决定TextView要显示的信息 */
				if (s1[2] == R.drawable.p01) {
					Toast toast = Toast.makeText(MainTest.this, "表扬一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("哇!你猜对了喔!!拍拍手!");
				} else {
					Toast toast = Toast.makeText(MainTest.this, "批评一下",
							Toast.LENGTH_SHORT);
					toast.show();
					mText.setText("你猜错了喔!!要不要再试一次?");
				}
			}
		});

		/* 点击Button后三张牌都翻为背面且重新洗牌 */
		mButton.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				mText.setText("猜猜看红心A是哪一张?");
				mImageView01.setImageDrawable(getResources().getDrawable(
						R.drawable.p04));
				mImageView02.setImageDrawable(getResources().getDrawable(
						R.drawable.p04));
				mImageView03.setImageDrawable(getResources().getDrawable(
						R.drawable.p04));
				mImageView01.setAlpha(255);
				mImageView02.setAlpha(255);
				mImageView03.setAlpha(255);
				randon();
			}
		});
	}

	/* 重新洗牌的程序 */
	private void randon() {
		for (int i = 0; i < 3; i  ) {
			int tmp = s1[i];
			int s = (int) (Math.random() * 2);
			s1[i] = s1[s];
			s1[s] = tmp;
		}
	}

}