實現模擬鬥地主

2021-10-25 10:05:01 字數 1641 閱讀 5877

/**

* 實現模擬鬥地主的功能

* 1.組合牌

* 2.洗牌

* 3.發牌

* 4.看牌

*/public

class

doudizhu

;// 定義4個花色陣列

string[

] colors =

;// 定義整數變數 作為鍵出現

int index =2;

// 遍歷陣列 花色+點數的組合,儲存到map集合

for(string number : numbers)

}//儲存大王 小王

poker.

put(0,

"大王");

pokernumber.

add(0)

; poker.

put(1,

"小王");

pokernumber.

add(1)

;// 洗牌功能 把牌的編號打亂

collections.

shuffle

(pokernumber)

;// 發牌功能 將牌編號,發給玩家集合,底牌集合

arraylist

player1 =

newarraylist

(); arraylist

player2 =

newarraylist

(); arraylist

player3 =

newarraylist

(); arraylist

boottm =

newarraylist

();// 發牌採用的是集合索引%3

for(

int i =

0; i < pokernumber.

size()

; i++

)else

if(i %3==

0)else

if(i %3==

1)else

if(i %3==

2)}//對玩家手中的牌進行排序

collections.

sort

(player1)

; collections.

sort

(player2)

; collections.

sort

(player3)

;// 看牌

look

("player1"

,player1,poker)

;look

("player2"

,player2,poker)

;look

("player3"

,player3,poker)

;look

("底牌"

,boottm,poker);}

public

static

void

look

(string name,arraylist

player,hashmap

poker)

system.out.

println()

;}}

鬥地主模擬java原始碼

方法一 發出的牌隨機排序沒有使用 public static void main string args string num 迴圈巢狀兩個陣列 拼接牌 for int i 0 i huase.length i system.out.println pai 輸出所有的牌 2 洗牌 把牌的順序打亂 c...

模擬鬥地主洗牌和發牌

分析 a 建立乙個牌盒 b 裝牌 c 洗牌 d 發牌 e 看牌 public class test system.out.println public static void main string args 定義乙個點陣列 string numbers for string c colors ar...

小專案 模擬鬥地主發牌

a 鬥地主的功能分析 a 具體規則 1.組裝54張撲克牌 2.將54張牌順序打亂 3.三個玩家參與遊戲,三人交替摸牌,每人17張牌,最後三張留作底牌。4.檢視三人各自手中的牌 按照牌的大小排序 底牌 b 分析 1.準備牌 完成數字與紙牌的對映關係 使用雙列map hashmap 集合,完成乙個數字與...