第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

JAVA第三季第7章簡(jiǎn)易撲克游戲

標(biāo)簽:
Java
package com.poker;

/**
 * 单张扑克牌
 * @author Administrator
 *
 */
public class Card implements Comparable<Card>{

    //花色
    private String huase;

    //点数
    private String data;

    //用来比较卡牌大小的2条属性
    //根据点数
    private int num;
    //根据花色
    private int col;

    public String getHuase() {
        return huase;
    }
    public void setHuase(String huase) {
        this.huase = huase;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }

    public int getNum() {
        return num;
    }
    public void setNum(int num) {
        this.num = num;
    }
    public int getCol() {
        return col;
    }
    public void setCol(int col) {
        this.col = col;
    }
    //构造函数
    public Card(String huase,String data,int num,int col){
        this.huase=huase;
        this.data=data;
        this.num=num;
        this.col=col;
    }

    public Card(){

    }
    @Override
    public int compareTo(Card o) {
        if(this.num>o.num)
            return 1;
        else if(this.num==o.num&&this.col>o.col)
            return 1;
        else 
            return -1;
    }

}
package com.poker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * 一整副扑克牌的List,包含了创建扑克牌和洗牌方法
 * @author Administrator
 *
 */
public class Poker{
    public List<Card> cardList=new ArrayList<Card>();//创建一副空扑克牌List

    //添加扑克牌的值
    public void createPoker(){
        System.out.println("----------------创建扑克牌------------------");
        String[] st1=new String[]{"黑桃","红心","梅花","方块"};
        String[] st2=new String[]{"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
        for(int i=0;i<4;i++){
            for(int j=0;j<13;j++){
                this.cardList.add(new Card(st1[i],st2[j],j,i));
            }
        }
        System.out.println("----------------扑克牌创建成功------------------");
        System.out.print("为:[");
        for (Card card : cardList) {
            System.out.print(card.getHuase()+card.getData()+",");
        }
        System.out.println("]");
    }

    //洗牌
    public void shufflePoker(){
        Collections.shuffle(cardList);
    }

}
package com.poker;

import java.util.ArrayList;
import java.util.List;
/**
 * 玩家
 * @author Administrator
 *
 */
public class Player{
    private int id;//玩家ID
    private String name;//玩家姓名
    public List<Card> handList=new ArrayList<Card>();;//玩家手牌

    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 Player(int id,String name){
        this.id=id;
        this.name=name;
    }
    public Player(){
    }

}
package com.poker;

import java.util.Collections;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * 游戏开始
 * @author Administrator
 *
 */
public class Play {

    public static void main(String[] args) {
        Poker poker=new Poker();//创建扑克对象
        Player[] pl=new Player[2];
        //创建扑克牌
        poker.createPoker();
        //洗牌
        System.out.println("----------------开始洗牌------------------");
        poker.shufflePoker();
        System.out.println("----------------洗牌结束------------------");
        for (Card card : poker.cardList) {
            System.out.print(card.getHuase()+card.getData()+",");
        }
        System.out.println("----------------创建玩家------------------");

        while(true){

            try{
                Scanner s=new Scanner(System.in);
                for(int j=0;j<2;j++){
                    System.out.println("请输入第"+(j+1)+"位玩家的ID和姓名:");
                    System.out.println("输入ID:");
                    pl[j]=new Player();
                    int id=s.nextInt();
                    pl[j].setId(id);
                    System.out.println("输入姓名:");
                    String name=s.next();
                    pl[j].setName(name);

                }
                break;
            }catch(InputMismatchException e){
                System.out.println("输入格式错误,请根据提示重新输入!");
            }

        }
        System.out.println("-----欢迎玩家:"+pl[0].getName());
        System.out.println("-----欢迎玩家:"+pl[1].getName());
        //发牌
        System.out.println("----------------开始发牌------------------");

        pl[0].handList.add(poker.cardList.get(0));
        System.out.println("-----玩家:"+pl[0].getName()+"-拿牌");

        pl[1].handList.add(poker.cardList.get(1));
        System.out.println("-----玩家:"+pl[1].getName()+"-拿牌");

        pl[0].handList.add(poker.cardList.get(2));
        System.out.println("-----玩家:"+pl[0].getName()+"-拿牌");

        pl[1].handList.add(poker.cardList.get(3));
        System.out.println("-----玩家:"+pl[1].getName()+"-拿牌");

        System.out.println("----------------发牌结束------------------");
        System.out.println("----------------开始游戏------------------");
        Collections.sort(pl[0].handList);
        Collections.sort(pl[1].handList);
        //玩家1最大的手牌
        System.out.println("玩家:"+pl[0].getName()+"最大的手牌为:"+pl[0].handList.get(1).getHuase()+pl[0].handList.get(1).getData());
        //玩家2最大的手牌
        System.out.println("玩家:"+pl[1].getName()+"最大的手牌为:"+pl[1].handList.get(1).getHuase()+pl[1].handList.get(1).getData());

        if(pl[0].handList.get(1).compareTo(pl[1].handList.get(1))==1){
            System.out.println("----------------玩家:"+pl[0].getName()+"获胜------------------");
        }else
            System.out.println("----------------玩家:"+pl[1].getName()+"获胜------------------");

        System.out.println("玩家各自的手牌为:");
        System.out.println(pl[0].getName()+":"+pl[0].handList.get(0).getHuase()+pl[0].handList.get(0).getData()+","
                +pl[0].handList.get(1).getHuase()+pl[0].handList.get(1).getData());
        System.out.println(pl[1].getName()+":"+pl[1].handList.get(0).getHuase()+pl[1].handList.get(0).getData()+","
                +pl[1].handList.get(1).getHuase()+pl[1].handList.get(1).getData());
    }

}
點(diǎn)擊查看更多內(nèi)容
6人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消