小遊戲:模擬鬥地主
阿新 • • 發佈:2018-11-18
小遊戲:模擬鬥地主
public class CollectionsTest { public static void main(String[] args) { String[] color= {"黑桃","紅桃","方片","梅花"}; String[] nom= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; ArrayList<String> box=new ArrayList<>(); //洗牌 for(int i=0;i<color.length;i++) { for(int j=0;j<nom.length;j++) { box.add(color[i]+nom[j]); } } box.add("大王"); box.add("小王"); //洗牌 Collections.shuffle(box); ArrayList<String> 林志玲 = new ArrayList<String>(); ArrayList<String> 林心如 = new ArrayList<String>(); ArrayList<String> 舒淇 = new ArrayList<String>(); //留下3張底牌給地主 for(int i=0;i<box.size()-3;i++) { if(i % 3 == 0) { 林志玲.add(box.get(i)); } else if(i % 3 == 1) { 林心如.add(box.get(i)); } else if(i % 3 == 2) { 舒淇.add(box.get(i)); } } System.out.println("林志玲:" + 林志玲); System.out.println("林心如:" + 林心如); System.out.println("舒淇:" + 舒淇); System.out.println("底牌:"); for (int i = box.size() - 3; i < box.size(); i++) { System.out.println(box.get(i)); } }
}