package com.android.app;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ResultActivity extends Activity {
private TextView myTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.resultstyle);
myTextView = (TextView)findViewById(R.id.res);
Intent intent = getIntent();
int ren = Integer.parseInt(intent.getStringExtra("ren"));
//业务逻辑判断
//自动生成npc产生拳的代码(1~3)
int npc = new Random().nextInt(3)+1;
//处理请求数据并进行逻辑判断,将结果返回
String res = "";
if(ren == npc){
res = "平局,再接再厉";
}else if(ren == 3 && npc == 1){
res = "恭喜,您获胜了……";
}else if(ren == 1 && npc == 3){
res = "虽败犹荣……再来一局";
}else if(ren < npc){
res = "恭喜,您获胜了……";
}else{
res = "虽败犹荣……再来一局";
}
String msg = "您:"+change(ren)+" vs "+change(npc)+":电脑\n您"+res;
myTextView.setText(msg);
}
//将数字转换成汉字
private String change(int r){
switch(r){
case 1:
return "石头";
case 2:
return "剪刀";
case 3:
return "布";
}
return null;
}
}
评论13
最新资源