Java Learning Note 34 (Set Frame VIII: Comprehensive case: Simulation of the Landlord's shuffle Licensing)

Source: Internet
Author: User
Tags shuffle

Rules:

1.54 cards, with suit

2. Order disruption, one person a card in turn, one person 17, leave three card as a hole card

3. Look at the cards: by the size of the King 2A .... 43 Sequential Print

Example:

 Packagedemo;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.HashMap; Public classDoudizhu { Public Static voidMain (string[] args) {//Create Map collection, key is number, value is cardHashmap<integer, string> pooker =NewHashmap<integer, string>(); //List Collection Storage number//set reason with list: You can call the Sort methodArraylist<integer> Pookernumber =NewArraylist<integer>(); //since 13 points are constant, the array is definedstring[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" }; //color constant, defining arraysstring[] colors = {"?", "?", "?", "?" }; //define integer variables, as keys, 0 and 1 are left to the size of the King        intindex = 2; //iterate through the array and deposit into the map collection         for(String number:numbers) { for(String color:colors) {pooker.put (index, Color+Number );                Pookernumber.add (index); Index++; }        }        //Separate storage size KingPooker.put (0, "King")); Pookernumber.add (0); Pooker.put (1, "Xiao Wang"); Pookernumber.add (1); //Shuffle, the number of cards upsetcollections.shuffle (Pookernumber); // Licensing//three players and cardsArraylist<integer> Player1 =NewArraylist<integer>(); ArrayList<Integer> Player2 =NewArraylist<integer>(); ArrayList<Integer> Player3 =NewArraylist<integer>(); ArrayList<Integer> Dipai =NewArraylist<integer>(); //three players per card, in turn         for(inti = 0; I < pookernumber.size (); i++) {            //do the cards first .            if(I < 3) {Dipai.add (Pookernumber.get (i)); }            //give each player a card, in turn            Else if(i% 3 = = 0) {Player1.add (Pookernumber.get (i)); } Else if(i% 3 = = 1) {Player2.add (Pookernumber.get (i)); } Else if(i% 3 = = 2) {Player3.add (Pookernumber.get (i)); }        }        //sort cards in the hands of playersCollections.sort (Player1);        Collections.sort (PLAYER2);        Collections.sort (PLAYER3); //look at the card, find the value according to the keyLook ("Player 1", Player1, Pooker); Look ("Player 2", Player2, Pooker); Look ("Player 3", Player3, Pooker); Look (Cards, Dipai, Pooker); }     Public Static voidLook (String name, arraylist<integer> player, Hashmap<integer, string>Pooker) {System.out.print (name+ ":");  for(Integer key:player) {String value=Pooker.get (key); System.out.print ("    " +value);    } System.out.println (); }}

Effect:

Each time the results are inconsistent:

Interested friends can continue to develop according to the rules of the landlord, make a simple game of landlords

Java Learning Note 34 (Set Frame VIII: Comprehensive case: Simulation of the Landlord's shuffle Licensing)

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.