日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

斗地主案例的代码实现

發(fā)布時(shí)間:2024/4/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 斗地主案例的代码实现 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package com.learn.demo04.Test;import java.util.ArrayList; import java.util.Collections;/*斗地主綜合案例:1.準(zhǔn)備牌2.洗牌3.發(fā)牌4.看牌*/ public class DouDiZhu {public static void main(String[] args) {//1.準(zhǔn)備牌//定義一個(gè)存儲(chǔ)54張牌的ArrayList集合,泛型使用StringArrayList<String> poker = new ArrayList<>();//定義兩個(gè)數(shù)組,一個(gè)數(shù)組存儲(chǔ)牌的花色,一個(gè)數(shù)組存儲(chǔ)牌的序號(hào)String[] colors = {"?","?","?","?"};String[] numbers = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};//先把大王和小王存儲(chǔ)到poker集合中poker.add("大王");poker.add("小王");//循環(huán)嵌套遍歷兩個(gè)數(shù)組,組裝52張牌for(String number : numbers){for (String color : colors) {//System.out.println(color+number);//把組裝好的牌存儲(chǔ)到poker集合中poker.add(color+number);}}//System.out.println(poker);/*2.洗牌使用集合的工具類Collections中的方法static void shuffle(List<?> list) 使用默認(rèn)隨機(jī)源對(duì)指定列表進(jìn)行置換。*/Collections.shuffle(poker);//System.out.println(poker);/*3.發(fā)牌*///定義4個(gè)集合,存儲(chǔ)玩家的牌和底牌ArrayList<String> player01 = new ArrayList<>();ArrayList<String> player02 = new ArrayList<>();ArrayList<String> player03 = new ArrayList<>();ArrayList<String> diPai = new ArrayList<>();/*遍歷poker集合,獲取每一張牌使用poker集合的索引%3給3個(gè)玩家輪流發(fā)牌剩余3張牌給底牌注意:先判斷底牌(i>=51),否則牌就發(fā)沒(méi)了*/for (int i = 0; i < poker.size() ; i++) {//獲取每一張牌String p = poker.get(i);//輪流發(fā)牌if(i>=51){//給底牌發(fā)牌diPai.add(p);}else if(i%3==0){//給玩家1發(fā)牌player01.add(p);}else if(i%3==1){//給玩家2發(fā)牌player02.add(p);}else if(i%3==2){//給玩家3發(fā)牌player03.add(p);}}//4.看牌System.out.println("劉德華:"+player01);System.out.println("周潤(rùn)發(fā):"+player02);System.out.println("周星馳:"+player03);System.out.println("底牌:"+diPai);} }

?

總結(jié)

以上是生活随笔為你收集整理的斗地主案例的代码实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。