三人斗地主的生成、发牌、洗牌(暂无手牌排序)
用Java来编写这样的小游戏
功能:
每人17张牌
留三张底牌
缺陷:
暂时不能将手牌有规律的排序
源码:
package com
.company
;
import java
.lang
.reflect
.Array
;
import java
.util
.ArrayList
;
import java
.util
.Collections
;
import java
.util
.List
;
public class DouDiZhu {
public static void main
(String
[] args
) {
List
<String> pokes
= new ArrayList<>();
List
<String> colors
= new ArrayList<>();
List
<String> numbers
= new ArrayList<>();
colors
.add("♥");
colors
.add("♠");
colors
.add("♦");
colors
.add("♣");
numbers
.add("A");
for (int i
= 2; i
<= 10; i
++) {
numbers
.add(i
+ "");
}
numbers
.add("J");
numbers
.add("Q");
numbers
.add("K");
for (String c
: colors
) {
for (String n
: numbers
) {
String pai
= c
+ n
;
pokes
.add(pai
);
}
}
pokes
.add("大王");
pokes
.add("小王");
System
.out
.println("牌" + pokes
);
Collections
.shuffle(pokes
);
System
.out
.println("洗牌之后" + pokes
);
ArrayList
<String> me
= new ArrayList<>();
ArrayList
<String> dabaobei
= new ArrayList<>();
ArrayList
<String> xiaobaobei
= new ArrayList<>();
ArrayList
<String> dipai
= new ArrayList<>();
for (int i
= 0; i
< pokes
.size(); i
++) {
String pai
= pokes
.get(i
);
if (i
>= 51) {
dipai
.add(pai
);
} else if (i
% 3 == 0) {
me
.add(pai
);
} else if (i
% 3 == 1) {
dabaobei
.add(pai
);
} else {
xiaobaobei
.add(pai
);
}
}
System
.out
.println(dipai
);
System
.out
.println("我"+me
);
System
.out
.println("大宝贝"+dabaobei
);
System
.out
.println("小宝贝"+xiaobaobei
);
}
}
输出结果:
转载请注明原文地址:https://ipadbbs.8miu.com/read-1717.html