猜拳游戏php代码,最常见的猜拳小游戏Android代码实现
本文实例为大家分享了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代码实现相关推荐
- python小游戏-16行代码实现3D撞球小游戏!-源码下载
python小游戏-16行代码实现3D撞球小游戏!-源码下载 所属网站分类: 资源下载 > python小游戏 作者:搞笑 链接: http://www.pythonheidong.com/bl ...
- Python四行代码实现的猜数字小游戏,基于thinker,带GUI界面
Python四行代码实现的猜数字小游戏,基于thinker,带GUI界面 from tkinter import * from tkinter import messagebox 导入提示框 from ...
- python50行小游戏_50行python代码实现的贪吃蛇小游戏
50行python代码实现的贪吃蛇小游戏 发布于 2014-09-01 21:26:24 | 1337 次阅读 | 评论: 1 | 来源: 网友投递 Python编程语言Python 是一种面向对象. ...
- 一行Python一行代码制作20款经典小游戏
今天分享一个有趣的Python游戏库freegames,它包含20余款经典小游戏,像贪吃蛇.吃豆人.乒乓.数字华容道等等,依托于标准库Turtle. 我们不仅可以通过1行代码进行重温这些童年小游戏,还 ...
- 用Python代码做一个简单数字小游戏
#作者是一个十三岁的小男孩. 编辑工具 电脑Python 需要模块 random #今日用代码做一个猜数小游戏 #话不多说,上代码!!! import random number = random.r ...
- 教你用Python一行代码制作20款经典小游戏~
今天分享一个有趣的Python游戏库freegames,它包含20余款经典小游戏,像贪吃蛇.吃豆人.乒乓.数字华容道等等,依托于标准库Turtle. 我们不仅可以通过1行代码进行重温这些童年小游戏,还 ...
- python入门小游戏代码20行,python入门小游戏代码
python入门可以做的小游戏 1.Python入门拼图小游戏简单介绍:将图像分为m×n个矩形块,并将图像右下角的矩形块替换为空白块后,将这些矩形块随机摆放成原图像的形状. 2.Python入门推箱子 ...
- C语言小游戏大全,C语言贪吃蛇小游戏(附源码)
一.C语言小游戏大全,C语言贪吃蛇小游戏(附源码) 贪吃蛇小游戏源码和更多C语言课设项目小游戏源码免 费 下 载 链 接 如下: c语言项目课设小游戏源码资料压缩包.zip-C文档类资源-CSDN下载 ...
- 打砖块小游戏php程序,javascript实现打砖块小游戏(附完整源码)
小时候玩一天的打砖块小游戏,附完整源码 在?给个赞? 实现如图 需求分析 1.小球在触碰到大盒子上.左.右边框,以及滑块后沿另一方向反弹,在碰到底边框后游戏结束: 2.小球在触碰到方块之后,方块消失: ...
- 网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码
网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 完整代码下载地址:网页版打地鼠小游戏源代码,网页版打灰太狼小游戏源码 核心代码 <!DOCTYPE html> <html> ...
最新文章
- 用力和应变片计算弹性模量_第4章 力学量传感器.pptx
- qt 初学 创建一个简单的计算器
- php怎么控制递归多少次,关于一个PHP递归处理统计的问题
- SteamVR导致场景相机不正常
- WinAPI: PolylineTo - 绘制一组连续线段(更新当前位置)
- 25 矩阵——QR分解、Householder 矩阵、镜面反射
- 一文看完“阿里云自动化运维沙龙 · 上海专场”整场干货
- UI自动化之PO模式
- poj3281 Dining (最大流)
- Blob如何在html里转换成图片,前端图片canvas,file,blob,DataURL等格式转换
- Make Clobber 和 Make Clean
- 于晓津外头游荡了半天
- 适合普通大众、非科班的路线
- 【DLML】深度学习调参有哪些技巧?
- Python3.X识别混合编码,顺便解决“AttributeError: 'module' object has no attribute 'urlopen'”
- NextCloud安装及配置(docker-compose)
- 2012年3月18日学习
- C# 获取鼠标选中的文字(屏幕取词)
- 服务器pe安装win7系统安装教程,u盘pe重装win7系统图文教程
- Python多线程 坑Unhandled exception in thread started by Error in sys.excepthook