public class TestGame {
List<PlayCard>cardlist=new ArrayList<PlayCard>();//用来存放手牌
Set<PlayCard>setPlayCard;//用来洗牌的set
List<PlayCard> cardlistNew=new ArrayList<PlayCard>();//用来存放一洗过的手牌
List<Player>playerlist=new ArrayList<Player>();//存放玩家
List<PlayCard>playerCard_1=new ArrayList<PlayCard>();//1玩家抽到的手牌
List<PlayCard>playerCard_2=new ArrayList<PlayCard>();//2玩家抽到的手牌
List<PlayCard>playerFinallyCard=new ArrayList<PlayCard>();//玩家最大手牌集合
public String a;
public String b;
public TestGame(){
this.cardlist=new ArrayList();
this.playerlist=new ArrayList();
this.setPlayCard=new HashSet();
}
public void addPlayCard(){
PlayCard[]playcard={
new PlayCard("红桃","1"),new PlayCard("红桃","2"),new PlayCard("红桃","3"),new PlayCard("红桃","4"),new PlayCard("红桃","5"),
new PlayCard("红桃","6"),new PlayCard("红桃","7"),new PlayCard("红桃","8"),new PlayCard("红桃","9"),new PlayCard("红桃","10"),
new PlayCard("红桃","11"),new PlayCard("红桃","12"),new PlayCard("红桃","13"),
new PlayCard("黑桃","1"),new PlayCard("黑桃","2"),new PlayCard("黑桃","3"),new PlayCard("黑桃","4"),new PlayCard("黑桃","5"),
new PlayCard("黑桃","6"),new PlayCard("黑桃","7"),new PlayCard("黑桃","8"),new PlayCard("黑桃","9"),new PlayCard("黑桃","10"),
new PlayCard("黑桃","11"),new PlayCard("黑桃","12"),new PlayCard("黑桃","13"),
new PlayCard("方片","1"),new PlayCard("方片","2"),new PlayCard("方片","3"),new PlayCard("方片","4"),new PlayCard("方片","5"),
new PlayCard("方片","6"),new PlayCard("方片","7"),new PlayCard("方片","8"),new PlayCard("方片","9"),new PlayCard("方片","10"),
new PlayCard("方片","11"),new PlayCard("方片","12"),new PlayCard("方片","13"),
new PlayCard("梅花","1"),new PlayCard("梅花","2"),new PlayCard("梅花","3"),new PlayCard("梅花","4"),new PlayCard("梅花","5"),
new PlayCard("梅花","6"),new PlayCard("梅花","7"),new PlayCard("梅花","8"),new PlayCard("梅花","9"),new PlayCard("梅花","10"),
new PlayCard("梅花","11"),new PlayCard("梅花","12"),new PlayCard("梅花","13")
};
cardlist.addAll(Arrays.asList(playcard));
for(PlayCard pc:cardlist){
System.out.println("创建扑克牌成功"+pc.Colour+":"+pc.Count);
}
}
public void addPlayer(){
Scanner input=new Scanner(System.in);
for(int i=0;i<2;i++){
System.out.println("请输入玩家ID");
String a=input.next();
System.out.println("请输入玩家姓名");
String b=input.next();
playerlist.add(new Player(a,b,null));
}
for(Player pl:playerlist){
System.out.println("玩家有"+pl.id +":"+pl.name);
}
}
public void shuffle(){
System.out.println("开始洗牌");
for(PlayCard pc:cardlist){
setPlayCard.add(new PlayCard(pc.Colour,pc.Count));
}
for(PlayCard pc1:setPlayCard){
cardlistNew.add(new PlayCard(pc1.Colour,pc1.Count));
}
System.out.println("洗牌结束");
}
public void startGame(){
PlayCard[] pd_1={
cardlistNew.get(0),cardlistNew.get(2)
};
PlayCard[]Pd_2={
cardlistNew.get(1),cardlistNew.get(3)
};
playerCard_1.addAll(Arrays.asList(pd_1));//玩家1抽到的手牌
playerCard_2.addAll(Arrays.asList(Pd_2));//玩家2抽到的手牌
for(int i=0;i<2;i++){
System.out.println("玩家"+playerlist.get(0).name+"拿牌");
System.out.println("玩家"+playerlist.get(1).name+"拿牌");
}
playerlist.set(0, new Player(playerlist.get(0).id,playerlist.get(0).name,playerCard_1));//往玩家1信息里面填写手牌信息
playerlist.set(1, new Player(playerlist.get(1).id,playerlist.get(1).name,playerCard_2));//往玩家2里面填写手牌信息
}
//开始比较手牌大小
public void compare(){
Collections.sort(playerCard_1);
System.out.println("玩家:"+playerlist.get(0).name+"最大手牌为"+playerCard_1.get(0).Colour+playerCard_1.get(0).Count);
System.out.println("玩家:"+playerlist.get(1).name+"最大手牌为"+playerCard_2.get(1).Colour+playerCard_2.get(1).Count);
playerFinallyCard.add(new PlayCard(playerCard_1.get(0).Colour,playerCard_1.get(0).Count));
playerFinallyCard.add(new PlayCard(playerCard_1.get(1).Colour,playerCard_1.get(1).Count));
Collections.sort(playerFinallyCard);
if(playerFinallyCard.get(0).equals(playerCard_1.get(0))){
System.out.println("--------"+playerlist.get(0).name+"获胜"+"------------");
}else{
System.out.println("---------"+playerlist.get(1).name+"获胜"+"------------");
}
}
public void showCard(){
System.out.println("玩家各自的手牌为");
System.out.println(playerlist.get(0).name+":"+playerCard_1.get(0).Colour+playerCard_1.get(0).Count+":"+playerCard_1.get(1).Colour+playerCard_1.get(1).Count);
System.out.println(playerlist.get(1).name+":"+playerCard_2.get(0).Colour+playerCard_2.get(0).Count+":"+playerCard_2.get(1).Colour+playerCard_2.get(1).Count);
}
public static void main(String[] args){
TestGame tg=new TestGame();
tg.addPlayCard();
tg.addPlayer();
tg.shuffle();
tg.startGame();
tg.compare();
tg.showCard();
}
}
爱吃豆角的虫子
相关分类