Android-->猜拳小游戏
--> 简单的 页面跳转 和 点击事件 的实现...
--> AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dragon.android.fight"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dragon.android.fight.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.dragon.android.fight.OtherActivity">
</activity>
</application> </manifest>
AndroidManifest
--> strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">fight</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="player1">甲方</string>
<string name="player2">乙方</string>
<string name="choose1">石头</string>
<string name="choose2">剪刀</string>
<string name="choose3">布</string>
<string name="sure">出拳</string>
<string name="again">再来一局</string> </resources>
--> fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" > <TextView
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" /> <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/choose1" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose2" /> <RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose3" />
</RadioGroup> <Button
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" /> <ImageView
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" /> </RelativeLayout>
--> activity_other.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff" > <TextView
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" /> <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/choose1" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose2" /> <RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose3" />
</RadioGroup> <Button
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" /> <TextView
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"/> <Button
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" /> <ImageView
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" /> </RelativeLayout>
activity_main
--> 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);
}
}
}
Android-->猜拳小游戏的更多相关文章
- Java猜拳小游戏(剪刀、石头、布)
1.第一种实现方法,调用Random数据包,直接根据“1.2.3”输出“剪刀.石头.布”.主要用了9条输出判断语句. import java.util.Random; import java.util ...
- C#之winform 猜拳小游戏
C#之winform 猜拳小游戏 1.建立项目文件 2.进行界面布局 2.1 玩家显示(控件:label) 2.2 显示玩家进行选择的控件(控件:label) 2.3 电脑显示(控件:label) ...
- 用Java编写的猜拳小游戏
学习目标: 熟练掌握各种循环语句 例题: 代码如下: // 综合案例分析,猜拳案例 // isContinue为是否开始游戏时你所输入的值 char isContinue; //y为开始,n为借宿 S ...
- winform小程序---猜拳小游戏
因为学的时间不长,所以借鉴了一些资料做了这个小程序,大家共同学习,共同进步.感觉很有自信,世上无难事,只怕有心人. using System; using System.Collections.Gen ...
- python学习-6 猜拳小游戏
import random # 调用随机数模块 pc = random.randint(1,3) # 产生1-3的随机数 print("来玩个猜拳游戏吧!") a = '石头' b ...
- 软件工程 Android小游戏 猜拳大战
一.前言 最近学校举办的大学生程序设计竞赛,自己利用课余时间写了一个小游戏,最近一直在忙这个写这个小游戏,参加比赛,最终是老师说自己写的简单,可以做的更复杂的点的.加油 二.内容简介 自己玩过Andr ...
- 微信小程序开发入门学习(1):石头剪刀布小游戏
从今天起开始捣鼓小程序了2018-12-17 10:02:15 跟着教程做了第一个入门实例有兴趣的朋友可以看看: 猜拳游戏布局 程序达到的效果 猜拳游戏的布局是纵向显示了三个组件:文本组件(tex ...
- Java石头剪刀布小游戏
package com.neusoft.test; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.Colo ...
- 介绍一款Android小游戏--交互式人机对战五子棋
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6589025 学习Android系统开发之余,编 ...
- Android使用学习之画图(Canvas,Paint)与手势感应及其应用(乒乓球小游戏)
作为一个没有学习Android的菜鸟,近期一直在工作之外努力地学习的Android的使用. 这周看了下Android的画图.主要是Canvas,Paint等,感觉须要实践下.下午正好有空,就想整一个乒 ...
随机推荐
- php 中的常量
1.__FINE__ 返回当前常量所在的行号. 2.__FILE__ 返回文件的完整路径和文件名. 3.__FUNCTION__ 返回函数名称. 4.__CLASS__ 返回类名称. 5.__METH ...
- 【python】selenium+python自动化测试环境搭建
参考资料: http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html http://www.easonhan.info/python/20 ...
- 使用ajax异步提交表单数据(史上最完整的版本)
额 为啥用这个 不用form呢,因为这个效率高,而且在浏览器中运行程序的时候如果出现bug的话,页面不会显示显示错误信息,提高了用户的体验度. 那么,就来看看把,先给数据库表截个图哈 然后写项目被 我 ...
- Android开发--RelativeLayout的应用
1.简介 relativeLayout为相对布局,它是新版本安卓的默认布局方式.相对布局可以设置一个部件相对于其他部件所在的位置,包括上下左右等等. 2.构建
- Octopus系列之各个页面调用示例2
判断登陆的调用 #if(${islogin}) <span> ${Oct_Welcome} or <a href="${siteurl}customer/logout/&q ...
- PHP批量过滤MYSQL数据库内站外链接和图片
因发现站内很多引用站外文章的链接失效,产生大量的死链接,对于搜索引擎来说是极不友好的,很不利于网站优化,所以站内添加了站外链接过滤功能,对于新加的文章,在添加入库时就自动增加rel="nof ...
- wdcp 打开网页显示 Apache 2 Test Page powered by CentOS
是因为更新过系统,安装并更新了系统自带的apache 执行这个命令即可 #ln -sf /www/wdlinux/init.d/httpd /etc/rc.d/init.d/httpd#reboot
- Node.js 常用工具 util
util 是一个Node.js 核心模块,提供常用函数的集合,用于弥补核心JavaScript 的功能 过于精简的不足. util.inherits util.inherits(constructor ...
- Java中类型的长度
介绍: Java中有8种基本类型,分别是boolean, char, byte, short, int, long, float, double.他们的长度固定,不是对象.对于有必要将基本类型作为对象 ...
- HTML中head里的内容经浏览器解析后全到body里
我从linux服务器nginx上把一个网站迁移到windows的IIS上数据什么的都么有问题,配置好rewrite以后,访问网站,发现样式变动了,网站上方空出了一块我用chrome浏览器的审查元素一看 ...