五子棋java代码详解 五子棋java代码详解视频-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

五子棋java代码详解 五子棋java代码详解视频

急!!! Java五子棋源代码注释

package org.liky.game.frame;

创新互联于2013年成立,先为殷都等服务建站,殷都等地企业,进行企业商务咨询服务。为殷都企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Toolkit;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

public class FiveChessFrame extends JFrame implements MouseListener, Runnable {

// 取得屏幕的宽度

int width = Toolkit.getDefaultToolkit().getScreenSize().width;

// 取得屏幕的高度

int height = Toolkit.getDefaultToolkit().getScreenSize().height;

// 背景图片

BufferedImage bgImage = null;

// 保存棋子的坐标

int x = 0;

int y = 0;

// 保存之前下过的全部棋子的坐标

// 其中数据内容 0: 表示这个点并没有棋子, 1: 表示这个点是黑子, 2:表示这个点是白子

int[][] allChess = new int[19][19];

// 标识当前应该黑棋还是白棋下下一步

boolean isBlack = true;

// 标识当前游戏是否可以继续

boolean canPlay = true;

// 保存显示的提示信息

String message = "黑方先行";

// 保存最多拥有多少时间(秒)

int maxTime = 0;

// 做倒计时的线程类

Thread t = new Thread(this);

// 保存黑方与白方的剩余时间

int blackTime = 0;

int whiteTime = 0;

// 保存双方剩余时间的显示信息

String blackMessage = "无限制";

String whiteMessage = "无限制";

public FiveChessFrame() {

// 设置标题

this.setTitle("五子棋");

// 设置窗体大小

this.setSize(500, 500);

// 设置窗体出现位置

this.setLocation((width - 500) / 2, (height - 500) / 2);

// 将窗体设置为大小不可改变

this.setResizable(false);

// 将窗体的关闭方式设置为默认关闭后程序结束

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// 为窗体加入监听器

this.addMouseListener(this);

// 将窗体显示出来

this.setVisible(true);

t.start();

t.suspend();

// 刷新屏幕,防止开始游戏时出现无法显示的情况.

this.repaint();

String imagePath = "" ;

try {

imagePath = System.getProperty("user.dir")+"/bin/image/background.jpg" ;

bgImage = ImageIO.read(new File(imagePath.replaceAll("\\\\", "/")));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public void paint(Graphics g) {

// 双缓冲技术防止屏幕闪烁

BufferedImage bi = new BufferedImage(500, 500,

BufferedImage.TYPE_INT_RGB);

Graphics g2 = bi.createGraphics();

g2.setColor(Color.BLACK);

// 绘制背景

g2.drawImage(bgImage, 1, 20, this);

// 输出标题信息

g2.setFont(new Font("黑体", Font.BOLD, 20));

g2.drawString("游戏信息:" + message, 130, 60);

// 输出时间信息

g2.setFont(new Font("宋体", 0, 14));

g2.drawString("黑方时间:" + blackMessage, 30, 470);

g2.drawString("白方时间:" + whiteMessage, 260, 470);

// 绘制棋盘

for (int i = 0; i 19; i++) {

g2.drawLine(10, 70 + 20 * i, 370, 70 + 20 * i);

g2.drawLine(10 + 20 * i, 70, 10 + 20 * i, 430);

}

// 标注点位

g2.fillOval(68, 128, 4, 4);

g2.fillOval(308, 128, 4, 4);

g2.fillOval(308, 368, 4, 4);

g2.fillOval(68, 368, 4, 4);

g2.fillOval(308, 248, 4, 4);

g2.fillOval(188, 128, 4, 4);

g2.fillOval(68, 248, 4, 4);

g2.fillOval(188, 368, 4, 4);

g2.fillOval(188, 248, 4, 4);

/*

* //绘制棋子 x = (x - 10) / 20 * 20 + 10 ; y = (y - 70) / 20 * 20 + 70 ;

* //黑子 g.fillOval(x - 7, y - 7, 14, 14); //白子 g.setColor(Color.WHITE) ;

* g.fillOval(x - 7, y - 7, 14, 14); g.setColor(Color.BLACK) ;

* g.drawOval(x - 7, y - 7, 14, 14);

*/

// 绘制全部棋子

for (int i = 0; i 19; i++) {

for (int j = 0; j 19; j++) {

if (allChess[i][j] == 1) {

// 黑子

int tempX = i * 20 + 10;

int tempY = j * 20 + 70;

g2.fillOval(tempX - 7, tempY - 7, 14, 14);

}

if (allChess[i][j] == 2) {

// 白子

int tempX = i * 20 + 10;

int tempY = j * 20 + 70;

g2.setColor(Color.WHITE);

g2.fillOval(tempX - 7, tempY - 7, 14, 14);

g2.setColor(Color.BLACK);

g2.drawOval(tempX - 7, tempY - 7, 14, 14);

}

}

}

g.drawImage(bi, 0, 0, this);

}

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

/*

* System.out.println("X:"+e.getX()); System.out.println("Y:"+e.getY());

*/

if (canPlay == true) {

x = e.getX();

y = e.getY();

if (x = 10 x = 370 y = 70 y = 430) {

x = (x - 10) / 20;

y = (y - 70) / 20;

if (allChess[x][y] == 0) {

// 判断当前要下的是什么颜色的棋子

if (isBlack == true) {

allChess[x][y] = 1;

isBlack = false;

message = "轮到白方";

} else {

allChess[x][y] = 2;

isBlack = true;

message = "轮到黑方";

}

// 判断这个棋子是否和其他的棋子连成5连,即判断游戏是否结束

boolean winFlag = this.checkWin();

if (winFlag == true) {

JOptionPane.showMessageDialog(this, "游戏结束,"

+ (allChess[x][y] == 1 ? "黑方" : "白方") + "获胜!");

canPlay = false;

}

} else {

JOptionPane.showMessageDialog(this, "当前位置已经有棋子,请重新落子!");

}

this.repaint();

}

}

/* System.out.println(e.getX() + " -- " + e.getY()); */

// 点击 开始游戏 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 70

e.getY() = 100) {

int result = JOptionPane.showConfirmDialog(this, "是否重新开始游戏?");

if (result == 0) {

// 现在重新开始游戏

// 重新开始所要做的操作: 1)把棋盘清空,allChess这个数组中全部数据归0.

// 2) 将 游戏信息: 的显示改回到开始位置

// 3) 将下一步下棋的改为黑方

for (int i = 0; i 19; i++) {

for (int j = 0; j 19; j++) {

allChess[i][j] = 0;

}

}

// 另一种方式 allChess = new int[19][19];

message = "黑方先行";

isBlack = true;

blackTime = maxTime;

whiteTime = maxTime;

if (maxTime 0) {

blackMessage = maxTime / 3600 + ":"

+ (maxTime / 60 - maxTime / 3600 * 60) + ":"

+ (maxTime - maxTime / 60 * 60);

whiteMessage = maxTime / 3600 + ":"

+ (maxTime / 60 - maxTime / 3600 * 60) + ":"

+ (maxTime - maxTime / 60 * 60);

t.resume();

} else {

blackMessage = "无限制";

whiteMessage = "无限制";

}

this.canPlay = true;

this.repaint();

}

}

// 点击 游戏设置 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 120

e.getY() = 150) {

String input = JOptionPane

.showInputDialog("请输入游戏的最大时间(单位:分钟),如果输入0,表示没有时间限制:");

try {

maxTime = Integer.parseInt(input) * 60;

if (maxTime 0) {

JOptionPane.showMessageDialog(this, "请输入正确信息,不允许输入负数!");

}

if (maxTime == 0) {

int result = JOptionPane.showConfirmDialog(this,

"设置完成,是否重新开始游戏?");

if (result == 0) {

for (int i = 0; i 19; i++) {

for (int j = 0; j 19; j++) {

allChess[i][j] = 0;

}

}

// 另一种方式 allChess = new int[19][19];

message = "黑方先行";

isBlack = true;

blackTime = maxTime;

whiteTime = maxTime;

blackMessage = "无限制";

whiteMessage = "无限制";

this.canPlay = true;

this.repaint();

}

}

if (maxTime 0) {

int result = JOptionPane.showConfirmDialog(this,

"设置完成,是否重新开始游戏?");

if (result == 0) {

for (int i = 0; i 19; i++) {

for (int j = 0; j 19; j++) {

allChess[i][j] = 0;

}

}

// 另一种方式 allChess = new int[19][19];

message = "黑方先行";

isBlack = true;

blackTime = maxTime;

whiteTime = maxTime;

blackMessage = maxTime / 3600 + ":"

+ (maxTime / 60 - maxTime / 3600 * 60) + ":"

+ (maxTime - maxTime / 60 * 60);

whiteMessage = maxTime / 3600 + ":"

+ (maxTime / 60 - maxTime / 3600 * 60) + ":"

+ (maxTime - maxTime / 60 * 60);

t.resume();

this.canPlay = true;

this.repaint();

}

}

} catch (NumberFormatException e1) {

// TODO Auto-generated catch block

JOptionPane.showMessageDialog(this, "请正确输入信息!");

}

}

// 点击 游戏说明 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 170

e.getY() = 200) {

JOptionPane.showMessageDialog(this,

"这个一个五子棋游戏程序,黑白双方轮流下棋,当某一方连到五子时,游戏结束。");

}

