package wdg;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
public class PlayCard {
List<Card>card=new ArrayList<Card>();
public Player p1;
public Player p2;
public void rearrangeCard(){
System.out.println("-----------开始洗牌------------");
Collections.shuffle(card);
System.out.println("-----------洗牌结束------------");
}
public PlayCard(){
}
public void makeCard(){
System.out.println("-----------创建扑克牌------------");
String a="23456789XJQKA";
String b;
for(int i=0;i<13;i++){
b=a.charAt(i)+"";
card.add(new Card(b,"黑桃",4*i+3));
while(i==7){i++;}
b="";
}
for(int i=0;i<13;i++){
b=a.charAt(i)+"";
card.add(new Card(b,"红桃",4*i+2));
while(i==7){i++;}
b="";
}
for(int i=0;i<13;i++){
b=a.charAt(i)+"";
card.add(new Card(b,"梅花",4*i+1));
while(i==7){i++;}
b="";
}
for(int i=0;i<12;i++){
b=a.charAt(i)+"";
card.add(new Card(b,"方块",4*i));
while(i==7){i++;}
b="";
}
card.add(8,new Card("10","黑桃",35));
card.add(21,new Card("10","红桃",34));
card.add(34,new Card("10","梅花",33));
card.add(47,new Card("10","方块",32));
System.out.println("-----------创建扑克牌成功!------------");
System.out.print("为:[");
for (Card m : card) {
System.out.print(m.flower+m.num+",");
}
card.add(new Card("A","方块",48));
System.out.println("方块A]");
for (Card s : card) {
System.out.println(s.flower+s.num+s.end);
}
}
public void getPlayerAndPlayGame(){
Scanner console=new Scanner(System.in);
System.out.println("-----------创建玩家------------");
Player p1=new Player();
Player p2=new Player();
System.out.println("请输入第1位玩家的ID和姓名");
while(true){
System.out.println("输入ID:");
try{
p1.ID=console.nextInt();
}catch(InputMismatchException e){
console.next();
System.out.println("请输入整数类型的ID!");
continue;
}
break;
}
System.out.println("输入姓名:");
p1.name=console.next();
System.out.println("请输入第2位玩家的ID和姓名");
while(true){
System.out.println("输入ID:");
try{
p2.ID=console.nextInt();
}catch(InputMismatchException e){
console.next();
System.out.println("请输入整数类型的ID!");
continue;
}
break;
}
System.out.println("输入姓名:");
p2.name=console.next();
System.out.println("-----------欢迎玩家:"+p1.name+"------------");
System.out.println("-----------欢迎玩家:"+p2.name+"------------");
System.out.println("-----------开始发牌------------");
System.out.println("玩家:"+p1.name+"拿牌");
System.out.println("玩家:"+p2.name+"拿牌");
System.out.println("玩家:"+p1.name+"拿牌");
System.out.println("玩家:"+p2.name+"拿牌");
Card c1=card.get(0);
Card c2=card.get(1);
Card c3=card.get(2);
Card c4=card.get(3);
if(c1.end>c3.end){
p1.playercard.add(c3);
p1.playercard.add(c1);
}else{
p1.playercard.add(c1);
p1.playercard.add(c3);
}
if(c2.end>c4.end){
p2.playercard.add(c4);
p2.playercard.add(c2);
}else{
p2.playercard.add(c2);
p2.playercard.add(c4);
}
System.out.println("-----------发牌结束------------");
System.out.println("-----------开始游戏...------------");
System.out.println("玩家:"+p1.name+"最大的手牌为:"+p1.playercard.get(1).flower+p1.playercard.get(1).num);
System.out.println("玩家:"+p2.name+"最大的手牌为:"+p2.playercard.get(1).flower+p2.playercard.get(1).num);
if(p1.playercard.get(1).end>p2.playercard.get(1).end){
System.out.println("-----------玩家:"+p1.name+"获胜------------");
}else{
System.out.println("-----------玩家:"+p2.name+"获胜------------");
}
System.out.println("玩家各自的手牌为:");
System.out.println(p1.name+":["+p1.playercard.get(0).flower+p1.playercard.get(0).num+","+p1.playercard.get(1).flower+p1.playercard.get(1).num+"]");
System.out.println(p2.name+":["+p2.playercard.get(0).flower+p2.playercard.get(0).num+","+p2.playercard.get(1).flower+p2.playercard.get(1).num+"]");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
PlayCard pc=new PlayCard();
pc.makeCard();
pc.rearrangeCard();
pc.getPlayerAndPlayGame();
}
}