荣岩岩作业14
package xcc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Collections;
import java.util.HashMap;
public class nnnnn {
/*模拟斗地主 洗牌,发牌
1,创建牌面
&& ##
? ? ? ?(黑红梅方)
1 2 3...J Q K
V && ## 2? 2? .... 3? 3?
K 1 2 3 4 .....53 54
/*模拟斗地主 洗牌,发牌
1,创建牌面
&& ##
? ? ? ?(黑红梅方)
1 2 3...J Q K
V && ## 2? 2? .... 3? 3?
K 1 2 3 4 .....53 54
2,洗牌
1,获取键的集合----set<>
2,将set集合转为list集合
3,Colletions.shuffle(List<?> list)
1,获取键的集合----set<>
2,将set集合转为list集合
3,Colletions.shuffle(List<?> list)
3,发牌
1,创建3个玩家集合+ 1个底牌集合
2,发编号(k)
3,通过编号 显示牌面 (通过k---v)
1,创建3个玩家集合+ 1个底牌集合
2,发编号(k)
3,通过编号 显示牌面 (通过k---v)
创建三个玩家 打印一下 他们手中 牌面*/
public static void main(String[] args) {
ArrayList<String> color=new ArrayList<String>();
color.add("?");
color.add("?");
color.add("?");
color.add("?");
ArrayList<String>number=new ArrayList<String>();
Collections.addAll(number, "3","4","5","6","7","8","9","10","J","Q","K","A","2");
HashMap<Integer, String>map=new HashMap<Integer, String>();
int index=0;
for(String thisNumber :number){
for(String thisColor:color){
map.put(index++, thisColor+thisNumber);
}
}
map.put(index++, "小王");
map.put(index++, "大王");
ArrayList<Integer>cards=new ArrayList<Integer>();
for (int i = 0; i <=53; i++) {
cards.add(i);
}
Collections.shuffle(cards);
ArrayList<Integer>iPlayer=new ArrayList<Integer>();
ArrayList<Integer>iPlayer2=new ArrayList<Integer>();
ArrayList<Integer>iPlayer3=new ArrayList<Integer>();
ArrayList<Integer>itCards=new ArrayList<Integer>();
for (int i = 0; i < cards.size(); i++) {
if (i>=51) {
itCards.add(cards.get(i));
}else{
if(i%3==0){
iPlayer.add(cards.get(i));
}else if(i%3==1){
iPlayer2.add(cards.get(i));
}else{
iPlayer3.add(cards.get(i));
}
}
Collections.sort(iPlayer);
Collections.sort(iPlayer2);
Collections.sort(iPlayer3);
ArrayList<String>sPlayer=new ArrayList<String>();
ArrayList<String>sPlayer2=new ArrayList<String>();
ArrayList<String>sPlayer3=new ArrayList<String>();
ArrayList<String>sCards=new ArrayList<String>();
for(Integer key:iPlayer){
sPlayer.add(map.get(key));
}
for(Integer key:iPlayer){
sPlayer2.add(map.get(key));
}
for(Integer key:iPlayer){
sPlayer3.add(map.get(key));
}
for(Integer key:iPlayer){
sCards.add(map.get(key));
}
System.out.println("玩家一"+sPlayer);
System.out.println("玩家二"+sPlayer2);
System.out.println("玩家三"+sPlayer3);
System.out.println("底牌"+);
}
}
}
public static void main(String[] args) {
ArrayList<String> color=new ArrayList<String>();
color.add("?");
color.add("?");
color.add("?");
color.add("?");
ArrayList<String>number=new ArrayList<String>();
Collections.addAll(number, "3","4","5","6","7","8","9","10","J","Q","K","A","2");
HashMap<Integer, String>map=new HashMap<Integer, String>();
int index=0;
for(String thisNumber :number){
for(String thisColor:color){
map.put(index++, thisColor+thisNumber);
}
}
map.put(index++, "小王");
map.put(index++, "大王");
ArrayList<Integer>cards=new ArrayList<Integer>();
for (int i = 0; i <=53; i++) {
cards.add(i);
}
Collections.shuffle(cards);
ArrayList<Integer>iPlayer=new ArrayList<Integer>();
ArrayList<Integer>iPlayer2=new ArrayList<Integer>();
ArrayList<Integer>iPlayer3=new ArrayList<Integer>();
ArrayList<Integer>itCards=new ArrayList<Integer>();
for (int i = 0; i < cards.size(); i++) {
if (i>=51) {
itCards.add(cards.get(i));
}else{
if(i%3==0){
iPlayer.add(cards.get(i));
}else if(i%3==1){
iPlayer2.add(cards.get(i));
}else{
iPlayer3.add(cards.get(i));
}
}
Collections.sort(iPlayer);
Collections.sort(iPlayer2);
Collections.sort(iPlayer3);
ArrayList<String>sPlayer=new ArrayList<String>();
ArrayList<String>sPlayer2=new ArrayList<String>();
ArrayList<String>sPlayer3=new ArrayList<String>();
ArrayList<String>sCards=new ArrayList<String>();
for(Integer key:iPlayer){
sPlayer.add(map.get(key));
}
for(Integer key:iPlayer){
sPlayer2.add(map.get(key));
}
for(Integer key:iPlayer){
sPlayer3.add(map.get(key));
}
for(Integer key:iPlayer){
sCards.add(map.get(key));
}
System.out.println("玩家一"+sPlayer);
System.out.println("玩家二"+sPlayer2);
System.out.println("玩家三"+sPlayer3);
System.out.println("底牌"+);
}
}
}