问答详情
源自:7-1 简易扑克牌游戏

创建扑克牌的问题,运行结果是这样

package com.yigege.poker;


import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;



public class Poker implements Comparable<Poker>{


private String hs;

private String ds;

private static final int CARDNUM = 52;

    private static final int SINGLECARDNUM = 13;

    private static final int COLORNUM = 4;

private static final List<String> Color = Arrays.asList("黑桃", "红桃", "梅花", "方块");

//    private static final List<String> Colors = Arrays.asList("方块", "草花", "红桃","黑桃");


private static final List<String> Number = Arrays.asList("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A");



public String getHs() {

return hs;

}

public String getDs() {

return ds;

}

public Poker(){

}

public Poker(String hs, String ds){

this.hs = hs;

this.ds = ds;

}

// public Poker(){

//

// }

public static List<Poker> cardCreate(){

List<Poker> card = new ArrayList<>();

for (int i=0; i<CARDNUM; ++i){

     String newValue = null;

         String newColor = null;

         int tmp = i % SINGLECARDNUM;

           newValue = Number.get(tmp);

//         System.out.println(tmp);

           tmp = i % COLORNUM;

           newColor = Color.get(tmp);

//cardList中添加扑克牌

card.add(new Poker(newColor, newValue));

}

return card;

}


 @Override

   public String toString() {

       return "[" + Color + " " + Number + "]";

   }

@Override

public int compareTo(Poker o) {

      if (Number.indexOf(this.ds) == Number.indexOf(o.ds)) {

           return Integer.valueOf(Color.indexOf(this.hs)).compareTo(Integer.valueOf(Color.indexOf(o.hs)));

       } else {

           return Integer.valueOf(Number.indexOf(this.ds)).compareTo(Integer.valueOf(Number.indexOf(o.ds)));

       }

   

}

}

http://img.mukewang.com/58103ddd0001c91211520648.jpg

提问者:qq_一大只耗子_03344965 2016-10-26 13:23

个回答

  • 优米网
    2016-10-26 22:07:14

    还有代码呢