importjava.util.ArrayList;importjava.util.Collections;importjava.util.List;/*** ClassName:Test
* Date: 2018年9月24日 上午9:51:37
*
*@authorPlum*/
public classTractor {public static voidmain(String[] args) {//模拟去除两张王的52张扑克牌
List puke = new ArrayList();for (int i = 1; i < 14; i++) {for (int j = 0; j < 4; j++) {
puke.add(i);
}
}
System.out.println("扑克牌模拟完毕。。。。。。。。");//洗牌
Collections.shuffle(puke);
List person1 = new ArrayList();
List person2 = new ArrayList();for (int i = 0; i < puke.size(); i++) {if (i < puke.size() / 2) {
person1.add(puke.get(i));
}else{
person2.add(puke.get(i));
}
}
List pub = new ArrayList();do{//第一个人先出牌
int t = person2.get(0);
pub.add(t);
person2.remove(0);
System.out.println("甲出牌:" +t);//判断最后一张牌和前面的每一张是否相等,相等则拿走//拿到最后一张牌
if (pub.size() > 1) {int first = -1;int l = pub.get(pub.size() - 1);for (int i = 0; i < pub.size(); i++) {
System.out.println("池子中的牌分别为:" +pub.get(i));
}for (int i = 0; i < pub.size() - 1; i++) {if (l ==pub.get(i)) {
System.out.println("第" + (i + 1) + "张牌和刚打入的一致,收进去!");
first=i;break;
}
}//将牌收入
if (first != -1) {for (int i = pub.size() - 1; i > first - 1; i--) {
person2.add(pub.get(i));
pub.remove(i);
}
}
}
System.out.println("甲总共" + person2.size() + "张牌:" +person2.toString());//第二个人出牌
if (person1.size() != 0) {
t= person1.get(0);
pub.add(t);
person1.remove(0);
System.out.println("乙出牌:" +t);if (pub.size() > 1) {int first = -1;int l = pub.get(pub.size() - 1);for (int i = 0; i < pub.size(); i++) {
System.out.println("池子中的牌分别为:" +pub.get(i));
}for (int i = 0; i < pub.size() - 1; i++) {if (l ==pub.get(i)) {
System.out.println("第" + (i + 1) + "张牌和刚打入的一致,收进去!");
first=i;break;
}
}//将牌收入
if (first != -1) {for (int i = pub.size() - 1; i > first - 1; i--) {
person1.add(pub.get(i));
pub.remove(i);
}
}
}
}
System.out.println("乙总共" + person1.size() + "张牌:" +person1.toString());
}while (person1.size() != 0 && person2.size() != 0);
System.out.println("==========游戏结束==========");
System.out.println("乙剩余" + person1.size() + "张牌!");
System.out.println("甲剩余" + person2.size() + "张牌!");
}
}