import java.util.Scanner;
class PlayCard {
public static void main(String[] args) {
while (true) {
System.out.println("1, 开始游戏");
System.out.println("2, 退出游戏");
Scanner sc = new Scanner (System.in);
int a = sc.nextInt();
if (a==1) {
char[] arr = {48,49,50,51,52,53,54,55,56,57,74,81,75,48,49,50,51,52,53,54,55,56,57,74,81,75,48,49,50,51,52,53,54,55,56,57,74,81,75,48,49,50,51,52,53,54,55,56,57,74,81,75,'大','小'};
char[] result = new char[54];
for (int j=0;j<=2 ;j++ ) {
result[j] = arr[(int)(arr.length* Math.random())];
arr= delete(arr, result[j]);
}
char 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]);
}
char[] p1 = new char[17];
char[] p2 = new char[17];
char[] p3 = new char[17];
for (int i =0;i<=16 ;i++ ) {
p1= result[i+3];
}
for (int i =0;i<=16 ;i++ ) {
p2= result[i+20];
}
for (int i =0;i<=16 ;i++ ) {
p3= result[i+37];
}
Player[] py = new Player[3];
Scanner sc3 = new Scanner(System.in);
System.out.println("请设置您的名字");
String str = sc3.nextLine();
py[0] = new Player(str,p1);
py[0].showMyCard();
py[1] = new Player("黎玉梅",p2);
//py[1].showMyCard();
py[2] = new Player("3号玩家",p3);
//py[2].showMyCard();
for (int i =0;i<=16 ;i++ ) {
if (p1==target) {
System.out.println("\n" + py[0].name + "你好,你有地主牌"+target +"请问你要叫地主吗? 请输入Yes or No");
Scanner s0 = new Scanner (System.in);
String st1 =s0.nextLine();
if (st1.equals("Yes")) {
py[0].getAll(result);
py[0].finalCard(result);
//py[0].showMyCard();
break;
}else {
py[1].callDZ(py, 1, result);
break;
}
}
if (p2==target) {
int q = (int)(2* Math.random());
if (q==1) {
System.out.println("黎玉梅有地主牌"+target+"并成为地主");
py[1].getAll(result);
py[1].finalCard(result);
//py[1].showMyCard();
break;
}else {
System.out.println("黎玉梅放弃当地主");
py[2].callDZ(py, 2, result);
break;
}
}
if(p3==target) {
int w = (int)(2*Math.random());
if (w==1) {
System.out.println("3号玩家有地主牌"+target+ "并成为地主");
py[2].getAll(result);
py[2].finalCard(result);
//py[2].showMyCard();
break;
}
else {
System.out.println("3号玩家放弃当地主");
py[0].callDZ(py, 0, result);
break;
}
}
}
while (true) {
py[0].outCard(py, 0);
if (py[0].mycard.length==0) {
System.out.println(py[0].name+ "赢了");
break;
}
py[1].outCard(py, 1);
if (py[1].mycard.length==0) {
System.out.println(py[1].name+ "赢了");
break;
}
py[2].outCard(py, 2);
if(py[2].mycard.length==0) {
System.out.println(py[2].name+ "赢了");
break;
}
}
}
else {
System.out.println("谢谢使用,下次再见");
break;
}
}
}
public static char[] delete(char[]arr, char x){
char[] a = new char[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;
}
}
class Player {
String name;
char[] mycard ;
static int[] Card =new int[54];
static int t =0;
public void callDZ(Player[] py, int i, char[] arr){
if (!(name.equals("黎玉梅"))&&!(name.equals("3号玩家"))) {
Scanner sc = new Scanner(System.in);
System.out.println(name+ "您好,请问你要叫地主吗? 请输入Yes or No");
String s = sc.nextLine();
if (s.equals("Yes")) {
getAll(arr);
py.finalCard(arr);
return;
}else {
System.out.println(py[(i+1)%3].name +"自动成为地主");
py[(i+1)%3].getAll(arr);
py[(i+1)%3].finalCard(arr);
//py[(i+1)%3].showMyCard();
public void outCard(Player[] p, int i ){
if (!(name.equals("黎玉梅"))&&!(name.equals("3号玩家"))) {
while (true) {
char[] standard = {'大','小','2','1','K','Q','J','0','9','8','7','6','5','4','3'};
Card[0]= 16;
Scanner s0 = new Scanner(System.in);
System.out.println(name + "你要出第几张牌");
int q =s0.nextInt();
int w =0;
for (w=0;w<standard.length ; w++) {
if (mycard[q-1]==standard[w]) {
break;
}
}
int r =0;
for (r=0;r<standard.length ; r++) {
if (p[(i+1)%3].mycard[0]==standard[r]) {
break;
}
}
int m =0;
for (m=0;m<standard.length ; m++) {
if (p[(i+2)%3].mycard[0]==standard[m]) {
break;
}
}
int f =0;
for (f=0;f<standard1.length ; f++) {
if (mycard[x-1]==standard1[f]) {
break;
}
}
int g =0;
for (g=0;g<standard1.length ; g++) {
if (p[(i+1)%3].mycard[0]==standard1[g]) {
break;
}
}
int h =0;
for (h=0;h<standard1.length ; h++) {
if (p[(i+2)%3].mycard[0]==standard1[h]) {
break;
}
}