Implementing a bucket landlord through Java

Source: Internet
Author: User

Functions: Shuffle, licensing, the hands of the players to sort the cards, to see the cards

 Packagedemo06;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.HashMap;/** *  * @authorAdministrator * Realize the function of simulated bucket landlord * 1. Combo Card * 2. Shuffle * 3. Licensing * 4. Look at the cards*/ Public classDoudizhu { Public Static voidMain (string[] args) {//1. Combo Card//Create Map collection, key is number, value is cardHashmap<integer, string> pooker=NewHashmap<>(); //Create a list collection, store numberingArraylist<integer> pookernumber=NewArraylist<>(); //defines an array of 13 pointsstring[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8",                "7", "6", "5", "4", "3"}; //define four suit arraysString[] colors={"♥", "♠", "♣", "♦"}; //defines an integer variable that appears as a key        intindex=2;//first, avoid the size King .//traversal Array, color + points combination store to map collection         for(String number:numbers) { for(String color:colors) {pooker.put (Index,color+Number );                Pookernumber.add (index); Index++; }        }        //storage King, and Xiao WangPooker.put (0, "King")); Pookernumber.add (0); Pooker.put (1, "Xiao Wang"); Pookernumber.add (1); //Shuffle, the number of cards upsetcollections.shuffle (Pookernumber); //Licensing function, the card number, sent to the player set, hole setArraylist<integer> player1=NewArraylist<>(); ArrayList<Integer> player2=NewArraylist<>(); ArrayList<Integer> player3=NewArraylist<>(); ArrayList<Integer> bottom=NewArraylist<>(); //the licensing is in set index%3         for(intI=0;i<pookernumber.size (); i++){            //do the cards first .            if(i<3){                //save it to the hole.Bottom.add (Pookernumber.get (i)); }                        //judgment on index%3            Else if(i%3==0){                //number on index, sent to player 1Player1.add (Pookernumber.get (i)); }Else if(i%3==1){                //number on index, sent to player 2Player2.add (Pookernumber.get (i)); }Else if(i%3==2){                //number on index, sent to player 3Player3.add (Pookernumber.get (i)); }        }        //sort numbers in the hands of playersCollections.sort (Player1);        Collections.sort (PLAYER2);        Collections.sort (PLAYER3); //look at the card, the number of players in the hand, to the map set to find, according to the key to find the valueLook ("Andy Lau", Player1,pooker); Look ("Jacky Cheung", Player2,pooker); Look (Dawn, Player3,pooker); Look (Cards, Bottom,pooker); }     Public Static voidLook (String name,arraylist<integer> Player,hashmap<integer, string>Pooker) {        //iterate through the ArrayList collection, get the element, and, as a key, find the value in the collection mapSystem.out.println (name+ ":");  for(Integer key:player) {String value=Pooker.get (key); System.out.print (Value+" ");    } System.out.println (); }}

Implementing a bucket landlord through Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.