斗地主 发牌核心 代码

Card

 

 

public class Card {

    // 点数

    public static final int THREE = 0;

    public static final int FOUR = 1;

    public static final int FIVE = 2;

    public static final int SIX = 3;

    public static final int SEVEN = 4;

    public static final int EIGHT = 5;

    public static final int NINE = 6;

    public static final int TEEN = 7;

    public static final int JACK = 8;

    public static final int QUEEN = 9;

    public static final int KING = 10;

    public static final int ACE = 11;

    public static final int DEUCE = 12;

 

    public static final int BLACK = 13;

    public static final int COLOR = 14;

 

    // 花色

    // 方块

    public static final int DIAMOND = 0;

    // 红桃

    public static final int HEART = 1;

    // 梅花

    public static final int CLUB = 2;

    // 黑桃

    public static final int SPADE = 3;

    //

    public static final int JOKER = 4;

    // 花色

    public  static String[] suit_names = { "方块", "红桃", "梅花", "黑桃", "" };

    public  static String[] rank_names = { "3", "4", "5", "6", "7", "8", "9",

            "10", "J", "Q", "K", "A", "2", "", "" };

    // 点数

    private int rank;

    // 花色

    private int suit;

 

    public Card() {

 

    }

 

    public Card(int rank, int suit) {

        setRank(rank);

        setSuit(suit);

    }

 

    public int getRank() {

        return rank;

    }

 

    public void setRank(int rank) {

        if (Card.THREE > rank || rank > Card.COLOR)

            throw new RuntimeException("超了");

        this.rank = rank;

    }

 

    public int getSuit() {

        return suit;

    }

 

    public void setSuit(int suit) {

        if (Card.DIAMOND > suit || suit > Card.JOKER)

            throw new RuntimeException("超了");

        this.suit = suit;

    }

 

    @Override

    public String toString() {

        return suit_names[suit] + rank_names[rank];

    }

}

 

Player 

 

 

 

import java.util.ArrayList;

import java.util.List;

 

public class Player {

        private   int  id;

        private   String  name;

        //用来存储玩家的Card

        private  List<Card> list=new ArrayList<Card>();

        public  void  add(Card  card){

             list.add(card);

        }

        public Player() {

        }

        public Player(int id, String name) {

            this.id = id;

            this.name = name;

        }

        public int getId() {

            return id;

        }

        public void setId(int id) {

            this.id = id;

        }

        public String getName() {

            return name;

        }

        public void setName(String name) {

            this.name = name;

        }

        public List<Card> getList() {

            return list;

        }

        public void setList(List<Card> list) {

            this.list = list;

        }

       

       

       

}

 

Contorller 

 

 

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

 

/**

 * 类名称:Controller  

 * 类描述:  

 * 创建人:li72  

 * 创建时间:2012-7-6 上午11:56:32  

 * 修改人:li72  

 * 修改时间:2012-7-6 上午11:56:32  

 * 修改备注:  

 

 */

public class Controller {

      

       public static void main(String[] args) {

             

              Player p1=new Player(1,"huang");

              Player p2=new Player(2,"zhou");

              Player p3=new Player(3,"li");

             

              Player []players={p1,p2,p3};

             

              List<Card> cards=new ArrayList<Card>();

             

              for(int rank=Card.THREE;rank<=Card.DEUCE;rank++){

                    

                     cards.add(new Card(rank,Card.DIAMOND));

                     cards.add(new Card(rank,Card.HEART));

                     cards.add(new Card(rank,Card.CLUB));

                     cards.add(new Card(rank,Card.SPADE));

                    

              }

             

              cards.add(new Card(Card.BLACK,Card.JOKER));

              cards.add(new Card(Card.COLOR,Card.JOKER));

             

             

              System.out.println(cards.size());

             

              Collections.shuffle(cards);

             

              for(int i=0;i<players.length;i++){

                     for (int j = 0; j < 17; j++) {

                            players[i].getList().add(cards.remove(0));

                     }

              }

             

             

              for (int i = 0; i < players.length; i++) {

                     System.out.println(players[i].getName()+players[i].getList());

              }

             

              System.out.println("剩余牌数");

              for(int i=0;i<cards.size();i++){

                     System.out.print(cards.get(i)+"  ");

              }

       }

      

 

}

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值