public class FingerGame {
private String[] op = new String[] { "布", "剪刀", "石头" };
Random r = new Random();
private int wj = 0;
private int dn = 0;
private int count = 0;
private int go() {
int k = r.nextInt(3);
System.out.println("电脑:" + op[k]);
return k;
}
private void compare(int i) {
count++;
System.out.println("玩家:" + op[i - 1]);
int k = go();
if ( i - 1 == k) {
System.out.println("打平");
} else if ( i - 1 - k == 1 || i-1-k == -2) {
System.out.println("玩家获胜");
wj++;
} else {
System.out.println("电脑获胜");
dn++;
}
}
private void info() {
System.out.println("共" + count + "盘");
System.out.println("玩家获胜" + wj + "盘");
System.out.println("电脑获胜" + dn + "盘");
System.out.println("平局" + (count-wj-dn) + "盘");
}
|
|