Android小游戏_猜拳


运行界面

Android小游戏_猜拳_第1张图片

Android小游戏_猜拳_第2张图片

类设计:

玩家类:WanJjia

电脑类:DianNao

角色类:JueSe

游戏类:YouXi

代码

角色类:JueSe

package com.cq.model;
public class JueSe {
private int status;
private String name;
public String getStatusStr(){
if(0 == status)return "NULL";
else if(1 == status)return "剪子";
else if(2 == status)return "包袱";
return "锤子";
}
public void setStatus(int status) {
this.status = status;
}
public int getStatus() {
return status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}



玩家类:WanJjia


package com.cq.model;
/**
 * 玩家类
 */
public class WanJia extends JueSe{
@Override
public String getName() {
return "玩家";
}
public void chuquan(int status){
setStatus(status);
}
}




电脑类: DianNao

package com.cq.model;
import java.util.Random;
/**
 * 电脑类
 * @author Cer
 *
 */
public class DianNao extends JueSe{
@Override
public String getName() {
return "电脑";
}
public void chuquan(){
int temp = new Random().nextInt(3) + 1;
switch (temp) {
case 1:
this.setStatus(YouXi.JZ);
break;
case 2:
this.setStatus(YouXi.BF);
break;
case 3:
this.setStatus(YouXi.CZ);
break;
}
}
}


游戏类:YouXi

package com.cq.model;
/**
 * 游戏类
 * @author Cer
 *
 */
public class YouXi {
public static final int JZ = 1;
public static final int BF = 2;
public static final int CZ = 3;
//判定输赢函数
public  static JueSe panding (WanJia wj ,DianNao dn){
int a = wj.getStatus();
int b = dn.getStatus();
//是否平局
if(a == b)return null;
if(3 == a){
if(1 != b)return dn;
return wj;
}else{
if(a > b)return dn;
return wj;
}
}
}


没有什么技术含量,这个游戏的唯一价值好像在面向对象设计上?!





你可能感兴趣的:(游戏,android,String,Random,Class)