用Java实现模拟斗地主:
import java.util.ArrayList;
import java.util.Collections;
public class PlayCards {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<>();
String [] color = {"红桃","黑桃","方块","梅花"};
String [] number = {"2","3","4","5","6","7","8","9","10","J","Q","K","A" };
for (String a:color
) {
for (String b:number
) {
arrayList.add(a+b);
}
}
arrayList.add("大王");
arrayList.add("小王");
Collections.shuffle(arrayList);
ArrayList<String> c =new ArrayList<String>();
ArrayList<String> d =new ArrayList<String>();
ArrayList<String> e =new ArrayList<String>();
ArrayList<String> f =new ArrayList<String>();
for (int i = 0; i <arrayList.size() ; i++) {
String s = arrayList.get(i);
if(i>=arrayList.size()-3)
{
f.add(s);
}else if(i%3==0)
{
c.add(s);
}else if(i%3==1)
{
d.add(s);
}else
{
e.add(s);
}
}
Showcard("张三",c);
Showcard("李四",d);
Showcard("王五",e);
Showcard("底牌",f);
}
public static void Showcard(String name,ArrayList<String> array)
{
System.out.println(name+"的牌是:");
for (String f:array
) {
System.out.print(f);
}
System.out.println("");
}
}