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 Suits suits;private int face;private Image image;/** * constructor * * @param suits * @param face * @param image */public Mahjong (suits 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 (suits) {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 suits getsuits () {return suits;} 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 () {suits[] suits = {suits.circle, suits.bamboo, suits.character};int[] faces = {1,2,3,4,5,6,7,8,9};for (int i = 0; I < mah.length; I++) {mah[i] = new Mahjong (suits[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 0 Basic design Mahjong Create tiles and Shuffle cards ~ well, that's it.