何如用c++或者Java编写出简单的骰子
1. 编写一个骰子的程序,盒子中有三个骰子,有两个人一起玩,请你写一个类Game,类中有一个方法void init(int[] one,int[] other),产生两个人的骰子值,并比较大小。
比较大小的方法为 int compare(int[] one,int[] other),若one大,则返回1,若other大则返回-1,若等大则返回0;
大小规则如下:豹子>顺子>对子>单个,同等牌型比大小。
package p0627;
import java。util。Arrays;
import java。util。Random;
public class LittleGame {
...全部
1. 编写一个骰子的程序,盒子中有三个骰子,有两个人一起玩,请你写一个类Game,类中有一个方法void init(int[] one,int[] other),产生两个人的骰子值,并比较大小。
比较大小的方法为 int compare(int[] one,int[] other),若one大,则返回1,若other大则返回-1,若等大则返回0;
大小规则如下:豹子>顺子>对子>单个,同等牌型比大小。
package p0627;
import java。util。Arrays;
import java。util。Random;
public class LittleGame {
public final int baozi = 4;
public final int shunzi = 3;
public final int duizi = 2;
public final int danpai = 1;
public LittleGame() {
}
public void init(int[] one, int[] other) {
Random rand = new Random();
for (int i = 0; i type2) {
return 1;
}
if (type1 other[0]) {
return 1;
}
if (one[0] v2) {
return 1;
}
if (v1 d2) {
return 1;
}
if (d1 s2) {
return 1;
}
if (s1 < s2) {
return -1;
}
break;
}
return 0;
}
public int checkType(int[] o) {
if (o[0] == o[2]) {
return baozi;
}
if (o[0] == o[1] || o[1] == o[2]) {
return duizi;
}
if (o[1] == o[0] + 1 && o[2] == o[1] + 1) {
return shunzi;
}
return danpai;
}
public static void main(String[] args) {
LittleGame l = new LittleGame();
int[] one = new int[3];
int[] other = new int[3];
l。
init(one, other);
int r = l。compare(one, other);
System。out。println(r);
}
}
。收起