4.3.3ֽůµÄ³õʼ»¯ÒÔ¼°·¢ÅƲÙ×÷
´úÂëʵÏÖÈçÏ£º
public void initCards(){
//Èç¹ûֽůÒѱ»¸³Öµ£¬¼´½«Æä´Ó¿ò¼ÜµÄÃæ°åÖÐÒÆÈ¥ if (cards[0] != null){
for (int i = 0; i < 104; i++){ pane.remove(cards[i]); } }
int n = 0;
//ͨ¹ýÄѶȵȼ¶£¬Îªn¸³Öµ
if (this.grade == Spider.EASY){ n = 1; }
else if (this.grade == Spider.NATURAL){ n = 2; }
else{
n = 4; }
//Ϊcard¸³Öµ
for (int i = 1; i <= 8; i++){
for (int j = 1; j <= 13; j++){
cards[(i - 1) * 13 + j - 1] = new PKCard((i % n + 1) + \
this);¼ÙÉèn=1,´Ëʱi%nµÄֵΪ0£¬Ôò1%n+1µÄֵΪ1£¬ËùÒÔ´´½¨µÄͼƬӦ¸ÃÊÇ1-1µ½1-13È«ÊǺÚÌÒ£¬ÎªÍ¬Ò»»¨É«£¬nµÈÓÚÆäËüֵʱÀàËÆ¡£
} } ÈçͼËùʾ£º
¼òµ¥£¬µ¥Ò»»¨É«£º
Öм¶£¬Ë«
17
¸ß¼¶£¬ËÄ»¨É«£º
//Ëæ»úֽů³õʼ»¯
this.randomCards();\\\\½«Ö½ÅƵÄ˳Ðò´òÂÒ }
/**
**Ö½ÅÆËæ»ú·ÖÅä */
public void randomCards(){ PKCard temp = null; //Ëæ»úÉú³ÉÅÆºÅ
for (int i = 0; i < 52; i++){
int a = (int) (Math.random() * 104); int b = (int) (Math.random() * 104); temp = cards[a]; cards[a] = cards[b]; cards[b] = temp; } }
ÉèÖÃֽůµÄλÖÃ
public void setCardsLocation(){ ×ø±êλÓÚ½çÃæµÄÓÒϽÇÇøÓò //³õʼ»¯´ýÕ¹¿ªµÄֽů
½«cardתÏò±³Ãæ cards[n].turnRear();
½«card·ÅÔڹ̶¨µÄλÖÃÉÏ
cards[n].moveto(new Point(x, y));
table = new Hashtable(); c = 0;
finish = 0; n = 0; a = 0;
int x = 883;
int y = 580;\\\\ for (int i = 0; i < 6; i++){
for (int j = 0; j < 10; j++){ int n = i * 10 + j; pane.add(cards[n]); // //
18
//½«cardµÄλÖü°Ïà¹ØÐÅÏ¢´æÈë
table.put(new Point(x, y), cards[n]); }
x += 10;\\\\xµÄֵѻ·Ò»´ÎÔö10£¬±íʾÏÂÒ»µþֽůµÄλÖà }
x = 20;
y=4£º\\\\×ø±êλÓÚÉÏ·½µÄÍæÅÆÇøÓò×î×ó±ßÒ»¸ö±³¾°¿òµÄλÖᣠ³õʼ»¯±íÃæÏÔʾµÄֽů
for (int i = 10; i > 5; i--){
for (int j = 0; j < 10; j++){
int n = i * 10 + j;\\\\Éú³ÉË÷ÒýÖµ
if (n >= 104) continue;\\\\Öµ³¬¹ý104ÔòÍ˳ö±¾´ÎÑ»· pane.add(cards[n]);\\\\½«Ë÷ÒýÖµËùÖ¸µÄֽůÌí¼Óµ½Ãæ°åÈÝÆ÷ cards[n].turnRear();\\\\½«Ö½ÅÆ×ªµ½±³ÃæÈ¥
cards[n].moveto(new Point(x, y));\\\\½«Ö½ÅÆÒƶ¯µÄ¹Ì¶¨µÄλÖÃÉÏÈ¥
table.put(new Point(x, y), cards[n]);\\\\½«Ö½ÅƼ°Æä¶ÔÓ¦µÄλÖôæÈëµ½¹þÏ£±íÖÐ
x += 101;±³¾°¿ò¼ä¸ôµÄXֵΪ101 }
x = 20;X×ø±ê»Øµ½ÔÏȵÄλÖô¦
y -= 5;Y×ø±ê»áÏòÏÂÒÆ¶¯5¸öµ¥Î»£¬±íʾµÚ¶þÐÐֽůµÄ³õʼ»¯¿ªÊ¼
}
}
19
·½·¨£ºÓÎÏ·ÔËÐÐ
public void deal() {
this.setNA();
//ÅжÏ10ÁÐÖÐÊÇ·ñ¿ÕÁÐ
for (int i = 0; i < 10; i++){
if (this.getLastCardLocation(i) == null){
JOptionPane.showMessageDialog(this, \ÓпÕλ²»ÄÜ·¢ÅÆ£¡\Ìáʾ\
JOptionPane.WARNING_MESSAGE); return; } }
int x = 20;
for (int i = 0; i < 10; i++){
Point lastPoint = this.getLastCardLocation(i); //ÕâÕÅÅÆÓ¦¡°±³ÃæÏòÉÏ¡± if (c == 0){
lastPoint.y += 5;\\\\µ±»¹Ã»Óз¢¹ýÅÆÊ±£¬Ã¿ÁеÄֽůÖÐy×ø±êÏà²î5¸öµ¥Î»¡£
}
//ÕâÕÅÅÆÓ¦¡°ÕýÃæÏòÉÏ¡± else{
lastPoint.y += 20;·ñÔòÊÇÁ½ÕÅÕýÃæÏÔÊ¾Ö½ÅÆ²îÖµ }
table.remove(cards[c + i].getLocation()); cards[c + i].moveto(lastPoint);
table.put(new Point(lastPoint), cards[c + i]); cards[c + i].turnFront();
cards[c + i].setCanMove(true);
//½«×é¼þcardÒÆ¶¯µ½ÈÝÆ÷ÖÐÖ¸¶¨µÄ˳ÐòË÷Òý¡£
20