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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

借鑒很多前輩的代碼進(jìn)行的改造,可以創(chuàng)建玩家人數(shù)以及每位玩家發(fā)牌的數(shù)量,有不完善的地方還望多多指教

package?com.imooc;

/*
?*?撲克牌類
?*?實現(xiàn)Comparable接口用于比較大小
?*?*/
public?class?Card?implements?Comparable<Card>?{
????//牌的點數(shù)
????private?String?pokerpoints;
????//牌的花色
????private?String?pokercolor;
????//初始化構(gòu)造方法
????public?Card(String?pokerpoints,String?pokercolor){
????????this.pokerpoints=pokerpoints;
????????this.pokercolor=pokercolor;
????}
????
????public?Card(){
????????
????}

????
????

????public?String?getPokerpoints()?{
????????return?pokerpoints;
????}




????public?void?setPokerpoints(String?pokerpoints)?{
????????this.pokerpoints?=?pokerpoints;
????}




????public?String?getPokercolor()?{
????????return?pokercolor;
????}




????public?void?setPokercolor(String?pokercolor)?{
????????this.pokercolor?=?pokercolor;
????}
????
????

????@Override
????public?String?toString()?{
????????return?pokercolor+pokerpoints+"";
????}

????//重寫Comparable的compareTO方法
????@Override
????public?int?compareTo(Card?o)?{
????????//用來比較點數(shù)
????????String?ifpokerpoints="2,3,4,5,6,7,8,9,10,J,Q,K,A";
????????//用來比較花色
????????String?ifpokercolor="方片,梅花,紅桃,黑桃";
????????
????????//當(dāng)前撲克牌點數(shù)第一次出現(xiàn)的位置減去O對象撲克牌點數(shù)第一次出現(xiàn)的位置
????????????????int?i=ifpokerpoints.indexOf(o.getPokerpoints())-ifpokerpoints.indexOf(this.getPokerpoints());
????????????????//如果點數(shù)的位置相同那么點數(shù)是一樣的
????????????????if(i==0){
????????????????????//如果點數(shù)一樣那么比較花色的位置是否相同
????????????????????i=ifpokercolor.indexOf(o.getPokercolor())-ifpokercolor.indexOf(this.getPokercolor());
????????????????}
????????????????//返回i的值正數(shù)大于負(fù)數(shù)小于
????????????????return?i;
????????
????}

}


package?com.imooc;

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

/*
?*?正副撲克牌的類
?*?*/

