Java Programming (one)-----face object Beginner Design Mahjong Create tiles and Shuffle cards ~ Well, that's it.

Source: Internet
Author: User
Tags shuffle

Zzzzzzzz

1. It's too lazy to start thinking about stickers ... This is a piece of mahjong

Package Com.lovo;import Java.awt.graphics;import java.awt.image;/** * class: Mahjong * @author Abe properties: Color points picture */public class Mah  Jong {private Suite suite;private int face;private Image image;/** * constructor *  * @param suits * @param face * @param image */public Mahjong (Suite suits, int face/*, Image image*/) {this.suite = Suits;this.face = Face;//this.image = Image;} /** * Draw a card */public void Draw (Graphics g,int x, int y) {g.drawimage (image, X, y, +, +, NULL);} /** * Output a card of points and suits */public string toString () {String str = ""; switch (suite) {case Circle:str + + face + "barrel"; Break;case bamb Oo:str + + face + "bar"; break;case Character:str + + face + "million"; break;} return str;} /** * Get color and points * @return */public Suite getsuits () {return suite;} public int Getface () {return face;}}
2. A pair of mahjong

Package Com.lovo;import Java.awt.image;import javax.swing.imageicon;/** * Class: A pair of mahjong tiles (108 photos) * * @author Abe properties: Face picture a deck of cards */public class Mahjongs {//private static image[] images = new image[36];p rivate mahjong[] mah = new mahjong[108];p rivate int sheet = 0;//static {//static loader//for (int i = 0; i < images.length; i++) {//imageicon icon = new ImageIcon ("mahjong/" + (i + 1) + ". jpg");//for (int j = 0; J < 4; J + +) {//images[i * 4 + j] = Icon.getimage ();//}//}//}/** * Constructor Initialization */publi  C mahjongs () {suite[] suites = {suite.circle, Suite.bamboo, suite.character};int[] faces = {1,2,3,4,5,6,7,8,9};for (int i = 0; i < mah.length; i++) {Mah[i] = new Mahjong (SUITES[I/36], faces[i% 9]/*, images[i]*/);}} /** * behavior: Shuffle */public void Stuffle () {for (int n = 0; n <; n++) {int i = (int) (Math.random () * 108); int j = (int) (Math.random () * 108); Mahjong temp;temp = mah[i];mah[i] = mah[j];mah[j] = temp;}} /** * Behavior: Licensing */public Mahjong deal () {return sheet < mah.length? mah[sheet++]: Null This is still a little vague to sheet after the output of the + +? }public mahjong[] GetAll () {return mah;}}

3. Printing

Package com.lovo;/** * Mahjong * @author Abe * */public class Testmah {public static void main (string[] args) {mahjongs Mahj = New Mahjongs (); Mahjong one = Null;mahj.stuffle (); for (int i = 0; i < 108; i++) {one = Mahj.deal (); System.out.print (one + "T"), if (i% 9 = = 8) {System.out.println ("");}}}
Duly completed ~

Java Programming (one)-----face object Beginner Design Mahjong Create tiles and Shuffle cards ~ Well, that's it.

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.