* 三人斗地主arraylist版(未排序)
* 分析:
* 1、定义一个牌合
* 2、装牌
* 3、洗牌
* 4、发牌
* 5、看牌
*
*/
public class pokeDemo {
public static void main(String[] args) {
ArrayList<String> array=new ArrayList<String>();
//装牌
//定义两个数组
String[]colors= {"♠","♣","^","@"};
String[]numbers= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
for (String color:colors){
for(String number:numbers){
array.add(color.concat(number));
}
}
array.add("小王");
array.add("大王");
//洗牌
Collections.shuffle(array);
System.out.println(array);
//发牌
ArrayList<String> player1= new ArrayList<String>();
ArrayList<String> player2= new ArrayList<String>();
ArrayList<String> player3= new ArrayList<String>();
ArrayList<String> dipai= new ArrayList<String>();
for(int x=0;x<array.size();x++){
if(x>=array.size()-3){
dipai.add(array.get(x));
}
if(x %3==0){
//玩家1的牌
player1.add(array.get(x));
}else
if(x %3==1)
{
//2
player2.add(array.get(x));
}else if (x%3==2)
{
//3
player3.add(array.get(x));
}
}
//看牌,写一个功能
//掉方法
lookPoker("玩家1",player1);
lookPoker("玩家2", player2);
lookPoker("玩家3", player3);
lookPoker("底牌", dipai);
}
public static void lookPoker(String name,ArrayList<String> array){
System.out.print(name+ ": ");
for(String s:array)
{
System.out.print(s);
System.out.print(" ");
}
System.out.println();
}
} |
|