比大小问题
老师讲讲比大小的问题吧
public int eqFlower(Poker p){//比较花色 int flower = 0; for(int i = 0;i<2;i++){ switch(p.getFlower()){ case "黑桃": flower = 4;break; case "红心": flower = 3;break; case "梅花": flower = 2;break; case "方块": flower = 1;break; default : System.out.println("花色2失败!"); break; } } return flower; } public int eqNumber(Poker p){//比较点数 int number = 0; for(int i = 0;i<2;i++){ switch(p.getNumber()){ case "1": number = 1;break; case "2": number = 2;break; case "3": number = 3;break; case "4": number = 4;break; case "5": number = 5;break; case "6": number = 6;break; case "7": number = 7;break; case "8": number = 8;break; case "9": number = 9;break; case "10": number = 10;break; case "J": number = 11;break; case "Q": number = 12;break; case "K": number = 13;break; case "A": number = 14;break; default : System.out.println("点数失败!"); break; } } return number; }
public void contrast(Player p1,Player p2){ //玩家1自己的牌進行比較 Poker myp1 = this.eqMyPoker(p1); //第一个玩家的最大牌 //玩家2自己的牌進行比較 Poker myp2 = this.eqMyPoker(p2); //第二个玩家的最大牌 System.out.println("玩家"+p1.getName()+"的最大手牌为:"+myp1.getFlower() +myp1.getNumber()); System.out.println("玩家"+p2.getName()+"的最大手牌为:"+myp2.getFlower() +myp2.getNumber()); //两个玩家进行比较 if(this.eqNumber(myp1)!=this.eqNumber(myp2)){ if(this.eqNumber(myp1)>this.eqNumber(myp2)){ p1.winShow(p1); System.out.println("玩家各自的手牌为:"); p1.show(); p2.show(); }else{ p2.winShow(p2); System.out.println("玩家各自的手牌为:"); p1.show(); p2.show(); } }else{ if(this.eqFlower(myp1)>this.eqFlower(myp2)){ p1.winShow(p1); System.out.println("玩家各自的手牌为:"); p1.show(); p2.show(); } } }
//内部比较,确定最大的一张牌 public Poker eqMyPoker(Player p){ if(eqNumber(p.getMyPoker().get(0))!=eqNumber(p.getMyPoker().get(1))){ if(eqNumber(p.getMyPoker().get(0))>eqNumber(p.getMyPoker().get(1))){ return p.getMyPoker().get(0); }else{ return p.getMyPoker().get(1); } }else{ if(eqFlower(p.getMyPoker().get(0))>eqFlower(p.getMyPoker().get(1))){ return p.getMyPoker().get(0); }else{ return p.getMyPoker().get(1); } } }
举报