Java小程序(模拟斗地主发牌):考察集合的用法以及方法的调用
作者:互联网
测试类
package com.ujiuye.pokegame;
import java.util.ArrayList;
/**
- @Description 模拟斗地主发牌
- @author LiZiCheng Email:lizicheng_public@163.com
- @version
- @data 2021年3月9日下午7:29:55
*/
public class PokeGameTest {
public static void main(String[] args) {
ArrayList<String> poke_list = new ArrayList<String>();
ArrayList<String> people01 = new ArrayList<String>();
ArrayList<String> people02 = new ArrayList<String>();
ArrayList<String> people03 = new ArrayList<String>();
ArrayList<String> last_poke = new ArrayList<String>();
System.out.println("买回来的新牌:" + CreatePoke.createPoke(poke_list));
System.out.println("洗 牌:" + ShufflePoke.shufflePoke(poke_list));
System.out.println("给人物1发牌:" + SendTo_01.sendTo01(poke_list, people01));
System.out.println("给人物2发牌:" + SendTo_02.sendTo02(poke_list, people02));
System.out.println("给人物3发牌:" + SendTo_03.sendTo03(poke_list, people03));
System.out.println("剩余三张底牌:" + LastPoke.lastPoke(poke_list, last_poke));
}
}
类:创建扑克牌
package com.ujiuye.pokegame;
import java.util.ArrayList;
public class CreatePoke {
/**
* @Description 创建扑克牌
* @author LiZiCheng
* @data 2021年3月9日下午7:23:19
* @return
*/
public static ArrayList<String> createPoke(ArrayList<String> poke_list){
String[] color_arr = new String[] {"♠","♥","♣","♦"};
String[] num_arr = new String[] {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
int count = 0;
for(int i = 0;i < color_arr.length;i++) {
for(int j = 0;j < num_arr.length;j++) {
poke_list.add(color_arr[i] + num_arr[j]);
count ++;
}
}
poke_list.add("大王");
count++;
poke_list.add("小王");
count++;
System.out.println("一副牌一共有:" + count + "张");
return poke_list;
}
}
类:洗牌
package com.ujiuye.pokegame;
import java.util.ArrayList;
import java.util.Collections;
public class ShufflePoke {
/**
* @Description 洗牌
* @author LiZiCheng
* @data 2021年3月9日下午7:25:06
* @return
*/
public static ArrayList<String> shufflePoke(ArrayList<String> poke_list){
Collections.shuffle(poke_list);
return poke_list;
}
}
类:给三个人发牌
import java.util.ArrayList;
public class SendTo_01 {
/**
* @Description 给01人物发牌
* @author LiZiCheng
* @data 2021年3月9日下午7:35:21
* @param people01
* @return
*/
public static ArrayList<String> sendTo01(ArrayList<String> poke_list,ArrayList<String> people01){
for(int i = 0;i < poke_list.size() - 3;i++) {
if(i % 3 == 0) {
people01.add(poke_list.get(i));
}
}
return people01;
}
}
public class SendTo_02 {
/**
* @Description 给02人物发牌
* @author LiZiCheng
* @data 2021年3月9日下午7:35:41
* @param people02
* @return
*/
public static ArrayList<String> sendTo02(ArrayList<String> poke_list,ArrayList<String> people02){
for(int i = 0;i < poke_list.size() - 3;i++) {
if((i + 2) % 3 == 0) {
people02.add(poke_list.get(i));
}
}
return people02;
}
}
public class SendTo_03 {
/**
* @Description 给03人物发牌
* @author LiZiCheng
* @data 2021年3月9日下午7:36:10
* @param people03
* @return
*/
public static ArrayList<String> sendTo03(ArrayList<String> poke_list,ArrayList<String> people03){
for(int i = 0;i < poke_list.size() - 3;i++) {
if((i + 4) % 3 == 0) {
people03.add(poke_list.get(i));
}
}
return people03;
}
}
类:底牌
import java.util.ArrayList;
public class LastPoke {
/**
* @Description 获取底牌
* @author LiZiCheng
* @data 2021年3月9日下午8:15:08
* @return
*/
public static ArrayList<String> lastPoke(ArrayList<String> poke_list,ArrayList<String> last_poke){
for(int i = poke_list.size() - 1;i > poke_list.size() - 4;i--) {
last_poke.add(poke_list.get(i));
}
return last_poke;
}
}
标签:poke,Java,斗地主,ArrayList,list,public,return,发牌 来源: https://blog.csdn.net/lizicheng1996/article/details/114600413