Development of landlord game based on Java----

Source: Internet
Author: User
Tags shuffle

This is an unordered hand with the ArrayList collection (no sorting function)

public class Pokerdemo {

public static void Main (string[] args) {
Create a card box
arraylist<string> array = new arraylist<string> ();

Define a suit array
string[] colors = {"?", "?", "?", "?"};
Define an array of points
string[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"};
Pack cards
for (String color:colors) {
for (String number:numbers) {
Array.add (Color.concat (number));
}
}
Array.add ("Xiao Wang");
Array.add ("King");

Shuffle
Collections.shuffle (array);

Licensing
arraylist<string> S1 = new arraylist<string> ();
arraylist<string> s2 = new arraylist<string> ();
arraylist<string> s3 = new arraylist<string> ();
arraylist<string> Dipai = new arraylist<string> ();

for (int i = 0; i < array.size (); i++) {
if (I >= array.size ()-3) {
Dipai.add (Array.get (i));
}else if (i% 3 ==0) {
S1.add (Array.get (i));
}else if (i% 3 ==1) {
S2.add (Array.get (i));
}else if (i% 3 ==2) {
S3.add (Array.get (i));
}
}
Look at the cards
Lookpoker ("Zhang San", S1);
Lookpoker ("John Doe", S2);
Lookpoker ("Harry", S3);
Lookpoker ("Hole cards", Dipai);

}

public static void Lookpoker (String name,arraylist<string> array) {
System.out.print (name + "The Hole Card is:");
for (String S:array) {
System.out.print (s+ "");
}
System.out.println ();
}

}

This is an ordered hand with the TreeSet collection (with sorting function)

Import java.util.*;

public class Pokerdemo {

public static void Main (string[] args) {
Create a HashMap collection
Hashmap<integer, string> HM = new Hashmap<integer, string> ();

Create a ArrayList collection
arraylist<integer> array = new arraylist<integer> ();

Define a suit array
string[] colors = {"?", "?", "?", "?"};
Define an array of points
string[] numbers = {"3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K", "A", "2"};
From 0 onwards to the HashMap in the storage number, and the corresponding card, while the ArrayList inside the memory number can be
int index = 0;
Pack cards
for (String number:numbers) {
for (String color:colors) {
String Poker = color.concat (number);
Hm.put (index, poker);
Array.add (index);
index++;

}
}
Hm.put (Index, "Xiao Wang");
Array.add (index);
index++;
Hm.put (Index, "King");
Array.add (index);

Shuffle (Wash is numbered)
Collections.shuffle (array);

Licensing
treeset<integer> S1 = new treeset<integer> ();
treeset<integer> s2 = new treeset<integer> ();
treeset<integer> s3 = new treeset<integer> ();
treeset<integer> Dipai = new treeset<integer> ();

for (int i = 0; i < array.size (); i++) {
if (I >= array.size ()-3) {
Dipai.add (Array.get (i));
} else if (i% 3 = = 0) {
S1.add (Array.get (i));
} else if (i% 3 = = 1) {
S2.add (Array.get (i));
} else if (i% 3 = = 2) {
S3.add (Array.get (i));
}
}

Look at the cards (traverse the TreeSet collection, get the number, and find the corresponding card in the HashMap collection)
Lookpoker ("Zhang San", S1, HM);
Lookpoker ("John Doe", S2, HM);
Lookpoker ("Harry", S3, HM);
Lookpoker ("Hole cards", Dipai, HM);

}

public static void Lookpoker (String name, treeset<integer> ts, Hashmap<integer, string> HM) {
System.out.print (name + "The card is:");
for (Integer key:ts) {
String value = Hm.get (key);
System.out.print (Value + "");
}
System.out.println ();
}

}

Development of landlord game based on Java----

Related Article

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.