// 点击 认输 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 270

e.getY() = 300) {

int result = JOptionPane.showConfirmDialog(this, "是否确认认输?");

if (result == 0) {

if (isBlack) {

JOptionPane.showMessageDialog(this, "黑方已经认输,游戏结束!");

} else {

JOptionPane.showMessageDialog(this, "白方已经认输,游戏结束!");

}

canPlay = false;

}

}

// 点击 关于 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 320

e.getY() = 350) {

JOptionPane.showMessageDialog(this,

"本游戏由MLDN制作,有相关问题可以访问");

}

// 点击 退出 按钮

if (e.getX() = 400 e.getX() = 470 e.getY() = 370

e.getY() = 400) {

JOptionPane.showMessageDialog(this, "游戏结束");

System.exit(0);

}

}

public void mouseReleased(MouseEvent e) {

// TODO Auto-generated method stub

}

private boolean checkWin() {

boolean flag = false;

// 保存共有相同颜色多少棋子相连

int count = 1;

// 判断横向是否有5个棋子相连,特点 纵坐标 是相同, 即allChess[x][y]中y值是相同

int color = allChess[x][y];

/*

* if (color == allChess[x+1][y]) { count++; if (color ==

* allChess[x+2][y]) { count++; if (color == allChess[x+3][y]) {

* count++; } } }

*/

// 通过循环来做棋子相连的判断

/*

* int i = 1; while (color == allChess[x + i][y + 0]) { count++; i++; }

* i = 1; while (color == allChess[x - i][y - 0]) { count++; i++; } if

* (count = 5) { flag = true; } // 纵向的判断 int i2 = 1 ; int count2 = 1 ;

* while (color == allChess[x + 0][y + i2]) { count2++; i2++; } i2 = 1;

* while (color == allChess[x - 0][y - i2]) { count2++; i2++; } if

* (count2 = 5) { flag = true ; } // 斜方向的判断(右上 + 左下) int i3 = 1 ; int

* count3 = 1 ; while (color == allChess[x + i3][y - i3]) { count3++;

* i3++; } i3 = 1; while (color == allChess[x - i3][y + i3]) { count3++;

* i3++; } if (count3 = 5) { flag = true ; } // 斜方向的判断(右下 + 左上) int i4 =

* 1 ; int count4 = 1 ; while (color == allChess[x + i4][y + i4]) {

* count4++; i4++; } i4 = 1; while (color == allChess[x - i4][y - i4]) {

* count4++; i4++; } if (count4 = 5) { flag = true ; }

*/

// 判断横向

count = this.checkCount(1, 0, color);

if (count = 5) {

flag = true;

} else {

// 判断纵向

count = this.checkCount(0, 1, color);

if (count = 5) {

flag = true;

} else {

// 判断右上、左下

count = this.checkCount(1, -1, color);

if (count = 5) {

flag = true;

} else {

// 判断右下、左上

count = this.checkCount(1, 1, color);

if (count = 5) {

flag = true;

}

}

}

}

return flag;

}

