Android--Android扑克牌猜点小游戏
来源:互联网 发布:java编程兵书 编辑:程序博客网 时间:2024/05/22 01:49
该游戏是简单的猜点游戏,1 点为正确的点数
java代码:
package com.mrzhu.test0109_project;import java.util.Random;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;public class Main extends Activity { private ImageView imav1; private ImageView imav2; private ImageView imav3; private Button reset;//重新开始按钮 private TextView content;//显示结果 private int[] arr;//0到2的数组,用于洗牌 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //取得控件 imav1 = (ImageView) findViewById(R.id.imv1); imav2 = (ImageView) findViewById(R.id.imv2); imav3 = (ImageView) findViewById(R.id.imv3); reset = (Button) findViewById(R.id.reset); content = (TextView) findViewById(R.id.content); //为重新开始按钮设置监听 reset.setOnClickListener(new resetOnClickListener()); } //判断点击了哪个牌,响应相应事件 public void click(View v){ if(v.getId() == imav1.getId()){ imav1Click(); }else if(v.getId() == imav2.getId()){ imav2onClick(); }else if(v.getId() == imav3.getId()){ imav3onClick(); } } //单击了第一张牌响应的事件 public void imav1Click() { retu(); if(arr[0] == 0) content.setText("恭喜你,你猜对了!"); else content.setText("哦哦,猜错了!"); imav2.setAlpha(100); imav3.setAlpha(100); imav2.setClickable(false); imav3.setClickable(false); } //单击了第二张牌响应的事件 public void imav2onClick() { retu(); if(arr[1] == 0) content.setText("恭喜你,你猜对了!"); else content.setText("哦哦,猜错了!"); imav1.setAlpha(100); imav3.setAlpha(100); imav1.setClickable(false); imav3.setClickable(false); } //单击了第三张牌响应的事件 public void imav3onClick() { retu(); if(arr[2] == 0) content.setText("恭喜你,你猜对了!"); else content.setText("哦哦,猜错了!"); imav1.setAlpha(100); imav2.setAlpha(100); imav1.setClickable(false); imav2.setClickable(false); } //重新开始按钮事件 public class resetOnClickListener implements OnClickListener{ public void onClick(View v) { imav1.setImageResource(R.drawable.p04); imav2.setImageResource(R.drawable.p04); imav3.setImageResource(R.drawable.p04); imav1.setAlpha(255); imav2.setAlpha(255); imav3.setAlpha(255); content.setText("猜猜看"); imav1.setClickable(true); imav2.setClickable(true); imav3.setClickable(true); } } //翻牌时调用的方法,生成不重复的随机数加到数组中,设置控件显示的图片 private void retu(){ Random random = new Random(); arr = new int[3]; for(int i = 0; i < 3; ++i){ int index = random.nextInt(3); if(arr[index] != 0) i--; else arr[index] = i; } imav1.setImageResource(R.drawable.p01 + arr[0]); imav2.setImageResource(R.drawable.p01 + arr[1]); imav3.setImageResource(R.drawable.p01 + arr[2]); }}
main.xml代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/content" android:textSize="20px" android:text="猜猜看" /> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/p04" android:id="@+id/imv1" android:onClick="click" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/p04" android:id="@+id/imv2" android:onClick="click" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/p04" android:id="@+id/imv3" android:onClick="click" /> </LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="重新开始" android:id="@+id/reset" /></LinearLayout>
资源下载地址:http://download.csdn.net/detail/zlqqhs/4977126
- Android--Android扑克牌猜点小游戏
- C++小游戏:扑克牌21点
- android小游戏“24点”放源码了!!
- android-猜数小游戏
- Android小游戏------猜数字
- Android 小游戏
- Java扑克牌小游戏
- Android 小项目之---猜扑克牌游戏 (附源码)
- 设计一个Android关于24点的小游戏之一(24点算法设计)
- Android小游戏_猜拳
- android猜拳小游戏
- android---猜拳小游戏
- Android弹球小游戏
- Android 猜拳小游戏
- android Splashy Flash小游戏
- android 美女拼图小游戏
- ”数独“android小游戏
- Android 小游戏 2048
- 图片垂直水平居中
- 一个猥琐的方法:解决模板类静态成员重定义的问题
- csdn编辑错误了。。。O(∩_∩)O~
- read_xml
- 分享自制的php分页类
- Android--Android扑克牌猜点小游戏
- IE7和IE9中的几个小小javascript兼容问题
- CABasicAnimation
- USACO1.2.4 Palindromic Squares(回文平方数)
- CALayer Animatable Properties
- 如何进行有效沟通
- leetcode 24: Maximum Depth of Binary Tree
- 谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词(转)
- SQL Server Error Log 管理