简易扑克牌游戏

java 练习3:
实现:
创建玩家,玩家在一副扑克牌中(不含大小王)获得手牌,取二人手中点数最大的牌进行比较,点数大的赢,点数相同比花色。
不足:
关于功能的拓展

package pokergame;

import java.util.ArrayList;
import java.util.List;

public class Player {
    private int ID;
    private String name;
    private List Handcards;
    
    public Player(int ID,String name) {
        this.ID=ID;
        this.name=name;
        this.Handcards=new ArrayList();
    }

    public int getID() {
        return ID;
    }

    public String getName() {
        return name;
    }

    public List getHandcards() {
        return Handcards;
    }
}
package pokergame;

import java.util.Arrays;
import java.util.List;

public class Cards implements Comparable {
    private String number;
    private String color;
    
    public Cards() {
    }
    
    public Cards(String number,String color) {
        this.number=number;
        this.color=color;
    }
    
    public String getNumber() {
        return number;
    }
    
    public String getColor() {
        return color;
    }
    
    @Override
    public int compareTo(Cards o) {
        List valueBase = Arrays.asList("2","3","4","5","6",
                "7","8","9","10","J","Q","K","A");
        List colorBase = Arrays.asList("黑桃","梅花","方块","红桃");
        if(valueBase.indexOf(this.number) == valueBase.indexOf(o.number))
            return Integer.valueOf(colorBase.indexOf(this.color)).
                    compareTo(Integer.valueOf(colorBase.indexOf(o.getColor())));
        else 
            return Integer.valueOf(valueBase.indexOf(this.number)).
                  compareTo(Integer.valueOf(valueBase.indexOf(o.getNumber())));
    }
    
    @Override
    public String toString() {
        return color+number;
    }
}
package pokergame;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Game {
    public static Scanner sc=new Scanner(System.in);
    public static final int CARDSNUM=52;
    public static void main(String[] args) {
        List players=new ArrayList();
        System.out.println("欢迎来到扑克世界!~~~");
        System.out.println("------------------创建一副扑克");
        List Pokers=createPokers();
        System.out.println("------------------开始洗牌");
        Collections.shuffle(Pokers);
        //System.out.println(Pokers.toString());
        System.out.println("------------------洗牌结束");
        System.out.println("请输入玩家数量(2-17):");
        while(true) {
            int player=playerNum();
            if(player>17) {
                System.out.println("玩家数量超出限制!请重新输入!");
            }else if(player<2) {
                System.out.println("Are you kidding me??请重新输入!");
            }else {
                //输入玩家信息
                for(int i=0;i createPokers(){
        List cards=new ArrayList();
        for(int i=0;i

你可能感兴趣的:(简易扑克牌游戏)