1.準備牌
特殊牌:大王,小王
52張牌:迴圈巢狀遍歷兩個集合/陣列,組裝52張牌
string[
] colors=
; string[
] numbers=
;
2.洗牌
使用collections中的shuffle(list)方法
3.發牌
一人一張輪流發牌,沒人17張
集合索引%3
剩餘3張給底牌
4.排序
使用collections中的sort方法
sort(list)
5.看牌
遍歷乙個集合,獲取到另乙個集合的key
遍歷key查詢到value
遍歷玩家和底牌的list集合,獲取到map集合的可以,通過key找到value值
public
class
doudizhu
; string[
] numbers=
;int index=0;
poker.
put(index,
"大王");
pokerindex.
add(index++);
poker.
put(index,
"小王");
pokerindex.
add(index++);
for(string number:numbers)
}//2.洗牌
collections.
shuffle
(pokerindex)
;//3.發牌
arraylist
player1=
newarraylist
<
>()
; arraylist
player2=
newarraylist
<
>()
; arraylist
player3=
newarraylist
<
>()
; arraylist
dipai=
newarraylist
<
>()
;for
(int i=
0;isize()
;i++
)else
if(i%3==
0)else
if(i%3==
1)else
}//4.排序
collections.
sort
(player1)
; collections.
sort
(player2)
; collections.
sort
(player3)
; collections.
sort
(dipai)
;lookpoker
("玩家一"
,poker,player1);}
//5.看牌
public
static
void
lookpoker
(string name,hashmap
poker,arraylist
list)
system.out.
println()
;}}
鬥地主發牌
鬥地主的發牌 a 鬥地主的發牌 實現模擬鬥地主的功能 1.組合牌 2.洗牌 3.發牌 4.看牌 public class doudizhu 定義4個花色陣列 string colors 定義整數變數,作為鍵出現 int index 2 遍歷陣列,花色 點數的組合,儲存到map集合 for strin...
案例 鬥地主
案例分析 1 準備 準備54張牌,儲存到一的集合中,特殊牌大小王。其他52張牌 定義乙個陣列 集合,儲存4種花色 定義乙個陣列 集合,儲存13個符號1 2 3 4 5 迴圈遍歷兩個陣列 集合,組裝52張牌,儲存到乙個集合中。5,2,a 再加上大?和小?2 洗牌 使用集合工具collections的方...
鬥地主的規則 歡樂鬥地主的規則
鬥地主牌型 火箭 即雙王 大王和小王 最大的牌。四張同數值牌 如四個 7 單牌 單個牌 如紅桃 5 對牌 數值相同的兩張牌 如梅花 4 方塊 4 三張牌 數值相同的三張牌 如三個 j 三帶一 數值相同的三張牌 一張單牌或一對牌。例如 333 6 或 444 99 飛機帶翅膀 三順 同數量的單牌 或同...