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等,感觉须要实践下.下午正好有空,就想整一个乒 ...
随机推荐
- Kanzi Studio中的概念
Kanzi Studio是Kanzi的UI编辑器,功能非常强大.在使用Kanzi Stadio之前,首先要先熟悉编辑器中的概念. Kanzi Studio中主要分project窗格,property窗 ...
- Json不知道key值情况下获取第一个键值对
JObject jsonData = new JObject(); jsonData.Add("1", "1"); jsonData.Add("2&q ...
- html5 drag and drop
注:链接.图片默认是draggable的. mousemove在整个拖放的过程中不会被触发. dragStart设置: e.dataTransfer.effectAllowed = "mov ...
- c读写文件
#include<stdio.h> void main(void) { // locate ]; scanf("%s", filename); getchar(); / ...
- caffe中python接口的使用
下面是基于我自己的接口,我是用来分类一维数据的,可能不具通用性: (前提,你已经编译了caffe的python的接口) 添加 caffe塻块的搜索路径,当我们import caffe时,可以找到. 对 ...
- Google Volley框架源码走读
PS一句:最终还是选择CSDN来整理发表这几年的知识点,该文章平行迁移到CSDN.因为CSDN也支持MarkDown语法了,牛逼啊! [工匠若水 http://blog.csdn.net/yanb ...
- 获得省市 json 后台代码
string connString = ConfigurationManager.ConnectionStrings["connStr"].ToString(); SqlConne ...
- netbean快捷键
1.Application应用程序的参数args的设置,在Build->Set Main Projects Configuration 2.程序运行快捷键F6 3.@Deprecated 4.代 ...
- Caché数据库学习笔记(2)
目录: 创建新类(表)(class文件)与创建routine(.mac .inc) 在类里面添加函数(classmethod) Terminal的使用 ======================= ...
- (36)老版和新版API调用
---------更新时间18:06 2016-09-18 星期日------- *前言 我用的是odoo8,但里面有相当多的api是以前版本,这时若我们自己开发的 插件采用新版本api,里面 ...