本帖最后由 何亚辉 于 2016-5-18 01:02 编辑
import java.util.Scanner;
class Doudizhu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[54];
for (int i =0;i<=53 ;i++ ) {
arr = i+1;
}
int[] result = new int[54];
for (int j=0;j<=2 ;j++ ) {
result[j] = arr[(int)(arr.length* Math.random())];
arr= delete(arr, result[j]);
}
int target = arr[(int)(Math.random()*52)];
for (int j=3;j<=53 ;j++ ) {
result[j]=arr[(int)(arr.length* Math.random())];
arr= delete(arr, result[j]);
}
int[] p1 = new int[17];
int[] p2 = new int[17];
int[] p3 = new int[17];
System.out.println("玩家P1, 您好,你的牌是");
for (int i =0;i<=16 ;i++ ) {
p1= result[i+3];
System.out.print(p1+" ");
}
System.out.println("\n" + "玩家P2, 您好,你的牌是");
for (int i =0;i<=16 ;i++ ) {
p2= result[i+20];
System.out.print(p2+" ");
}
System.out.println("\n" + "玩家P3, 您好,你的牌是");
for (int i =0;i<=16 ;i++ ) {
p3= result[i+37];
System.out.print(p3+" ");
}
for (int i =0;i<=16 ;i++ ) {
if (p1==target) {
System.out.println("\n" + "玩家P1你好,你有地主牌"+target +"请问你要叫地主吗? 请输入Yes or No");
String s =sc.nextLine();
if (s.equals("Yes")) {
getAll(result);
break;
}else {
System.out.println("对不起,必须叫地主,,不然就不好玩了");
break;
}
}
if (p2==target) {
System.out.println("\n" + "玩家P2你好,你有地主牌"+target +"请问你要叫地主吗?请输入Yes or No");
String s =sc.nextLine();
if (s.equals("Yes")) {
getAll(result);
break;
}else {
System.out.println("对不起,必须叫地主,,不然就不好玩了");
break;
}
}
if(p3==target) {
System.out.println("\n" + "玩家P3你好,你有地主牌"+target +"请问你要叫地主吗?请输入Yes or No");
String s =sc.nextLine();
if (s.equals("Yes")) {
getAll(result);
break;
}
else {
System.out.println("对不起,必须叫地主,,不然就不好玩了");
break;
}
}
}
}
public static int[] delete(int[]arr, int x){
int[] a = new int[arr.length-1];
int i =0;
for (i =0;i<arr.length ;i++ ) {
if (arr==x) {
break;
}
}
for (int j =0;j<arr.length-1 ; j++) {
if (j<i) {
a[j]=arr[j];
}else {
a[j]=arr[j+1];
}
}
return a;
}
public static void getAll( int[] arr){
System.out.print("这是3张地主底牌,请拿好");
for (int i=0;i<=2 ;i++ ) {
System.out.print(arr+ " ");
}
}
}
|
|