// 判断棋子连接的数量

private int checkCount(int xChange, int yChange, int color) {

int count = 1;

int tempX = xChange;

int tempY = yChange;

while (x + xChange = 0 x + xChange = 18 y + yChange = 0

y + yChange = 18

color == allChess[x + xChange][y + yChange]) {

count++;

if (xChange != 0)

xChange++;

if (yChange != 0) {

if (yChange 0)

yChange++;

else {

yChange--;

}

}

}

xChange = tempX;

yChange = tempY;

while (x - xChange = 0 x - xChange = 18 y - yChange = 0

y - yChange = 18

color == allChess[x - xChange][y - yChange]) {

count++;

if (xChange != 0)

xChange++;

if (yChange != 0) {

if (yChange 0)

yChange++;

else {

yChange--;

}

}

}

return count;

}

public void run() {

// TODO Auto-generated method stub

// 判断是否有时间限制

if (maxTime 0) {

while (true) {

if (isBlack) {

blackTime--;

if (blackTime == 0) {

JOptionPane.showMessageDialog(this, "黑方超时,游戏结束!");

}

} else {

whiteTime--;

if (whiteTime == 0) {

JOptionPane.showMessageDialog(this, "白方超时,游戏结束!");

}

}

blackMessage = blackTime / 3600 + ":"

+ (blackTime / 60 - blackTime / 3600 * 60) + ":"

+ (blackTime - blackTime / 60 * 60);

whiteMessage = whiteTime / 3600 + ":"

+ (whiteTime / 60 - whiteTime / 3600 * 60) + ":"

+ (whiteTime - whiteTime / 60 * 60);

this.repaint();

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println(blackTime + " -- " + whiteTime);

}

}

}

}

