本文实例为大家分享了Android猜拳小游戏,供大家参考,具体内容如下

简单的 页面跳转 和 点击事件 的实现...

--> AndroidManifest.xml

package="com.dragon.android.fight"

android:versionCode="1"

android:versionName="1.0" >

android:minSdkVersion="15"

android:targetSdkVersion="19" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name="com.dragon.android.fight.MainActivity"

android:label="@string/app_name" >

android:name="com.dragon.android.fight.OtherActivity">

AndroidManifest

--> strings.xml

fight

Hello world!

Settings

甲方

乙方

石头

剪刀

出拳

再来一局

--> fragment_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff"

tools:context="com.dragon.android.fight.MainActivity$PlaceholderFragment" >

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="36dp"

android:text="@string/player1"

android:textSize="30sp" />

android:id="@+id/radioGroup1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true" >

android:id="@+id/radio0"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true"

android:text="@string/choose1" />

android:id="@+id/radio1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/choose2" />

android:id="@+id/radio2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/choose3" />

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/radioGroup1"

android:layout_below="@+id/radioGroup1"

android:layout_marginTop="14dp"

android:text="@string/sure" />

android:id="@+id/imageView1"

android:layout_width="120dp"

android:layout_height="120dp"

android:layout_above="@+id/radioGroup1"

android:layout_below="@+id/textView1"

android:layout_centerHorizontal="true"

android:src="@drawable/b" />

--> activity_other.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#ffffff" >

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="36dp"

android:text="@string/player2"

android:textSize="30sp" />

android:id="@+id/radioGroup1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true" >

android:id="@+id/radio0"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true"

android:text="@string/choose1" />

android:id="@+id/radio1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/choose2" />

android:id="@+id/radio2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/choose3" />

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/radioGroup1"

android:layout_below="@+id/radioGroup1"

android:layout_marginTop="14dp"

android:text="@string/sure" />

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textView1"

android:layout_below="@+id/button1"

android:visibility="invisible"

android:layout_marginTop="14dp"/>

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/textView2"

android:layout_centerHorizontal="true"

android:visibility="invisible"

android:text="@string/again" />

android:id="@+id/imageView1"

android:layout_width="120dp"

android:layout_height="120dp"

android:layout_above="@+id/radioGroup1"

android:layout_below="@+id/textView1"

android:layout_centerHorizontal="true"

android:src="@drawable/a" />

--> MainActivity

package com.dragon.android.fight;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.RadioButton;

import android.widget.RadioGroup;

public class MainActivity extends Activity {

// 设置一个静态变量,用于关闭Activity

public static MainActivity instance = null;

private RadioGroup radioGroup1;

private Button button1;

private ImageView imageView1;

@Override

protected void onCreate(Bundle savedInstanceState) {

// 代表当前的Activity

instance = this;

super.onCreate(savedInstanceState);

setContentView(R.layout.fragment_main);

radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);

// 设置图片透明

// imageView1 = (ImageView) findViewById(R.id.imageView1);

// imageView1.getBackground().setAlpha(100);

button1 = (Button) findViewById(R.id.button1);

button1.setOnClickListener(new MyButtonListener());

}

class MyButtonListener implements OnClickListener {

@Override

public void onClick(View v) {

// 得到选中的RadioButton

RadioButton radioButton = (RadioButton) findViewById(radioGroup1

.getCheckedRadioButtonId());

String radioText = radioButton.getText().toString();

Intent intent = new Intent();

intent.putExtra("checked", radioText);

intent.setClass(MainActivity.this, OtherActivity.class);

startActivity(intent);

}

}

}

--> OtherActivity

package com.dragon.android.fight;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.TextView;

public class OtherActivity extends Activity {

private RadioGroup radioGroup1;

private Button button1;

private TextView textView2;

private RadioButton radioButton;

private Button button2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_other);

radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);

button1 = (Button) findViewById(R.id.button1);

textView2 = (TextView) findViewById(R.id.textView2);

button2 = (Button) findViewById(R.id.button2);

button1.setOnClickListener(new MyButtonListener());

button2.setOnClickListener(new MyButtonListener1());

}

class MyButtonListener implements OnClickListener {

@Override

public void onClick(View v) {

radioButton = (RadioButton) findViewById(radioGroup1

.getCheckedRadioButtonId());

String buttonText = radioButton.getText().toString();

Intent intent = getIntent();

String checked = intent.getStringExtra("checked");

// 设置View为可见

textView2.setVisibility(View.VISIBLE);

button2.setVisibility(View.VISIBLE);

String msg = "甲出:" + checked + "\n" + "乙出:" + buttonText

+ "\n";

if (buttonText.equals(checked)) {

textView2.setText(msg + "平局");

}

if (buttonText.equals("石头")) {

if (checked.equals("剪刀")) {

textView2.setText(msg + "乙方赢");

} else if (checked.equals("布")) {

textView2.setText(msg + "甲方赢");

}

}

if (buttonText.equals("剪刀")) {

if (checked.equals("布")) {

textView2.setText(msg + "乙方赢");

} else if (checked.equals("石头")) {

textView2.setText(msg + "甲方赢");

}

}

if (buttonText.equals("布")) {

if (checked.equals("石头")) {

textView2.setText(msg + "乙方赢");

} else if (checked.equals("剪刀")) {

textView2.setText(msg + "甲方赢");

}

}

}

}

