简易记牌器

三个玩家分得相同数目的随机牌,依次发牌每发一次牌统计一下余下的牌



package java0804homework;



import java.util.ArrayList;


public class t001 {


public static void main(String[] args) {
// TODO Auto-generated method stub
poke play = new poke();
play.card();
play.sendcard();
play.jishu();


}


}


class poke {
String[] hua = { "黑桃", "方块", "梅花", "红心" };
String[] num = { "3", "4", "5", "6", "7", "8", "9", "10", "A", "J", "Q", "K", "2" };
ArrayList a = new ArrayList();
ArrayList a1 = new ArrayList();
ArrayList a2 = new ArrayList();
ArrayList a3 = new ArrayList();


void card() {
for (int i = 0; i < hua.length; i++) {
for (int j = 0; j < num.length; j++) {
a.add(hua[i] + num[j]);


}
}
a.add("大王大王");
a.add("小王小王");
// System.out.println(a);
}


void sendcard() {
for (int i = 0; i < 18; i++) {
a1.add(a.get(i));
}
for (int i = 0; i < 18; i++) {
a2.add(a.get(i + 18));
}
for (int i = 0; i < 18; i++) {
a3.add(a.get(i + 36));
}


}
//计算牌面
void jishu() {
while (!(a1.isEmpty()) || !(a2.isEmpty()) || !(a3.isEmpty())) {


int f = (int) (Math.random() * a1.size());


System.out.println("1玩家出了" + a1.get(f));
a.remove(a1.get(f));
a1.remove(f);
System.out.println("还剩" + a1);


//1玩家出牌后计算所有牌面上的牌
System.out.print("牌面上还有");

ArrayList ta =  a;
//System.out.println(a);
// System.out.println(ta);
// System.out.println(a);
for (int i = 0; i < ta.size(); i++) {


int num = 1;
String b = ta.get(i).toString().substring(2);
// System.out.println(a);
// System.out.println("ff"+ta);


for (int j = i + 1; j < ta.size(); j++) {
String c = ta.get(j).toString().substring(2);
if (b.equals(c)) {
ta.remove(j);
num++;
}
}
System.out.print(" " + b + "," + num + "张" + " ");
}
//System.out.println(a);


//玩家二

System.out.println();
System.out.println("=====");


int h = (int) (Math.random() * a2.size());
System.out.println("2玩家出了" + a2.get(h));
a.remove(a2.get(h));
a2.remove(h);
System.out.println("还剩" + a2);

//2玩家出牌后计算所有牌面上的牌
System.out.print("牌面上还有");

ArrayList ta2 =  a;

for (int i = 0; i < ta2.size(); i++) {


int num = 1;
String b = ta2.get(i).toString().substring(2);


for (int j = i + 1; j < ta2.size(); j++) {
String c = ta2.get(j).toString().substring(2);
if (b.equals(c)) {
ta2.remove(j);
num++;
}
}
System.out.print(" " + b + "," + num + "张" + " ");
}

//3玩家
System.out.println();
System.out.println("=====");


int k = (int) (Math.random() * a3.size());
System.out.println("3玩家出了" + a3.get(k));
a.remove(a3.get(k));
a3.remove(k);
System.out.println("还剩" + a3);
////3玩家出牌后计算所有牌面上的牌
System.out.print("牌面上还有");

ArrayList ta3 = (ArrayList) a;
for (int i = 0; i < ta3.size(); i++) {


int num = 1;
String b = ta3.get(i).toString().substring(2);


for (int j = i + 1; j < ta3.size(); j++) {
String c = ta3.get(j).toString().substring(2);
if (b.equals(c)) {
ta3.remove(j);
num++;
}
}
System.out.print(" " + b + "," + num + "张" + " ");
}

System.out.println();
System.out.println("=====");
}
}
}

你可能感兴趣的:(java,java)