当前位置:网站首页>Case - simulated landlords (primary version)

Case - simulated landlords (primary version)

2022-06-13 05:05:00 Jason_ LH1024

package it.com;

import java.util.ArrayList;
import java.util.Collections;

public class Poker {
    public static void main(String[] args) {
        // Create a card box , That is to define a collection object , use ArrayList Set implementation 
        ArrayList<String> array = new ArrayList<>();

        // Put cards in the card box 
     /*
     2,3,4,5,6,,,,k,A,
     2,...
     2,...
     2,...
      King , Xiao Wang 
      */
        // Define an array of decors 
        String[] colors = {"", "", "", ""};
        String[] numbers = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
        for (String color : colors) {
            for (String number : numbers) {
                array.add(color + number);

            }
        }
        array.add(" King ");
        array.add(" Xiao Wang ");

        // Shuffle , That is to break up the cards , use Collections Of shuffle() Method realization 
        Collections.shuffle(array);

        //  System.out.println(array);
        // Deal is to traverse the set , Deal cards to three players 
        ArrayList<String> fulong = new ArrayList<>();
        ArrayList<String> zhonglong = new ArrayList<>();
        ArrayList<String> pinlong = new ArrayList<>();
        ArrayList<String> dipai = new ArrayList<>();

        for (int i = 0; i < array.size(); i++) {
            String poker = array.get(i);
            if (i >= array.size() - 3) {
                dipai.add(poker);
            } else if (i % 3 == 0) {
                fulong.add(poker);
            } else if (i % 3 == 1) {
                zhonglong.add(poker);
            } else if (i % 3 == 2) {
                pinlong.add(poker);
            }
        }
    // Look at cards , That is, three players traverse their cards respectively 
        lookPoker(" Rich peasants ",fulong);
        lookPoker(" Middle peasants ",zhonglong);
        lookPoker(" The poor peasants ",pinlong);
        lookPoker(" a hand ",dipai);



    }
    // How to look at the cards 
    public static void lookPoker(String name,ArrayList<String> array){
        System.out.print(name+" The card is :");
        for (String poker:array) {
            System.out.print(poker+" ");
        }
        System.out.println();

        
    }
}

原网站

版权声明
本文为[Jason_ LH1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280515587696.html