为了账号安全,请及时绑定邮箱和手机立即绑定

扑克牌游戏运行成功 请大家帮忙看看找找错

扑克牌游戏运行成功 请大家帮忙看看找找错

猛禽斩侧卫 2016-01-21 08:50:46
public class TestGame {List<PlayCard>cardlist=new ArrayList<PlayCard>();//用来存放手牌Set<PlayCard>setPlayCard;//用来洗牌的setList<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();}}
查看完整描述

1 回答

?
爱吃豆角的虫子

TA贡献22条经验 获得超6个赞

PlayCard  的类呢????

查看完整回答
反对 回复 2016-01-29
  • 1 回答
  • 0 关注
  • 1419 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信