求五子棋Java代码旁边就注释 让我看的清楚明白一些,要详细的解释和思路

import java.applet.*;

import t.*;

import t.event.*;

import java.applet.Applet;

import t.Color; //这一段import就不说了,下面要用到的就import进来

public class wuziqi extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener

//继承Applet表明是个applet,后面的接口必须要实现每个接口的所有方法

{

int color_Qizi=0;//旗子的颜色标识 0:白子 1:黑子

int intGame_Start=0;//游戏开始标志 0未开始 1游戏中

int intGame_Body[][]=new int[16][16]; //设置棋盘棋子状态 0 无子 1 白子 2 黑子

java五子棋 程序解释

要想充分了解你还是自己找doc帮助文档

//导入包

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

//构造applet程序

public class 五子棋 extends Applet implements ActionListener,MouseListener

{

String str="五子棋游戏!";

Dimension currentPos=new Dimension(); //实例化 像素

int zuobiao[][]=new int[19][15]; //声明一个19*15的棋盘

int x=20,y=20;

boolean unfirstpaint=false;

boolean one=false;

//======================================================================

public void init() //初始化(生存周期第一步)

{

addMouseListener(this); //对鼠标添加监听

for(int i=0;i=18;i++) //使整个棋盘设置为0

{

for(int j=0;j=14;j++)

zuobiao[i][j]=0;

}

}

//======================================================================

public void paint(Graphics g) //画图(生存周期第二步)

{

int x0=30,y0=50,dx=30,dy=30,N=18,M=14; //x0,y0初始坐标,dx,dy每格间距

int x1,y1,x2,y2;

g.setColor(Color.green); //

y1=y0;

y2=y0+M*dy;

for(int i=0;i=N;i++) //用绿色画棋盘中纵向的线

{

x1=x0+i*dx;

g.drawLine(x1,y1,x1,y2);

}

g.setColor(Color.red); //设置成红色

x1=x0;

x2=x0+N*dx;

for(int j=0;j=M;j++) //用红色画棋盘中横向的线

{

y1=y0+j*dy;

g.drawLine(x1,y1,x2,y1);

}

g.setColor(Color.red); //设置成红色

g.setFont(new Font("TimesRoman",Font.BOLD,25)); //设置字体

g.drawString(str,120,30); //在指定位置(120,30)写入“五子棋游戏!”

g.setColor(Color.red); //设置成红色

g.fillOval(600,60,20,20) //用红色填充椭圆;

g.drawString(" : 甲方",610,80); //在椭圆中写入字

g.setColor(Color.blue); //设置成蓝色

g.fillOval(600,100,20,20); //用蓝色填充椭圆;

g.drawString(" : 乙方",610,120); //在椭圆中写入字

//======================================================================

//这里代码不全,currentPos没有赋值,不好推测

if(unfirstpaint) //判断是否为第一次画棋子,如果不是第一次,执行

{

for(int i=0;i=18;i++)//画棋子

{

for(int j=0;j=14;j++)

{

if(currentPos.width=(45+i*30)currentPos.width=(15+i*30))

//你的源文件不是这样写的,我觉得应该是这么写

x=i;

if(currentPos.height=(65+j*30)currentPos.height=(35+j*30))

y=j;

}

}

}

//=====================================================================

if(x!=20y!=20)

if(zuobiao[x][y]==0)

{

if(one)

zuobiao[x][y]=1; //等于1说明是红色棋子

else

zuobiao[x][y]=2; //等于2说明是蓝色棋子

}

//画点图=====================================================================

for(int i=0;i=18;i++)

for(int j=0;j=14;j++)

{

if(zuobiao[i][j]==1) //如果为1,画红棋子

{

g.setColor(Color.red);

g.fillOval(20+i*30,40+j*30,20,20);

}

if(zuobiao[i][j]==2) //如果为2,画蓝棋子

{

g.setColor(Color.blue);

g.fillOval(20+i*30,40+j*30,20,20);

}

}

求java五子棋代码要注释~现在1小时等待

package org.crazyit.gobang;

import java.io.BufferedReader;

import java.io.InputStreamReader;

/**

* 五子棋游戏类

*

* @author yangenxiong yangenxiong2009@gmail点抗

* @author Kelvin Mak kelvin.mak125@gmail点抗

* @version 1.0

* br/网站: a href=""疯狂Java联盟/a

* brCopyright (C), 2009-2010, yangenxiong

* brThis program is protected by copyright laws.

*/

public class GobangGame {

// 定义达到赢条件的棋子数目

private final int WIN_COUNT = 5;

// 定义用户输入的X坐标

private int posX = 0;

// 定义用户输入的X坐标

private int posY = 0;

// 定义棋盘

private Chessboard chessboard;

/**

* 空构造器

*/

public GobangGame() {

}

/**

* 构造器,初始化棋盘和棋子属性

*

* @param chessboard

* 棋盘类

*/

public GobangGame(Chessboard chessboard) {

this.chessboard = chessboard;

}

/**

* 检查输入是否合法。

*

* @param inputStr

* 由控制台输入的字符串。

* @return 字符串合法返回true,反则返回false。

*/

public boolean isValid(String inputStr) {

// 将用户输入的字符串以逗号(,)作为分隔,分隔成两个字符串

String[] posStrArr = inputStr.split(",");

try {

posX = Integer.parseInt(posStrArr[0]) - 1;

posY = Integer.parseInt(posStrArr[1]) - 1;

} catch (NumberFormatException e) {

chessboard.printBoard();

System.out.println("请以(数字,数字)的格式输入:");

return false;

}

// 检查输入数值是否在范围之内

if (posX 0 || posX = Chessboard.BOARD_SIZE || posY 0

|| posY = Chessboard.BOARD_SIZE) {

chessboard.printBoard();

System.out.println("X与Y坐标只能大于等于1,与小于等于" + Chessboard.BOARD_SIZE

+ ",请重新输入:");

return false;

}

// 检查输入的位置是否已经有棋子

String[][] board = chessboard.getBoard();

if (board[posX][posY] != "十") {

chessboard.printBoard();

System.out.println("此位置已经有棋子,请重新输入:");

return false;

}

return true;

}

/**

* 开始下棋

*/

public void start() throws Exception {

// true为游戏结束

boolean isOver = false;

chessboard.initBoard();

chessboard.printBoard();

// 获取键盘的输入

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String inputStr = null;

// br.readLine:每当键盘输入一行内容按回车键,则输入的内容被br读取到

while ((inputStr = br.readLine()) != null) {

isOver = false;

if (!isValid(inputStr)) {

// 如果不合法,要求重新输入,再继续

continue;

}

// 把对应的数组元素赋为"●"

String chessman = Chessman.BLACK.getChessman();

chessboard.setBoard(posX, posY, chessman);

// 判断用户是否赢了

if (isWon(posX, posY, chessman)) {

isOver = true;

} else {

// 计算机随机选择位置坐标

int[] computerPosArr = computerDo();

chessman = Chessman.WHITE.getChessman();

chessboard.setBoard(computerPosArr[0], computerPosArr[1],

chessman);

// 判断计算机是否赢了

if (isWon(computerPosArr[0], computerPosArr[1], chessman)) {

isOver = true;

}

}

// 如果产生胜者,询问用户是否继续游戏

if (isOver) {

// 如果继续,重新初始化棋盘,继续游戏

if (isReplay(chessman)) {

chessboard.initBoard();

chessboard.printBoard();

continue;

}

// 如果不继续,退出程序

break;

}

chessboard.printBoard();

System.out.println("请输入您下棋的坐标,应以x,y的格式输入:");

}

}

/**

* 是否重新开始下棋。

*

* @param chessman

* "●"为用户,"○"为计算机。

* @return 开始返回true,反则返回false。

*/

public boolean isReplay(String chessman) throws Exception {

chessboard.printBoard();

String message = chessman.equals(Chessman.BLACK.getChessman()) ? "恭喜您,您赢了,"

: "很遗憾,您输了,";

System.out.println(message + "再下一局?(y/n)");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

if (br.readLine().equals("y")) {

// 开始新一局

return true;

}

return false;

}

/**

* 计算机随机下棋

*/

public int[] computerDo() {

int posX = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));

int posY = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));

String[][] board = chessboard.getBoard();

while (board[posX][posY] != "十") {

posX = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));