public?class?Poker?{
????//用來存放撲克牌的集合
????List<Card>?listcard=new?ArrayList<Card>();
????
????//創(chuàng)建撲克牌
????public??void??creatPoker(){
????????System.out.println("-----創(chuàng)建撲克牌-----");
????????//定義一個牌數(shù)的數(shù)組
????????String[]?name={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
????????//定義一個花色數(shù)組
????????String[]?color={"方片","梅花","紅桃","黑桃"};
????????
????????//循環(huán)往撲克牌集合中添加撲克
????????for(int?i=0;i<name.length;i++){
????????????for(int?j=0;j<color.length;j++){
????????????????listcard.add(new?Card(name[i],color[j]));
????????????}
????????}
????????System.out.println(listcard);
????????System.out.println("-----創(chuàng)建完成-----");
????}
????
????//洗牌
????public?void?randompoker(){
????????System.out.println("-----開始洗牌-----");
????????//調(diào)用Collections.shuffle()就可以實現(xiàn)順序打亂
????????Collections.shuffle(listcard);
????????System.out.println(listcard);
????????System.out.println("-----洗牌完成-----");
????}
????
????//獲取撲克牌的數(shù)量
????public?int?size(){
????????return?this.listcard.size();
????}
????//返回當(dāng)前撲克牌集合
????public?List<Card>?getlistCard(){
????????return?this.listcard;
????}
}


package?com.imooc;

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

/*
?*?玩家類
?*?包括玩家id,玩家姓名
?*?玩家手中最大的牌和存放玩家手牌的集合
?*?*/
public?class?Player?implements?Comparable<Player>?{
????//玩家id
????private?int?id;
????//玩家姓名
????private?String?name;
????//玩家手中最大的牌
????private?Card?maxcard;
????//存放玩家手牌的集合
????private?List<Card>?cards=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?List<Card>?getCards()?{
????????return?cards;
????}
????public?void?setCards(List<Card>?cards)?{
????????this.cards?=?cards;
????}
????
????
????//構(gòu)造方法
????public?Player(int?id,String?name){
????????this.id=id;
????????this.name=name;
????}
????
????//獲取玩家手中最大的牌
????public?Card?getMaxcard(){
????????//先排序,Card類中重寫了comprarTo()方法,下標(biāo)為0的是最大的值
????????Collections.sort(cards);
????????//返回獲取到的最大的值
????????return?this.maxcard=cards.get(0);
????}
????
????
????
????@Override
????public?int?compareTo(Player?o)?{
????????//?根據(jù)玩家手中最大的牌進(jìn)行排序,獲勝的玩家排在最前面
????????return?this.getMaxcard().compareTo(o.getMaxcard());
????????
????}
????
????//玩家拿牌的方法
????public?void?add(Card?card){
????????System.out.println("玩家:"+this.name+"拿牌:"+card);
????????//添加到手牌集合
????????this.cards.add(card);
????}
????
????
????//輸出玩家最大的手牌
????public?void?showMax(){
????????System.out.println("玩家:"+this.name+"的最大手牌為:"+this.getMaxcard());
????}
}


package?com.imooc;

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

/*
?*?撲克牌游戲類
?*?創(chuàng)建玩家
?*?根據(jù)輸入的玩家信息進(jìn)行發(fā)牌
?*?最后比較大小
?*?*/
public?class?PokerGema?{
????//存放玩家的集合
????private?List<Player>?listplayer=new?ArrayList<Player>();
????//整幅撲克牌的類
????Poker?poker=new?Poker();
????//接收用戶輸入的信息
????private?Scanner?scanner=new?Scanner(System.in);
????//保存玩家的人數(shù)
????int?number=0;
????
????//創(chuàng)建玩家人數(shù)
????public?void?creatplayerNumber(){
????????System.out.println("撲克牌的總數(shù)為:"+poker.size());
????????System.out.println("-----請輸入要創(chuàng)建的玩家人數(shù)-----");
????????//判斷鍵盤是否有輸入,當(dāng)有輸入時進(jìn)行循壞
????????while(scanner.hasNext()){????????????
????????????//判斷輸入的值是否為整形,當(dāng)為整形時執(zhí)行循壞
????????????if(scanner.hasNextInt()){
????????????????int?j=scanner.nextInt();
????????????????//判斷輸入的值是否大于2并且小于撲克牌的數(shù)量
????????????????if(j>1&&j<poker.size()){
????????????????????//接收用戶輸入的信息
????????????????????number=j;????????????????
????????????????????break;
????????????????}else{
????????????????????System.out.println("請輸入正確的玩家人數(shù)");
????????????????????System.out.println("玩家人數(shù)要大于2,并且小于撲克牌的總數(shù):"+poker.size());
????????????????????continue;//繼續(xù)循環(huán)
????????????????}
????????????????
????????????}else{
????????????????System.out.println("請輸入數(shù)字哦!");
????????????????//清空scanner的數(shù)據(jù)
????????????????scanner.next();
????????????????continue;//繼續(xù)循環(huán)
????????????}
????????}
????????//循環(huán)添加玩家
????????for(int?i=1;i<=number;i++){
????????????System.out.println("請輸入第:"+i+"個玩家姓名");
????????????listplayer.add(new?Player(i,scanner.next()));//添加玩家
????????}
????????//循壞輸出玩家信息
????????for?(Player?player?:?listplayer)?{
????????????System.out.println("歡迎玩家:"+player.getName());
????????}
????????????
????}
????
????
????//開始創(chuàng)建撲克牌
????public?void?StartCreatingPoker(){
????????//創(chuàng)建撲克牌
????????poker.creatPoker();
????????//洗牌
????????poker.randompoker();
????}
????//發(fā)牌
????public?void?dealpoker(){
????????//提示用戶輸入信息
????????System.out.println("請設(shè)置每位玩家發(fā)多少張牌");
????????System.out.println("每位玩家發(fā)牌的數(shù)量必須大于0并且發(fā)牌的總數(shù)不能超過撲克牌的數(shù)量:"+poker.size());
????????//用于保存每位玩家發(fā)牌的數(shù)量
????????int?i=0;
????????//判斷是否有輸入
????????while(scanner.hasNext()){
????????????//判斷輸入的是否是int型
????????????if(scanner.hasNextInt()){
????????????????int?j=scanner.nextInt();//將輸入的值賦值給j;
????????????????int?k=j*number;//計算玩家人乘以每位玩家發(fā)牌的牌數(shù)得到總的發(fā)牌數(shù)量
????????????????//判斷每位玩家的牌數(shù)要大于0并且小于撲克牌的數(shù)量
????????????????if(j>0&&k<poker.size()){
????????????????????i=j;
????????????????????break;//跳出循環(huán)
????????????????}else{
????????????????????System.out.println("每位玩家發(fā)牌的數(shù)量必須大于0并且小于撲克牌的總數(shù):"+poker.size());
????????????????????continue;//繼續(xù)循環(huán)
????????????????}
????????????}else{
????????????????System.out.println("請輸入整數(shù)");
????????????????//清空scanner輸入的信息
????????????????scanner.next();
????????????????continue;//繼續(xù)循環(huán)
????????????}
????????}
????????//每位玩家發(fā)牌的數(shù)量乘以玩家的人數(shù)得到發(fā)牌的總數(shù)
????????int?pokernumber=i*number;????
????????//每位玩家拿牌的數(shù)量乘以玩家的人數(shù)得到發(fā)牌的總數(shù),然后總數(shù)多少就循環(huán)多少次
????????for(int?j=0;j<pokernumber;){
????????????//依次向玩家1添加撲克牌1,玩家2添加撲克牌2,玩家1添加撲克牌3,玩家2添加撲克牌4.。。。。。
????????????for(int?b=0;b<number;b++){
????????????????//獲得每位玩家然后依次添加撲克牌
????????????????listplayer.get(b).add(poker.getlistCard().get(j));
????????????????j++;//每次基數(shù)加一
????????????}
????????}
????????????
????}
????
????//輸出玩家手中各自的手牌和最大的撲克牌
????public?void?PlayerMaxPoker(){
????????//輸出玩家各自的手牌
????????for?(Player?playername?:?listplayer)?{
????????????System.out.println("玩家:"+playername.getName()+"的手牌為:"+playername.getCards().toString());
????????}
????????
????????
????????//輸出最大的手牌
????????for?(Player?playername?:?listplayer)?{
????????????playername.showMax();
????????}
????}
????
????//比較大小,根據(jù)玩家手中最大的牌進(jìn)行排序
????public?void?comparePlayer(){
????????Collections.sort(listplayer);
????????System.out.println("玩家:"+listplayer.get(0).getName()+"獲勝!");
????}
????

}


package?com.imooc;

public?class?Test?{

????/**
?????*主程序測試類
?????*/
????public?static?void?main(String[]?args)?{
????????//創(chuàng)建撲克牌游戲類的實例
????????PokerGema?pokergema=new?PokerGema();
????????//創(chuàng)建撲克牌
????????pokergema.StartCreatingPoker();
????????//創(chuàng)建玩家
????????pokergema.creatplayerNumber();
????????//發(fā)牌
????????pokergema.dealpoker();
????????////輸出玩家手中各自的手牌和最大的撲克牌
????????pokergema.PlayerMaxPoker();
????????//比較大小,根據(jù)玩家手中最大的牌進(jìn)行排序
????????pokergema.comparePlayer();

????}

}


正在回答

舉報

0/150
提交
取消

借鑒很多前輩的代碼進(jìn)行的改造,可以創(chuàng)建玩家人數(shù)以及每位玩家發(fā)牌的數(shù)量,有不完善的地方還望多多指教

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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