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 poke = new HashMap<>();

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

        ArrayList pokeIndex = new ArrayList<>();

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

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

        List 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 play01 = new ArrayList<>();

        List play02 = new ArrayList<>();

        List play03 = new ArrayList<>();

        List 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 poke,List player) {

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

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

        for (Integer ker : player) {

            String value = poke.get(ker);

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

        }

        System.out.println();

    }

}

你可能感兴趣的:(java,游戏,其他,数据结构)