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等,感觉须要实践下.下午正好有空,就想整一个乒 ...
随机推荐
- JQ写简单的伸缩菜单(内附效果图和源代码)
效果如图: JQ代码就那么几句, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- windows下安装redis和memcached
redis安装: http://www.68idc.cn/help/server/20141128135092.html phpredis下载地址:https://github.com/phpredi ...
- 学的一点点ps
从C语言的代码中解脱开始学ps,看到色彩鲜明的东西,心里只有那么爽.哈哈.只学习3天,虽然只是一些皮毛,可还是学到了一些以前不知道的东西.让我对ps多了很多兴趣,决定以后要自学更多的ps技能.要给图片 ...
- js string to int
一.js中string转int有两种方式 Number() 和 parseInt() <script> var str='1250' ; alert( Number(str) ...
- hdu 2177 取(2堆)石子游戏(威佐夫博奕)
题目链接:hdu 2177 这题不是普通的 Nim 博弈,我想它应该是另一种博弈吧,于是便推 sg 函数打了个 20*20 的表来看,为了方便看一些,我用颜色作了标记,打表代码如下: #include ...
- 将回车键转tab键
//功能:将回车键转tab键$(function () {$('input:text:first').focus();var $enter = $("input[type=text],but ...
- 运用js解决java selenium元素定位问题
一.解决定位并操作uneditable元素 尝试了通过id,xpath等等定位元素后点击都提示Element is not clickable at point 再看了下可以click的元素发现上面有 ...
- Java:Collection List Set
Java:集合 常见集合:List Set List 特点:元素是有序的,而且元素可以重复,因为该集合体系有索引. 常见的三个子类:ArrayList.LinkedList.Verctor List集 ...
- 如何使用 WinInet 时提供下载上载进度信息
概要许多开发人员都使用 WinInet 函数来下载或上载文件在 Internet 上的想要提供一个进度条以指示多少文件传输已完成,但多少就越长.您可以使用以下机制来完成此.Collapse image ...
- JDBC成绩管理系统
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...