MainActivity类:
package com.mcm.fingerplay;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private RadioGroup leftRadioGroup;
private RadioGroup rightRadioGroup;
private RadioButton leftStoneButton;
private RadioButton leftScissorsButton;
private RadioButton leftClothButton;
private RadioButton rightStoneButton;
private RadioButton rightScissorsButton;
private RadioButton rightClothButton;
private Button button;
private TextView resultTextView;
static int flag = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultTextView = (TextView) findViewById(R.id.resultTextView);
resultTextView.setBackgroundColor(Color.YELLOW);
leftRadioGroup = (RadioGroup) findViewById(R.id.leftRadioGroup);
rightRadioGroup = (RadioGroup) findViewById(R.id.rightRadioGroup);
leftRadioGroupLister l = new leftRadioGroupLister();
leftRadioGroup.setOnCheckedChangeListener(l);
rightRadioGroupLister r = new rightRadioGroupLister();
rightRadioGroup.setOnCheckedChangeListener(r);
button = (Button) findViewById(R.id.button);
ButtonLister buttonLister = new ButtonLister();
button.setOnClickListener(buttonLister);
leftStoneButton = (RadioButton) findViewById(R.id.leftStoneButton);
leftScissorsButton = (RadioButton) findViewById(R.id.leftScissorsButton);
leftClothButton = (RadioButton) findViewById(R.id.leftClothButton);
rightStoneButton = (RadioButton) findViewById(R.id.rightStoneButton);
righ

该博客介绍了如何在Android平台上实现一个简单的猜拳游戏。通过MainActivity类和对应的监听器,实现了用户选择石头、剪刀或布,并根据用户和系统的选项判断胜负。游戏结果会显示在界面上。
最低0.47元/天 解锁文章
4636

被折叠的 条评论
为什么被折叠?



