资源简介

java实现单机版和网络对战版五子棋,功能包括计时、悔棋、聊天、显示双方状态等等。详细见https://blog.csdn.net/qq_37913997/article/details/81148253

资源截图

代码片段和文件信息

package com.fivechess.judge;

/**
 * 下过棋之后判断是否五子成线
 * 以棋盘左上角为坐标原点
 * 横向x坐标变化,纵向y坐标变化,斜向x,y变化
 * 在每次横向或纵向或斜向变化后均判断一次是否连成5子
 * @author admin
 * 
 **/

import javax.swing.*;

import java.awt.*;
import com.fivechess.model.Chess;

public class Judge {
/**
 * 判断是否五子成线
 * @param xIndex 该点横坐标
 * @param yIndex 该点纵坐标
 * @param chess 数组
 * @param role 黑棋或白棋
 * @return 黑棋或白棋或空
 */
public static int whowin(int xIndex int yIndexint chess[][]int role){
int continueCount = 1;//连续棋子个数
//横向向左
for(int x=xIndex-1;x>=0;x--){
if(chess[x][yIndex] == role){  
                continueCount++;
}
else{
break;
}
}
//横向向右
for(int x=xIndex+1;x<19;x++){
if(chess[x][yIndex] == role){  
                continueCount++;
}
else{
break;
}
}
//判断是否大于5
if(continueCount>=5){
return role;
}
else{
continueCount = 1;
}
//纵向向上
for(int y=yIndex-1;y>=0;y--){
if(chess[xIndex][y] == role){  
                continueCount++;
}
else{
break;
}
}
//纵向向下
for(int y=yIndex+1;y<19;y++){
if(chess[xIndex][y] == role){  
                continueCount++;
}
else{
break;
}
}
//判断是否大于5
if(continueCount>=5){
return role;
}
else{
continueCount = 1;
}
//左上
for(int x=xIndex-1y=yIndex-1;x>=0 && y>=0;x--y--){
if(chess[x][y] == role){  
                continueCount++;
}
else{
break;
}
}
//右下
for(int x=xIndex+1y=yIndex+1;x<19 && y<19;x++y++){
if(chess[x][y] == role){  
                continueCount++;
}
else{
break;
}
}
//判断是否大于5
if(continueCount>=5){
return role;
}
else{
continueCount = 1;
}
//右上
for(int x=xIndex+1y=yIndex-1;x<19 && y>=0;x++y--){
if(chess[x][y] == role){  
                continueCount++;
}
else{
break;
}
}
//左下
for(int x=xIndex-1y=yIndex+1;x>=0 && y<19;x--y++){
if(chess[x][y] == role){  
                continueCount++;
}
else{
break;
}
}
//判断是否大于5
if(continueCount>=5){
return role;
}
else{
continueCount = 1;
}
return 0;
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-21 13:21  FiveChess-master\
     文件         353  2018-07-21 13:21  FiveChess-master\.classpath
     文件         368  2018-07-21 13:21  FiveChess-master\.project
     目录           0  2018-07-21 13:21  FiveChess-master\.settings\
     文件         587  2018-07-21 13:21  FiveChess-master\.settings\org.eclipse.jdt.core.prefs
     文件         125  2018-07-21 13:21  FiveChess-master\README.md
     目录           0  2018-07-21 13:21  FiveChess-master\bin\
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\judge\
     文件        1222  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\judge\Judge.class
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\model\
     文件         387  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\model\Chess.class
     文件        7577  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\model\Computer.class
     文件         643  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\model\Coord.class
     文件        1178  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\model\TimeThread.class
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\net\
     文件        1093  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\net\NetTool.class
     目录           0  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\
     文件        3279  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\ChessBoard.class
     文件        3443  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\ChooseLevel.class
     文件        2321  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\MainBoard.class
     文件        4663  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\PCChessBoard.class
     文件        5109  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\PCMainBoard.class
     文件        5178  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\PPChessBoard.class
     文件        4680  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\PPMainBoard$1.class
     文件        8498  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\PPMainBoard.class
     文件        2837  2018-07-21 13:21  FiveChess-master\bin\com\fivechess\view\SelectMenu.class
     文件         530  2018-07-21 13:21  FiveChess-master\bin\log4j.properties
     文件           3  2018-07-21 13:21  FiveChess-master\fivechess.log
     目录           0  2018-07-21 13:21  FiveChess-master\images\
............此处省略30个文件信息

评论

共有 条评论