class MyButtonListener1 implements OnClickListener {

@Override

public void onClick(View arg0) {

Intent intent = new Intent();

intent.setClass(OtherActivity.this, MainActivity.class);

finish();

// 关闭指定Activity

MainActivity.instance.finish();

startActivity(intent);

}

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

猜拳游戏php代码,最常见的猜拳小游戏Android代码实现相关推荐

  1. python小游戏-16行代码实现3D撞球小游戏!-源码下载

    python小游戏-16行代码实现3D撞球小游戏!-源码下载 所属网站分类: 资源下载 > python小游戏 作者:搞笑 链接: http://www.pythonheidong.com/bl ...

  2. Python四行代码实现的猜数字小游戏,基于thinker,带GUI界面

    Python四行代码实现的猜数字小游戏,基于thinker,带GUI界面 from tkinter import * from tkinter import messagebox 导入提示框 from ...

  3. python50行小游戏_50行python代码实现的贪吃蛇小游戏

    50行python代码实现的贪吃蛇小游戏 发布于 2014-09-01 21:26:24 | 1337 次阅读 | 评论: 1 | 来源: 网友投递 Python编程语言Python 是一种面向对象. ...

  4. 一行Python一行代码制作20款经典小游戏

    今天分享一个有趣的Python游戏库freegames,它包含20余款经典小游戏,像贪吃蛇.吃豆人.乒乓.数字华容道等等,依托于标准库Turtle. 我们不仅可以通过1行代码进行重温这些童年小游戏,还 ...

  5. 用Python代码做一个简单数字小游戏

    #作者是一个十三岁的小男孩. 编辑工具 电脑Python 需要模块 random #今日用代码做一个猜数小游戏 #话不多说,上代码!!! import random number = random.r ...

  6. 教你用Python一行代码制作20款经典小游戏~

    今天分享一个有趣的Python游戏库freegames,它包含20余款经典小游戏,像贪吃蛇.吃豆人.乒乓.数字华容道等等,依托于标准库Turtle. 我们不仅可以通过1行代码进行重温这些童年小游戏,还 ...

  7. python入门小游戏代码20行,python入门小游戏代码

    python入门可以做的小游戏 1.Python入门拼图小游戏简单介绍:将图像分为m×n个矩形块,并将图像右下角的矩形块替换为空白块后,将这些矩形块随机摆放成原图像的形状. 2.Python入门推箱子 ...

  8. C语言小游戏大全,C语言贪吃蛇小游戏(附源码)

    一.C语言小游戏大全,C语言贪吃蛇小游戏(附源码) 贪吃蛇小游戏源码和更多C语言课设项目小游戏源码免 费 下 载 链 接 如下: c语言项目课设小游戏源码资料压缩包.zip-C文档类资源-CSDN下载 ...

  9. 打砖块小游戏php程序,javascript实现打砖块小游戏(附完整源码)

    小时候玩一天的打砖块小游戏,附完整源码 在?给个赞? 实现如图 需求分析 1.小球在触碰到大盒子上.左.右边框,以及滑块后沿另一方向反弹,在碰到底边框后游戏结束: 2.小球在触碰到方块之后,方块消失: ...

  10. 网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码

    网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 完整代码下载地址:网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 核心代码 <!DOCTYPE html> <html> ...

最新文章

  1. 用力和应变片计算弹性模量_第4章 力学量传感器.pptx
  2. qt 初学 创建一个简单的计算器
  3. php怎么控制递归多少次,关于一个PHP递归处理统计的问题
  4. SteamVR导致场景相机不正常
  5. WinAPI: PolylineTo - 绘制一组连续线段(更新当前位置)
  6. 25 矩阵——QR分解、Householder 矩阵、镜面反射
  7. 一文看完“阿里云自动化运维沙龙 · 上海专场”整场干货
  8. UI自动化之PO模式
  9. poj3281 Dining (最大流)
  10. Blob如何在html里转换成图片,前端图片canvas,file,blob,DataURL等格式转换
  11. Make Clobber 和 Make Clean
  12. 于晓津外头游荡了半天
  13. 适合普通大众、非科班的路线
  14. 【DLML】深度学习调参有哪些技巧?
  15. Python3.X识别混合编码,顺便解决“AttributeError: 'module' object has no attribute 'urlopen'”
  16. NextCloud安装及配置(docker-compose)
  17. 2012年3月18日学习
  18. C# 获取鼠标选中的文字(屏幕取词)
  19. 服务器pe安装win7系统安装教程,u盘pe重装win7系统图文教程
  20. Python多线程 坑Unhandled exception in thread started by Error in sys.excepthook

热门文章

  1. mysql数据库 day06
  2. 08 友盟项目--拆分日志为五个表---UDTF自定义函数
  3. 嵌入式linux和pc机的linux对照
  4. 转: CentOS 安装 SVN1.8 客户端
  5. OpenMMLab 生成模型算法库发布,打工人也能玩转图像生成!
  6. MIDL2020赛事object-CXR(胸部X射线异物检测大赛)
  7. 金哥和你一起学模型压缩——结构篇
  8. MIT“35岁以下科技创新35人”榜单揭晓
  9. 清华大学开源迁移学习算法库:基于PyTorch实现已有算法
  10. source insight 4.0 无法同步文件问题