猜拳游戏android报告,android 之猜拳游戏练习

android 之猜拳游戏练习

2013-05-21 11:28:00

写猜拳游戏的目的主要是练习linerlayout和relativelayout;有三个页面,其中两个是linerlayout的。

在我的资源里已经将代码上传了:http://download.csdn.net/detail/yuexin2/5419533

HumanToComputer.java中:

package com.example.guesshand;

import java.util.Random;

import android.annotation.SuppressLint;

import android.app.Activity;

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;

import android.widget.TextView;

import android.widget.RadioGroup.OnCheckedChangeListener;

public class HumanToComputer extends Activity {

public Button cok;

public RadioButton mstoreOne;

public RadioButton mjiandaoOne;

public RadioButton mbuOne;

public RadioGroup moneRadioGroup;

public TextView cresult;

public ImageView cimgTwo;

public ImageView cimgOne;

private int men=0;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.human_computer);

cresult = (TextView)findViewById(R.id.cresult);

cimgTwo = (ImageView)findViewById(R.id.cimgTwo);

cimgOne = (ImageView)findViewById(R.id.cimgOne);

cok = (Button)findViewById(R.id.cOk);

OnCokClicked occ = new OnCokClicked();

cok.setOnClickListener(occ);

moneRadioGroup = (RadioGroup)findViewById(R.id.moneRadioGroup);

mstoreOne = (RadioButton)findViewById(R.id.mstoreOne);

mjiandaoOne = (RadioButton)findViewById(R.id.mjiandaoOne);

mbuOne = (RadioButton)findViewById(R.id.mbuOne);

OnRadioGroupChange orgc = new OnRadioGroupChange();

moneRadioGroup.setOnCheckedChangeListener(orgc);

}

class OnRadioGroupChange implements OnCheckedChangeListener{

@Override

public void onCheckedChanged(RadioGroup arg0, int arg1) {

if(arg1==R.id.mstoreOne){

men=1;

}

else if(arg1==R.id.mjiandaoOne){

men=2;

}

else if(arg1==R.id.mbuOne){

men=3;

}

}

}

class OnCokClicked implements OnClickListener{

@Override

public void onClick(View v) {

Random rnd = new Random();

int computer = rnd.nextInt(3);

computer++;

System.out.println("电脑:"+computer);

if(men==1){

if(computer==2){

cresult.setText("玩家赢了!!!");

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

if(computer==3){

cresult.setText("电脑赢了!!!");

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

}

if(men==2){

if(computer==1){

cresult.setText("电脑赢了!!!");

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

if(computer==3){

cresult.setText("玩家赢了!!!");

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

}

if(men==3){

if(computer==2){

cresult.setText("电脑赢了!!!");

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

if(computer==1){

cresult.setText("玩家赢了!!!");

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.no));

}

}

if(men == computer&&men!=0){

cresult.setText("平局!!!");

cimgOne.setImageDrawable(getResources().getDrawable(R.drawable.yes));

cimgTwo.setImageDrawable(getResources().getDrawable(R.drawable.yes));

}

if(men!=0&&computer!=0){

men = 0;

}

}

}

}

HumanToHumanActivity.java文件:

package com.example.guesshand;

import android.app.Activity;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import an

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值