System.exit(0);
}
});// 关闭窗体
}
public void keyPressed(KeyEvent evt) {
switch (evt.getKeyCode()) {
case KeyEvent.VK_ENTER :
if (ziShu % 2 == 0)// 子数来判断谁赢
{
heiXia();
} else {
baiXia();
}
shui = shuiYing();
break;
case KeyEvent.VK_ESCAPE :
System.exit(1);
break;
case KeyEvent.VK_LEFT :
guangBiaoDong(-1, 0);// 光标动的坐标
break;
case KeyEvent.VK_RIGHT :
guangBiaoDong(1, 0);// 光标动的坐标
break;
case KeyEvent.VK_DOWN :
guangBiaoDong(0, 1);// 光标动的坐标
break;
case KeyEvent.VK_UP :
guangBiaoDong(0, -1);// 光标动的坐标
break;
}
frame.repaint();
}
@SuppressWarnings("serial")
class Screen extends JComponent {
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
xianShi(g2d);// 画图
}
}
public static void main(String[] args) {
new Five();
}
void xianShi(Graphics2D g2d)// 显示
{
xianShiQiPan(g2d);// 显示棋盘
xianShiQiZis(g2d);// 显示旗子
xianShiGuangBiao(g2d);// 显示光标
g2d.setFont(new Font("STXingkai", 1, 30));// 0708第二小组
g2d.setColor(Color.black);
g2d.drawString("欢乐五子棋Java版", 280, 580);
g2d.setFont(new Font("stCaiyun", 1, 40));
if (shui == 0)// 判断
{
g2d.setColor(Color.black);
xianShiTiShiXia(g2d);// 显示谁下棋
} else {
g2d.setColor(Color.black);
xianShiTiShiYing(g2d); // 显示谁赢棋
}
}
void guangBiaoDong(int fangX, int fangY)// //光标动
{
if (gbx + fangX10 || gbx + fangX0 || gby + fangY10|| gby + fangY0) {
} else {
gbx = gbx + fangX;
gby = gby + fangY;
}
}
void heiXia()// 黑棋
{
if (pans[gby][gbx] == 0) {
pans[gby][gbx] = -1;
ziShu++;
}
}
void baiXia()// 白棋
{
if (pans[gby][gbx] == 0) {
pans[gby][gbx] = 1;
ziShu++;
}
}
int shuiYing()// 0: 1:bai -1:hei谁赢拉
{
return kanFangShuiYing(1, 0) + kanFangShuiYing(0, 1)
+ kanFangShuiYing(1, 1) + kanFangShuiYing(1, -1);
}
// ---------------------------------------------
void xianShiQiPan(Graphics2D g2d)// 显示棋盘
{
g2d.setColor(Color.pink);
g2d.fillRect(0, 0, 40 * 12, 40 * 12);// 0,0,40*12,40*12
g2d.setColor(Color.BLACK);
// 行格
for (int i = 0; i11; i++)// 40,行*40+40,440,行*40+40
{
g2d.drawLine(40, i * 40 + 40, 440, i * 40 + 40);
}
// 列格
for (int k = 0; k11; k++)// 列*40+40,40,列*40+40,440
{
g2d.drawLine(k * 40 + 40, 40, k * 40 + 40, 440);
}
}
void xianShiQiZis(Graphics2D g2d)// 显示旗子
{
for (int h = 0; h11; h++) {
for (l = 0; l11; l++) {
switch (pans[h][l]) {
case 1 :
g2d.setColor(Color.BLACK);
g2d.fillOval(40 - 15 + l * 40, 40 - 15 + h * 40, 30, 30);// (40-15+l*40,40-15+h*40,30,30);
break;
case -1 :
g2d.setColor(Color.white);
g2d.fillOval(40 - 15 + l * 40, 40 - 15 + h * 40, 30, 30);// (40-15+l*40,40-15+h*40,30,30);
break;
case 0 :
break;
}
}
}
}
void xianShiGuangBiao(Graphics2D g2d)// 显示光标
{
g2d.setColor(Color.blue);
g2d.fillOval(40 - 5 + gbx * 40, 40 - 5 + gby * 40, 10, 10);
}
@SuppressWarnings("deprecation")
void xianShiTiShiYing(Graphics2D g2d)// 显示谁赢
{
switch (shui) {
case 1 :
// 黑棋
g2d.setColor(Color.black);
g2d.drawString("黑棋win", 200, 520);
JOptionPane pane = new JOptionPane("黑棋胜利^_^");
JDialog dialog = pane.createDialog(frame, "提示...");
dialog.show();
推荐阅读
- 保皇直播技巧,保皇游戏直播
- 云从科技新增ChatGPT概念,云从科技是什么公司
- 毕业设计模仿现有的网站吗,毕业设计论文去网上模仿
- 即时战略类游戏发展史小说,即时战略类的游戏
- linux命令逻辑符号 linux命令符号解释
- 电商如何发液体快递,液体怎么发国际快递
- 会展小程序开发功能,会展软件应用
- 无人直播图片动漫,无人直播效果怎么样
- php抓取首页数据 php获取当前页面url