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

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

java第三季撲克牌游戲代碼

標(biāo)簽:
Java

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

public class player {
public int id;
public String name;
public List<poker> myPo = new ArrayList<poker>();
public player(int id,String name)
{
this.id = id;
this.name = name;
}
}

public class poker implements Comparable<poker> {
public String flower;
public String num;
public Integer k;//定义点数大小
public Integer f;//定义花色大小
public poker(String flower,String num){
this.flower = flower;
this.num = num;
if(num.equals("J"))
{
this.k = 11;
}
else if(num.equals("Q"))
{
this.k = 12;
}
else if(num.equals("K"))
{
this.k = 13;
}
else if(num.equals("A"))
{
this.k = 14;
}
else
{
this.k = Integer.parseInt(num);
}
if(flower.equals("方块"))
{
this.f = 1;
}
else if(flower.equals("梅花"))
{
this.f = 2;
}
else if(flower.equals("红心"))
{
this.f = 3;
}
else
{
this.f = 4;
}
}

 public int compareTo(poker arg0){
     if(!(this.k==arg0.k))
     {
         return this.k.compareTo(arg0.k);
     }
     else
     {
         return this.f.compareTo(arg0.f);
     }

 }
 public String toString(){
     return (this.flower+this.num);
 }

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

public class PlayGame {
List<poker> allPokers = new ArrayList<poker>();
List<player> players = new ArrayList<player>();
public void createPokers(){
System.out.println("----------创建扑克牌----------");
String[] flowers = {"方块","梅花","红心","黑桃"};
String[] nums = {"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++)
{
allPokers.add(new poker(flowers[i],nums[j]));
}
}
System.out.println("----------扑克牌创建成功!----------");
System.out.print("为:"+allPokers.toString());

}

public void shuf(){
    System.out.println("----------开始洗牌...----------");
    Collections.shuffle(allPokers);
    System.out.println("----------洗牌结束!----------");
}

public void createPlayers(int num){
    System.out.println("----------创建玩家...----------");
    Scanner console = new Scanner(System.in);
    int id = 0;
    boolean isError = true;
    for(int i=0;i<num;i++)
    {
        System.out.println("请输入第"+(i+1)+"位玩家id和姓名:");

        while(isError)
        {
            System.out.println("输入id:");
            try{
                 console = new Scanner(System.in);  //所输入的非整型一直在扫描器,因此会陷入死循环
                 id = console.nextInt();
                 break;
                }catch(Exception e){
                    System.out.println("请输入整数类型的id!");

// String s = console.next();
}
}
System.out.println("输入姓名:");
String name = console.next();
players.add(new player(id,name));
}
for(player p:players)
{
System.out.println("欢迎玩家:"+p.name);
}
}

public void deal(int numOfPokes){
    System.out.println("----------开始发牌--------------");
    int j = 0;
    for(int i =0;i<numOfPokes;i++)
    {
        for(player p:players)
        {
            System.out.println("玩家:"+p.name+"-拿牌");
            p.myPo.add(allPokers.get(j++));
        }
    }
    System.out.println("----------发牌结束!----------");
}

public void startGame(){
    System.out.println("----------开始游戏----------");
    for(player p:players)
    {

// Collections.sort(p.myPo);
System.out.println("玩家:"+p.name+
"最大的手牌为:"+Collections.max(p.myPo).toString());
}
}
public void winOrLose(){
player winner = players.get(0);
for(int i=1; i<players.size()-1;i++)
{
poker p = Collections.max(players.get(i).myPo);
if(p.compareTo(Collections.max(winner.myPo))>1)
{
winner = players.get(i);
}
}
System.out.println("----------玩家:"+winner.name+"获胜!----------");
}
public void pokersOfPlayer(){
System.out.println("玩家各自的手牌为:");
for(player p:players)
{
System.out.println(p.name+":"+p.myPo.toString());
}
}

public static void main(String[] args) {
    PlayGame pg = new PlayGame();
    pg.createPokers();
    pg.shuf();
    pg.createPlayers(3);
    pg.deal(3);
    pg.startGame();
    pg.winOrLose();
    pg.pokersOfPlayer();
}

}

點(diǎn)擊查看更多內(nèi)容
8人點(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ì)
微信客服

購課補(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
提交
取消