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

--> 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-->猜拳小游戏的更多相关文章

  1. Java猜拳小游戏(剪刀、石头、布)

    1.第一种实现方法,调用Random数据包,直接根据“1.2.3”输出“剪刀.石头.布”.主要用了9条输出判断语句. import java.util.Random; import java.util ...

  2. C#之winform 猜拳小游戏

    C#之winform 猜拳小游戏 1.建立项目文件 2.进行界面布局 2.1 玩家显示(控件:label) 2.2  显示玩家进行选择的控件(控件:label) 2.3 电脑显示(控件:label) ...

  3. 用Java编写的猜拳小游戏

    学习目标: 熟练掌握各种循环语句 例题: 代码如下: // 综合案例分析,猜拳案例 // isContinue为是否开始游戏时你所输入的值 char isContinue; //y为开始,n为借宿 S ...

  4. winform小程序---猜拳小游戏

    因为学的时间不长,所以借鉴了一些资料做了这个小程序,大家共同学习,共同进步.感觉很有自信,世上无难事,只怕有心人. using System; using System.Collections.Gen ...

  5. python学习-6 猜拳小游戏

    import random # 调用随机数模块 pc = random.randint(1,3) # 产生1-3的随机数 print("来玩个猜拳游戏吧!") a = '石头' b ...

  6. 软件工程 Android小游戏 猜拳大战

    一.前言 最近学校举办的大学生程序设计竞赛,自己利用课余时间写了一个小游戏,最近一直在忙这个写这个小游戏,参加比赛,最终是老师说自己写的简单,可以做的更复杂的点的.加油 二.内容简介 自己玩过Andr ...

  7. 微信小程序开发入门学习(1):石头剪刀布小游戏

    从今天起开始捣鼓小程序了2018-12-17   10:02:15 跟着教程做了第一个入门实例有兴趣的朋友可以看看: 猜拳游戏布局 程序达到的效果 猜拳游戏的布局是纵向显示了三个组件:文本组件(tex ...

  8. Java石头剪刀布小游戏

    package com.neusoft.test; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.Colo ...

  9. 介绍一款Android小游戏--交互式人机对战五子棋

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6589025 学习Android系统开发之余,编 ...

  10. Android使用学习之画图(Canvas,Paint)与手势感应及其应用(乒乓球小游戏)

    作为一个没有学习Android的菜鸟,近期一直在工作之外努力地学习的Android的使用. 这周看了下Android的画图.主要是Canvas,Paint等,感觉须要实践下.下午正好有空,就想整一个乒 ...

随机推荐

  1. 继续Kanzi

    转眼间,Kanzi已经发展到3.3版本了,之前研究过的东西,今天有空下了个版本跟进更新看看有没有什么变化.新的引擎跟以前2.x版本有很大的差别.新引擎增加了很多新功能(包括局部刷新技术),也跟随大潮加 ...

  2. 《BI那点儿事》数据流转换——审核

    审核转换允许对数据流添加审核审核数据,以往使用HIPPA和Sarbanes-Oxley (SOX)时,必须跟踪谁在什么时插入数据,审核转换可以实现这种功能.例如要跟踪那一个task向表里插入数据,可以 ...

  3. HQL 参数绑定、唯一结果、分页、投影总结(下)

    分页: 在用hibernate封装的分页方法前,我们先回顾一下,Oracle里面原生分页做法 --分页查询 --(pageNo-1)*pagesize=起始行 pageNo*pagesize=结束行 ...

  4. Evolutionary Computing: 2. Genetic Algorithm(1)

    本篇博文讲述基因算法(Genetic Algorithm),基因算法是最著名的进化算法. 内容依然来自博主的听课记录和教授的PPT. Outline 简单基因算法 个体表达 变异 重组 选择重组还是变 ...

  5. MySQL 死锁问题分析

    转载: MySQL 死锁问题分析 线上某服务时不时报出如下异常(大约一天二十多次):"Deadlock found when trying to get lock;". Oh, M ...

  6. CSS权重及样式优先级问题

    CSS权重值计算 一条样式规则的整体权重值包含四个独立的部分:[A, B, C, D]; (1) A 表示内联样式(写在标签的style属性中),只有 1 或者 0 两个值:对于内联样式,由于没有选择 ...

  7. 关于ecshop的那些故事

    1.php下foreach()错误提示Warning: Invalid argument supplied for foreach() 错误提示:Warning: Invalid argument s ...

  8. session没有过期,其保存的数据无故丢失的原因

    问题: 我们经常会做到的一个功能,将登录用户信息保存到session中,在页面上显示登录用户名.但是,如果很短时间内甚至几秒没有刷新这个页面的话,这个用户名就消失了,其实就是session中保存的用户 ...

  9. IEnumerable接口的Aggregate方法

    以前小猪为了累加一个集合中的类容通常会写出类似这样的C#代码: string result ="": foreach (var item in items) { result+=i ...

  10. iOS开发UI篇—模仿ipad版QQ空间登录界面

    iOS开发UI篇—模仿ipad版QQ空间登录界面 一.实现和步骤 1.一般ipad项目在命名的时候可以加一个HD,标明为高清版 2.设置项目的文件结构,分为home和login两个部分 3.登陆界面的 ...