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

Easy扑克牌(没边玩,实现不了扑克牌大小的比较及用户拿牌的存储)

标签:
Java

玩家类

package com.project5;
**加粗文字**
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.project5.Puke;

public class User {
    public int id;
    public String name;
    public static List<Puke> pukess;
    public User(int id, String name) {
        this.id = id;
        this.name = name;
        this.pukess = new ArrayList<Puke>();
    }

}

扑克牌类

package com.project5;

public class Puke  {
    String collor;
    String num;
    public Puke(String collor, String num) {
        this.collor = collor ;

        this.num = num;
    }
}

系统类

package com.project5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;

import com.project5.User;

public class easyGame {
    public static Map<Integer, User> Users;
    public static List<Puke> pukes;
    private Random random;
    private Scanner console;
    public easyGame() {
        this.pukes = new ArrayList<Puke>();
        console = new Scanner(System.in);
        random = new Random();
        this.Users = new HashMap<Integer, User>();
    }
    public void add(){
        String col = null;
        for(int i=0;i<4;i++){
            switch(i){
                case 0:col="黑桃";
                        break;
                case 1:col="红桃";
                        break;
                case 2:col="梅花";
                        break;
                case 3:col="方片";
                        break;
            }
            for(Integer j=2;j<15;j++){
                String k =j+"";
                Puke pk = new Puke(col,k);
                pukes.add(pk); 
            }
        }
    }
    public void xiPai(){
        for(int i =0;i<1000;i++){
            int m = random.nextInt(52);
            int n = random.nextInt(52);
            Puke puck1 = pukes.get(m);
            Puke puck2 = pukes.get(n);
            pukes.set(n, puck1);
            pukes.set(m, puck2);
        }
    }
    public void showPai(){
        for (Object puke :pukes) {
            Puke yy = (Puke)puke;
            Integer jj = Integer.valueOf(yy.num);
            if(jj>10){
                switch(Integer.valueOf(yy.num)){
                    case 11:System.out.print(yy.collor+"J"+" ");
                            break;
                    case 12:System.out.print(yy.collor+"Q"+" ");
                            break;
                    case 13:System.out.print(yy.collor+"K"+" ");
                            break;
                    case 14:System.out.print(yy.collor+"A"+" ");
                            break;
                }
            }else{
            System.out.print(yy.collor+yy.num+" ");
            }
        }
        System.out.println("");
    }
    public void clibUser(int i){
        int j = i;
        for(;;){
            System.out.println("输入ID:");
            try{
                int id = console.nextInt();
                System.out.println("输入姓名:");
                String name = console.next();
                User cr= new User(id,name);
                Users.put(j, cr);
                break;
            }catch(Exception e){
                System.out.println("请输入整数类型的ID!");
                continue;
            }
        }
    }
    public void faPai(){
        for(int i=1;i<=4;i++){
            if(i%2==1){
                System.out.println("-----玩家:"+Users.get(1).name+"拿牌");

                Puke cv= pukes.get(i-1);
                Users.get(1).pukess.add(cv);
            }else{
                System.out.println("-----玩家:"+Users.get(2).name+"拿牌");
                Puke av= pukes.get(i-1);
                Users.get(2).pukess.add(av);
            }
        }
    }
    public void Dx(User newuser){
        User user = newuser;

        if(user.pukess.get(0).num==user.pukess.get(1).num){
            int n = 0;
            int m = 0;
            switch(user.pukess.get(0).collor){
            case "黑桃":m=4;
                    break;
            case "红桃":m=3;
                    break;
            case "梅花":m=2;
                    break;
            case "方片":m=1;
                    break;
            }
            switch(user.pukess.get(1).collor){
            case "黑桃":n=4;
                        break;
            case "红桃":n=3;
                        break;
            case "梅花":n=2;
                        break;
            case "方片":n=1;
                        break;
            }
            if(m>n){
                System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+user.pukess.get(0).num);
            }else{
                System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+user.pukess.get(1).num);
            }
        }else if(Integer.valueOf(user.pukess.get(0).num)>Integer.valueOf(user.pukess.get(1).num)){
            int jj = Integer.valueOf(user.pukess.get(0).num);
            if(jj>10){
                switch(jj){
                    case 11:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+"J"+" ");
                            break;
                    case 12:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+"Q"+" ");
                            break;
                    case 13:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+"K"+" ");
                            break;
                    case 14:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+"A"+" ");
                            break;
                }
            }else{
            System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(0).collor+user.pukess.get(0).num);
            }
        }else{
            int kk = Integer.valueOf(user.pukess.get(1).num);
            if(kk>10){
                switch(kk){
                    case 11:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+"J"+" ");
                            break;
                    case 12:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+"Q"+" ");
                            break;
                    case 13:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+"K"+" ");
                            break;
                    case 14:System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+"A"+" ");
                            break;
                }
            }
            System.out.println("玩家:"+user.name+"最大的手牌为:"+user.pukess.get(1).collor+user.pukess.get(1).num);
        }

    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        easyGame game = new easyGame();
        System.out.println("------------------创建扑克牌-----------------");
        game.add();
        System.out.println("----------------扑克牌创建成功!---------------");

        game.showPai();
        System.out.println("-------------------开始洗牌------------------");
        game.xiPai();
        game.showPai();
        System.out.println("-------------------洗牌结束------------------");
        System.out.println("-------------------创建玩家------------------");
        for(int i=1;i<3;i++){
            System.out.println("请输入第"+i+"玩家的ID和姓名:");
            game.clibUser(i);
        }
        for(int i=1;i<3;i++){
            System.out.println("-----欢迎玩家:"+Users.get(i).name);
        }
        System.out.println("------------------开始发牌...----------------");
        game.faPai();
        System.out.println("------------------发牌结束-------------------");
        System.out.println("------------------开始游戏...----------------");

        game.Dx(Users.get(1));
        game.Dx(Users.get(2));
        System.out.println("------------------游戏结束-------------------");
        System.out.println("玩家各自的手牌为:");
        for(int i =1;i<3;i++){
            System.out.print(Users.get(i).name+":");
            for(int j=0;i<2;i++){
                int jj = Integer.valueOf(Users.get(i).pukess.get(j).num);
                if(jj>10){
                    switch(jj){
                    case 11:System.out.print(Users.get(i).pukess.get(j).collor+"J"+" ");
                            break;
                    case 12:System.out.print(Users.get(i).pukess.get(j).collor+"Q"+" ");
                            break;
                    case 13:System.out.print(Users.get(i).pukess.get(j).collor+"K"+" ");
                            break;
                    case 14:System.out.print(Users.get(i).pukess.get(j).collor+"A"+" ");
                            break;
                    }
                }else{
                    System.out.println(Users.get(i).pukess.get(j).collor+Users.get(i).pukess.get(j).num+" ");

                }
            }
        }
    }
}

图片描述

图片描述

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消