Article View: cn.bbs.comp.lang.java
Article #24348TicTacToeԴ����
From: wooce
Date: Tue, 24 Mar 1998 00:00
Date: Tue, 24 Mar 1998 00:00
99 lines
3135 bytes
3135 bytes
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.applet.*;
/**
* A TicTacToe applet. A very simple, and mostly brain-dead
*/
public
class TicTacToe extends Applet {
/**
* White's current position. The computer is white.
*/
int white;
/**
* Black's current position. The user is black.
*/
int black;
/**
* The squares in order of importance...
*/
final static int moves[] = {4, 0, 2, 6, 8, 1, 3, 5, 7};
/**
* The winningrossImage, c*xoff + 1, r*yoff + 1, this);
}
}
}
}
/**
* The user has clicked in the applet. Figure out where
* and see if a legal move is possible. If it is a legal
* move, respond with a legal move (if possible).
*/
public boolean mouseUp(Event evt, int x, int y) {
switch (status()) {
case WIN:
case LOSE:
case STALEMATE:
play(getCodeBase(), "audio/return.au");
white = black = 0;
if (first) {
white |= 1 << (int)(Math.random() * 9);
}
first = !first;
repaint();
return true;
}
// Figure out the row/colum
Dimension d = size();
int c = (x * 3) / d.width;
int r = (y * 3) / d.height;
if (yourMove(c + r * 3)) {
repaint();
switch (status()) {
case WIN:
play(getCodeBase(), "audio/joy.au");
break;
case LOSE:
play(getCodeBase(), "audio/joy.au");
break;
case STALEMATE:
break;
default:
if (myMove()) {
repaint();
switch (status()) {
case WIN:
play(getCodeBase(), "audio/joy.au");
break;
case LOSE:
play(getCodeBase(), "audio/joy.au");
break;
case STALEMATE:
break;
default:
play(getCodeBase(), "audio/ding.au");
}
} else {
play(getCodeBase(), "audio/beep.au");
}
}
} else {
play(getCodeBase(), "audio/beep.au");
}
return true;
}
public String getAppletInfo() {
return "TicTacToe by Arthur van Hoff";
}
}
--
[m[1;33m�� ��Դ:���������� BBS bbs.nease.net��[FROM: 202.96.174.34][m
Technical Details
Message-ID:
<3Nc8MY$7WW@bbs.nease.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f6cb0,5acd74b6c35a0603,start X-Google-Attributes: gidf6cb0,public From: wooce.bbs@bbs.nease.net (wooce) Subject: TicTacToeԴ���� Date: 1998/03/24 Message-ID: <3Nc8MY$7WW@bbs.nease.net> X-Deja-AN: 337112686 X-Filename: Java/M.890727490.A Organization: Net Ease Newsgroups: cn.bbs.comp.lang.java,