posY = (int) (Math.random() * (Chessboard.BOARD_SIZE - 1));

}

int[] result = { posX, posY };

return result;

}

/**

* 判断输赢

*

* @param posX

* 棋子的X坐标。

* @param posY

* 棋子的Y坐标

* @param ico

* 棋子类型

* @return 如果有五颗相邻棋子连成一条直接,返回真,否则相反。

*/

public boolean isWon(int posX, int posY, String ico) {

// 直线起点的X坐标

int startX = 0;

// 直线起点Y坐标

int startY = 0;

// 直线结束X坐标

int endX = Chessboard.BOARD_SIZE - 1;

// 直线结束Y坐标

int endY = endX;

// 同条直线上相邻棋子累积数

int sameCount = 0;

int temp = 0;

// 计算起点的最小X坐标与Y坐标

temp = posX - WIN_COUNT + 1;

startX = temp 0 ? 0 : temp;

temp = posY - WIN_COUNT + 1;

startY = temp 0 ? 0 : temp;

// 计算终点的最大X坐标与Y坐标

temp = posX + WIN_COUNT - 1;

endX = temp Chessboard.BOARD_SIZE - 1 ? Chessboard.BOARD_SIZE - 1

: temp;

temp = posY + WIN_COUNT - 1;

endY = temp Chessboard.BOARD_SIZE - 1 ? Chessboard.BOARD_SIZE - 1

: temp;

// 从左到右方向计算相同相邻棋子的数目

String[][] board = chessboard.getBoard();

for (int i = startY; i endY; i++) {

if (board[posX][i] == ico board[posX][i + 1] == ico) {

sameCount++;

} else if (sameCount != WIN_COUNT - 1) {

sameCount = 0;

}

}

if (sameCount == 0) {

// 从上到下计算相同相邻棋子的数目

for (int i = startX; i endX; i++) {

if (board[i][posY] == ico board[i + 1][posY] == ico) {

sameCount++;

} else if (sameCount != WIN_COUNT - 1) {

sameCount = 0;

}

}

}

if (sameCount == 0) {

// 从左上到右下计算相同相邻棋子的数目

int j = startY;

for (int i = startX; i endX; i++) {

if (j endY) {

if (board[i][j] == ico board[i + 1][j + 1] == ico) {

sameCount++;

} else if (sameCount != WIN_COUNT - 1) {

sameCount = 0;

}

j++;

}

}

}

return sameCount == WIN_COUNT - 1 ? true : false;

}

public static void main(String[] args) throws Exception {

GobangGame gb = new GobangGame(new Chessboard());

gb.start();

}

}


网页标题:五子棋java代码详解 五子棋java代码详解视频
本文网址:http://kswsj.cn/article/ddghoes.html

其他资讯