[java]代码库
package com.playGame;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pokers {
List<Integer> gameCards=new ArrayList<>();
int card=-1;
public void playGame(){
boolean start=true;
while(start){
int card=(int)(Math.random()*54);
if(gameCards.contains(card)){
continue;
}
gameCards.add(card);
if(gameCards.size()==54){
break;
}
}
shuffle();
}
Map<Integer,ArrayList<Integer>> playsPokers=new HashMap<Integer,ArrayList<Integer>>();
private void shuffle() {
int cardsIndex=(int)(Math.random()*52);
System.out.println("地主牌是:"+getNumber(gameCards.get(cardsIndex)));
int landlord=cardsIndex%3;
playsPokers.put(0,new ArrayList<Integer>());
playsPokers.put(1,new ArrayList<Integer>());
playsPokers.put(2,new ArrayList<Integer>());
for(int i=0;i<gameCards.size();i++){
int eachPlay=i%3;
if(i>51){
playsPokers.get(landlord).add(gameCards.get(i));
}else{
playsPokers.get(eachPlay).add(gameCards.get(i));
}
}
showCards();
}
private void showCards() {
for(int i=0;i<3;i++){
System.out.println("\n玩家"+(i+1));
List<Integer> everyPokers=playsPokers.get(i);
for(Integer numberPokers:everyPokers){
System.out.print(" "+getNumber(numberPokers));
}
}
}
String [] colors=new String[]{"黑桃","红桃","方块","梅花"};
public String getColors(int kinds){
int index=kinds%4;
return colors[index];
}
String [] numbers=new String[]{"2","3","4","5","6","7","8","9","10","J","Q","K","A","小王","大王"};
public String getNumber(int numberIndex){
if(numberIndex<52){
int peopleCards=numberIndex/4;
return getColors(numberIndex)+numbers[peopleCards];
}else if(numberIndex==52){
return numbers[numbers.length-2];
}else if(numberIndex==53){
return numbers[numbers.length-1];
}
return null;
}
}
package com.playGame;
public class Main {
public static void main(String args[]){
Pokers stats=new Pokers();
stats.playGame();
}
}