Java游戏开发之斗地主-无界面开发

import java.util.ArrayList;

import java.util.Collections;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Scanner;

import java.util.Set;

 

public class Demo02Mymethod {

 

    public static void main(String[] args){ 

        //定义一个集合poke集合用来存储牌

        HashMap<Integer, String> poke = new HashMap<>();

        //pokeIndex这个集合是方便后期排序

        ArrayList<Integer> pokeIndex = new ArrayList<>();

        //首先定义两个集合用来存储数字和花色

        List<String> colors = List.of("♥","♣","♦","♠");

        List<String> numbers = List.of("2","A","K","Q","J","10","9","8","7","6","5","4","3");

        //首先把大王,小王存进去,index是下标,key对应的value值

        int index = 0;

        poke.put(index, "大王");

        pokeIndex.add(index);

        index++;

        poke.put(index, "小王");

        pokeIndex.add(index);

        index++;

        

        //下面是组装牌,图案和数字进行配对,然后存入poke里面

        for (String number : numbers) {

            for (String color : colors) {

                poke.put(index, number+color);

                pokeIndex.add(index);

                index++;

            }

        }

        //现在要进行洗牌

        Collections.shuffle(pokeIndex);

        

        

        //现在我要进行发牌,发牌要定义4个集合,分别是存储用户play01, play02,play03的牌,然后存储底牌的集合

        List<Integer> play01 = new ArrayList<>();

        List<Integer> play02 = new ArrayList<>();

        List<Integer> play03 = new ArrayList<>();

        List<Integer> downPoke = new ArrayList<>();

        //现在进行发牌

        for (int i = 0; i < poke.size(); i++) {

            if(i >= 51) {

                downPoke.add(pokeIndex.get(i));

            }else if(i % 3 == 0) {

                play01.add(pokeIndex.get(i));

            }else if(i % 3 == 1) {

                play02.add(pokeIndex.get(i));

            }else if(i % 3 == 2) {

                play03.add(pokeIndex.get(i));

            }

        }

        //现在我要把底牌以及三个玩家的牌进行排序

        Collections.sort(play01);

        Collections.sort(play02);

        Collections.sort(play03);

        Collections.sort(downPoke);

        

        //调用lookPoke方法进行看牌

        lookPoke("刘德华", poke, play03);

        lookPoke("李小龙", poke, play02);

        lookPoke("周润发", poke, play01);

        lookPoke("底牌", poke, downPoke);

    

    }

    

        //现在我要定义一个方法进行看牌

        public static void lookPoke(String name,HashMap<Integer, String> poke,List<Integer> player) {

        System.out.print(name+" :");

        //现在我要组装牌,所以哟啊使用遍历

        for (Integer ker : player) {

            String value = poke.get(ker);

            System.out.print(value+" ");

        }

        System.out.println();

    }

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Znovko

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

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

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

打赏作者

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

抵扣说明:

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

余额充值