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;
}

}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Programming Life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值