Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
|
14f7f1bc90 | 1 year ago |
|
8e6ba80c4d | 1 year ago |
|
89e712cc32 | 1 year ago |
|
9874101dcf | 1 year ago |
|
8f3a572db6 | 1 year ago |
|
5edb875a93 | 1 year ago |
|
f145f14d03 | 1 year ago |
|
8f6f45219e | 1 year ago |
|
fba92a8176 | 1 year ago |
|
71201830d2 | 1 year ago |
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Game.iml" filepath="$PROJECT_DIR$/.idea/Game.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,179 @@
|
||||
Index: .idea/vcs.xml
|
||||
IDEA additional info:
|
||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
||||
<+>UTF-8
|
||||
===================================================================
|
||||
--- .idea/vcs.xml (date 1712723456804)
|
||||
+++ .idea/vcs.xml (date 1712723456804)
|
||||
@@ -0,0 +1,6 @@
|
||||
+<?xml version="1.0" encoding="UTF-8"?>
|
||||
+<project version="4">
|
||||
+ <component name="VcsDirectoryMappings">
|
||||
+ <mapping directory="" vcs="Git" />
|
||||
+ </component>
|
||||
+</project>
|
||||
\ No newline at end of file
|
||||
Index: .idea/misc.xml
|
||||
IDEA additional info:
|
||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
||||
<+>UTF-8
|
||||
===================================================================
|
||||
--- .idea/misc.xml (date 1712723456796)
|
||||
+++ .idea/misc.xml (date 1712723456796)
|
||||
@@ -0,0 +1,9 @@
|
||||
+<?xml version="1.0" encoding="UTF-8"?>
|
||||
+<project version="4">
|
||||
+ <component name="JavaScriptSettings">
|
||||
+ <option name="languageLevel" value="ES6" />
|
||||
+ </component>
|
||||
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
+ <output url="file://$PROJECT_DIR$/out" />
|
||||
+ </component>
|
||||
+</project>
|
||||
\ No newline at end of file
|
||||
Index: .idea/modules.xml
|
||||
IDEA additional info:
|
||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
||||
<+>UTF-8
|
||||
===================================================================
|
||||
--- .idea/modules.xml (date 1712723456812)
|
||||
+++ .idea/modules.xml (date 1712723456812)
|
||||
@@ -0,0 +1,8 @@
|
||||
+<?xml version="1.0" encoding="UTF-8"?>
|
||||
+<project version="4">
|
||||
+ <component name="ProjectModuleManager">
|
||||
+ <modules>
|
||||
+ <module fileurl="file://$PROJECT_DIR$/.idea/Game.iml" filepath="$PROJECT_DIR$/.idea/Game.iml" />
|
||||
+ </modules>
|
||||
+ </component>
|
||||
+</project>
|
||||
\ No newline at end of file
|
||||
Index: .idea/Game.iml
|
||||
IDEA additional info:
|
||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
||||
<+>UTF-8
|
||||
===================================================================
|
||||
--- .idea/Game.iml (date 1712723456786)
|
||||
+++ .idea/Game.iml (date 1712723456786)
|
||||
@@ -0,0 +1,9 @@
|
||||
+<?xml version="1.0" encoding="UTF-8"?>
|
||||
+<module type="JAVA_MODULE" version="4">
|
||||
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
+ <exclude-output />
|
||||
+ <content url="file://$MODULE_DIR$" />
|
||||
+ <orderEntry type="inheritedJdk" />
|
||||
+ <orderEntry type="sourceFolder" forTests="false" />
|
||||
+ </component>
|
||||
+</module>
|
||||
\ No newline at end of file
|
||||
Index: .idea/workspace.xml
|
||||
IDEA additional info:
|
||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
||||
<+>UTF-8
|
||||
===================================================================
|
||||
--- .idea/workspace.xml (date 1712724838733)
|
||||
+++ .idea/workspace.xml (date 1712724838733)
|
||||
@@ -0,0 +1,102 @@
|
||||
+<?xml version="1.0" encoding="UTF-8"?>
|
||||
+<project version="4">
|
||||
+ <component name="ChangeListManager">
|
||||
+ <list default="true" id="4cf62424-7e6c-4a44-b3f2-8a3dc44f2df7" name="Default Changelist" comment="新建文本文档">
|
||||
+ <change afterPath="$PROJECT_DIR$/.idea/Game.iml" afterDir="false" />
|
||||
+ <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
+ <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
+ <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
+ <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
+ </list>
|
||||
+ <option name="SHOW_DIALOG" value="false" />
|
||||
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
+ <option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
+ </component>
|
||||
+ <component name="Git.Settings">
|
||||
+ <option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
+ <map>
|
||||
+ <entry key="$PROJECT_DIR$" value="main" />
|
||||
+ </map>
|
||||
+ </option>
|
||||
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
+ </component>
|
||||
+ <component name="ProjectId" id="2etUbpOK5dhq80Q1B4zdGvUsGef" />
|
||||
+ <component name="ProjectViewState">
|
||||
+ <option name="hideEmptyMiddlePackages" value="true" />
|
||||
+ <option name="showLibraryContents" value="true" />
|
||||
+ </component>
|
||||
+ <component name="PropertiesComponent">
|
||||
+ <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
+ <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
+ <property name="WebServerToolWindowFactoryState" value="false" />
|
||||
+ <property name="aspect.path.notification.shown" value="true" />
|
||||
+ <property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
+ <property name="settings.editor.selected.configurable" value="preferences.editor.code.editing" />
|
||||
+ </component>
|
||||
+ <component name="SvnConfiguration">
|
||||
+ <configuration />
|
||||
+ </component>
|
||||
+ <component name="TaskManager">
|
||||
+ <task active="true" id="Default" summary="Default task">
|
||||
+ <changelist id="4cf62424-7e6c-4a44-b3f2-8a3dc44f2df7" name="Default Changelist" comment="" />
|
||||
+ <created>1712723441894</created>
|
||||
+ <option name="number" value="Default" />
|
||||
+ <option name="presentableId" value="Default" />
|
||||
+ <updated>1712723441894</updated>
|
||||
+ <workItem from="1712723443784" duration="1391000" />
|
||||
+ </task>
|
||||
+ <task id="LOCAL-00001" summary="新建文本文档">
|
||||
+ <created>1712723482913</created>
|
||||
+ <option name="number" value="00001" />
|
||||
+ <option name="presentableId" value="LOCAL-00001" />
|
||||
+ <option name="project" value="LOCAL" />
|
||||
+ <updated>1712723482913</updated>
|
||||
+ </task>
|
||||
+ <task id="LOCAL-00002" summary="新建文本文档">
|
||||
+ <created>1712723954614</created>
|
||||
+ <option name="number" value="00002" />
|
||||
+ <option name="presentableId" value="LOCAL-00002" />
|
||||
+ <option name="project" value="LOCAL" />
|
||||
+ <updated>1712723954614</updated>
|
||||
+ </task>
|
||||
+ <task id="LOCAL-00003" summary="新建文本文档">
|
||||
+ <created>1712724236228</created>
|
||||
+ <option name="number" value="00003" />
|
||||
+ <option name="presentableId" value="LOCAL-00003" />
|
||||
+ <option name="project" value="LOCAL" />
|
||||
+ <updated>1712724236228</updated>
|
||||
+ </task>
|
||||
+ <option name="localTasksCounter" value="4" />
|
||||
+ <servers />
|
||||
+ </component>
|
||||
+ <component name="TypeScriptGeneratedFilesManager">
|
||||
+ <option name="version" value="2" />
|
||||
+ </component>
|
||||
+ <component name="VcsManagerConfiguration">
|
||||
+ <MESSAGE value="新建文本文档" />
|
||||
+ <option name="LAST_COMMIT_MESSAGE" value="新建文本文档" />
|
||||
+ </component>
|
||||
+ <component name="WindowStateProjectService">
|
||||
+ <state x="528" y="233" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1712724141313">
|
||||
+ <screen x="0" y="0" width="1536" height="864" />
|
||||
+ </state>
|
||||
+ <state x="528" y="233" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.864@0.0.1536.864" timestamp="1712724141313" />
|
||||
+ <state x="367" y="0" key="CommitChangelistDialog2" timestamp="1712724574560">
|
||||
+ <screen x="0" y="0" width="1536" height="864" />
|
||||
+ </state>
|
||||
+ <state x="367" y="0" key="CommitChangelistDialog2/0.0.1536.864@0.0.1536.864" timestamp="1712724574560" />
|
||||
+ <state x="578" y="152" key="RollbackChangesDialog" timestamp="1712724523416">
|
||||
+ <screen x="0" y="0" width="1536" height="864" />
|
||||
+ </state>
|
||||
+ <state x="578" y="152" key="RollbackChangesDialog/0.0.1536.864@0.0.1536.864" timestamp="1712724523416" />
|
||||
+ <state x="361" y="165" key="Vcs.Push.Dialog.v2" timestamp="1712724259761">
|
||||
+ <screen x="0" y="0" width="1536" height="864" />
|
||||
+ </state>
|
||||
+ <state x="361" y="165" key="Vcs.Push.Dialog.v2/0.0.1536.864@0.0.1536.864" timestamp="1712724259761" />
|
||||
+ <state x="457" y="219" key="git4idea.merge.GitPullDialog" timestamp="1712724380999">
|
||||
+ <screen x="0" y="0" width="1536" height="864" />
|
||||
+ </state>
|
||||
+ <state x="457" y="219" key="git4idea.merge.GitPullDialog/0.0.1536.864@0.0.1536.864" timestamp="1712724380999" />
|
||||
+ </component>
|
||||
+</project>
|
||||
\ No newline at end of file
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="4cf62424-7e6c-4a44-b3f2-8a3dc44f2df7" name="Default Changelist" comment="新建文本文档">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/Game.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2etUbpOK5dhq80Q1B4zdGvUsGef" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="aspect.path.notification.shown" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.editor.code.editing" />
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="4cf62424-7e6c-4a44-b3f2-8a3dc44f2df7" name="Default Changelist" comment="" />
|
||||
<created>1712723441894</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1712723441894</updated>
|
||||
<workItem from="1712723443784" duration="1391000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="新建文本文档">
|
||||
<created>1712723482913</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1712723482913</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="新建文本文档">
|
||||
<created>1712723954614</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1712723954614</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="新建文本文档">
|
||||
<created>1712724236228</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1712724236228</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="2" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="新建文本文档" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="新建文本文档" />
|
||||
</component>
|
||||
<component name="WindowStateProjectService">
|
||||
<state x="528" y="233" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1712724141313">
|
||||
<screen x="0" y="0" width="1536" height="864" />
|
||||
</state>
|
||||
<state x="528" y="233" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.864@0.0.1536.864" timestamp="1712724141313" />
|
||||
<state x="367" y="0" key="CommitChangelistDialog2" timestamp="1712724574560">
|
||||
<screen x="0" y="0" width="1536" height="864" />
|
||||
</state>
|
||||
<state x="367" y="0" key="CommitChangelistDialog2/0.0.1536.864@0.0.1536.864" timestamp="1712724574560" />
|
||||
<state x="578" y="152" key="RollbackChangesDialog" timestamp="1712724523416">
|
||||
<screen x="0" y="0" width="1536" height="864" />
|
||||
</state>
|
||||
<state x="578" y="152" key="RollbackChangesDialog/0.0.1536.864@0.0.1536.864" timestamp="1712724523416" />
|
||||
<state x="361" y="165" key="Vcs.Push.Dialog.v2" timestamp="1712724259761">
|
||||
<screen x="0" y="0" width="1536" height="864" />
|
||||
</state>
|
||||
<state x="361" y="165" key="Vcs.Push.Dialog.v2/0.0.1536.864@0.0.1536.864" timestamp="1712724259761" />
|
||||
<state x="457" y="219" key="git4idea.merge.GitPullDialog" timestamp="1712724380999">
|
||||
<screen x="0" y="0" width="1536" height="864" />
|
||||
</state>
|
||||
<state x="457" y="219" key="git4idea.merge.GitPullDialog/0.0.1536.864@0.0.1536.864" timestamp="1712724380999" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,25 +0,0 @@
|
||||
package 五子棋;
|
||||
|
||||
import java.awt.Color;
|
||||
public class Chess {
|
||||
|
||||
private int x;//棋子的x坐标索引
|
||||
private int y;//棋子的y坐标索引
|
||||
private Color color;//棋子颜色
|
||||
public static int DIAMETER=30;//直径
|
||||
public Chess(int x,int y,Color color){//棋子构造函数
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.color=color;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
package 五子棋;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class ChessBord extends JPanel implements MouseListener{//继承面板类和鼠标事件接口
|
||||
public static int MARGIN=30;//定义边距
|
||||
public static int ROWS=15;//定义行数
|
||||
public static int COLS=15;//定义列数
|
||||
public static int GRID_SPAN=35;//网格间距
|
||||
Chess[] chessList=new Chess[(ROWS+1)*(COLS+1)];//定义一个棋子数组
|
||||
String[][] board=new String[MARGIN*2+GRID_SPAN*COLS][MARGIN*2+GRID_SPAN*COLS];//声明一个字符串数组,用来判断输赢
|
||||
int chessCount;//棋子数目
|
||||
int xindex,yindex;//棋子的坐标索引
|
||||
boolean start=true;//开始默认黑子先下
|
||||
boolean GameOver=false;//定义是否游戏结束
|
||||
public ChessBord() {//棋盘类构造函数
|
||||
setBackground(Color.LIGHT_GRAY);//设置背景颜色
|
||||
addMouseListener(this);//将棋盘类添加到鼠标事件监听器
|
||||
addMouseMotionListener(new MouseMotionListener() {//匿名内部类
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {//根据鼠标的移动所在的坐标来设置鼠标光标形状
|
||||
int x1=(e.getX()-MARGIN+GRID_SPAN/2)/GRID_SPAN;//对鼠标光标的x坐标进行转换
|
||||
int y1=(e.getY()-MARGIN+GRID_SPAN/2)/GRID_SPAN;//对鼠标光标的y坐标进行转换
|
||||
if(x1<0||x1>ROWS||y1<0||y1>COLS||GameOver||findchess(x1, y1)) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//设置鼠标光标为默认形状
|
||||
}else {
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));//设置鼠标光标为手型
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
}
|
||||
});
|
||||
for(int i=0;i<MARGIN*2+GRID_SPAN*COLS;i++) {//对board[][]赋初值
|
||||
for (int j = 0; j < MARGIN*2+GRID_SPAN*COLS; j++) {
|
||||
board[i][j]="0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {//鼠标点击事件
|
||||
if(GameOver)//游戏结束,不能按
|
||||
return ;
|
||||
String colorName=start?"黑棋":"白棋";//判断是什么颜色的棋子
|
||||
xindex=(e.getX()-MARGIN+GRID_SPAN/2)/GRID_SPAN;//得到棋子x坐标
|
||||
yindex=(e.getY()-MARGIN+GRID_SPAN/2)/GRID_SPAN;//得到棋子y坐标
|
||||
board[xindex][yindex]=colorName;//以棋子x坐标y坐标做索引将棋子的颜色添加到board中
|
||||
if(xindex<0||xindex>ROWS||yindex<0||yindex>COLS) {//棋子在棋盘外不能下,
|
||||
return ;
|
||||
}else if(findchess( xindex, yindex)) {//所下位置已有棋子,不能下
|
||||
return ;
|
||||
}
|
||||
Chess po=new Chess(xindex,yindex,start?Color.black:Color.WHITE);//对棋子对象进行初始化
|
||||
chessList[chessCount++]=po;//将棋子对象添加到棋子数组中
|
||||
repaint();//重画图型
|
||||
if(win( xindex,yindex,start)) {//判断是否胜利
|
||||
String msg=String.format("恭喜 %s赢了",colorName);
|
||||
JOptionPane.showMessageDialog(this, msg);
|
||||
//gameOver=true;
|
||||
GameOver=true;
|
||||
}else if(chessCount==(COLS+1)*(ROWS+1)) {//判断是否全部下满
|
||||
String msg=String.format("恭喜 %s赢了",colorName);
|
||||
JOptionPane.showMessageDialog(this, msg);
|
||||
GameOver=true;
|
||||
}
|
||||
start=!start;//改变棋子先下棋状态
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {//画棋盘和棋子
|
||||
super.paintComponent(g);
|
||||
for(int i=0;i<=ROWS;i++) {//画横线
|
||||
g.drawLine(MARGIN, MARGIN+i*GRID_SPAN, MARGIN+COLS*GRID_SPAN, MARGIN+i*GRID_SPAN);
|
||||
}
|
||||
for(int j=0;j<=COLS;j++) {//画竖线
|
||||
g.drawLine(MARGIN+j*GRID_SPAN, MARGIN, MARGIN+j*GRID_SPAN, MARGIN+ROWS*GRID_SPAN);
|
||||
}
|
||||
for(int i=0;i<chessCount;i++) {//画棋子
|
||||
int xpos=chessList[i].getX()*GRID_SPAN+MARGIN;//得到棋子x坐标
|
||||
int ypos=chessList[i].getY()*GRID_SPAN+MARGIN;//得到棋子y坐标
|
||||
g.setColor(chessList[i].getColor());//设置棋子颜色
|
||||
g.fillOval(xpos-Chess.DIAMETER/2, ypos-Chess.DIAMETER/2, Chess.DIAMETER, Chess.DIAMETER);//画棋子
|
||||
if(i==chessCount-1){
|
||||
g.setColor(Color.red);//标记最后一个棋子为红色
|
||||
g.drawRect(xpos-Chess.DIAMETER/2, ypos-Chess.DIAMETER/2, Chess.DIAMETER, Chess.DIAMETER);
|
||||
}
|
||||
}
|
||||
}
|
||||
private boolean findchess(int index,int yindex) {//查找所在位置是否有棋子
|
||||
for (Chess c : chessList) {
|
||||
if(c!=null&&c.getX()==xindex&&c.getY()==yindex)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean win(int x,int y,boolean start) {//对棋子输赢的判断
|
||||
String str=start?"黑棋":"白棋";
|
||||
//棋子所在行和列是否有五子相连的情况
|
||||
for(int i=0;i<16;i++){
|
||||
if((board[x][i].equals(str)&&board[x][i+1].equals(str)&&board[x][i+2].equals(str)&&board[x][i+3].equals(str)&&board[x][i+4].equals(str))||(board[i][y].equals(str)&&board[i+1][y].equals(str)&&board[i+2][y].equals(str)&&board[i+3][y].equals(str)&&board[i+4][y].equals(str)))
|
||||
return true;
|
||||
}
|
||||
//棋子所在撇行是否有五子相连的情况
|
||||
if(x+y>=4&&x+y<=30){
|
||||
int i=(x+y<=19)?x+y:x+y-20;
|
||||
if(x+y<=19){
|
||||
for(int k=0;k<=i-4;k++){
|
||||
if(board[k][i-k].equals(str)&&board[k+1][i-k-1].equals(str)&&board[k+2][i-k-2].equals(str)&&board[k+3][i-k-3].equals(str)&&board[k+4][i-k-4].equals(str))
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
for(int k=i;k<=15;k++){
|
||||
if(board[k][20-k].equals(str)&&board[k+1][20-k-1].equals(str)&&board[k+2][20-k-2].equals(str)&&board[k+3][20-k-3].equals(str)&&board[k+4][20-k-4].equals(str))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//棋子所在捺行是否有五子相连的情况
|
||||
if(y-x<=15&&x-y<=15){
|
||||
int i=(x<y)?y-x:x-y;
|
||||
if(x<y){
|
||||
for(int k=0;k<=19-4-i;k++){
|
||||
if(board[k][i+k].equals(str)&&board[k+1][i+k+1].equals(str)&&board[k+2][i+k+2].equals(str)&&board[k+3][i+k+3].equals(str)&&board[k+4][i+k+4].equals(str))
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
for(int k=i;k<=15;k++){
|
||||
if(board[k][i+k].equals(str)&&board[k+1][i+k+1].equals(str)&&board[k+2][i+k+2].equals(str)&&board[k+3][i+k+3].equals(str)&&board[k+4][i+k+4].equals(str))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void goback() {//悔棋函数
|
||||
if(chessCount==0) {
|
||||
return ;
|
||||
}
|
||||
chessList[chessCount-1]=null;
|
||||
chessCount--;
|
||||
if(chessCount>0) {
|
||||
xindex=chessList[chessCount-1].getX();
|
||||
yindex=chessList[chessCount-1].getY();
|
||||
}
|
||||
start=!start;
|
||||
repaint();
|
||||
}
|
||||
public void restartGame() {//重新开始函数
|
||||
for(int i=0;i<chessList.length;i++)//设置为初始状态
|
||||
chessList[i]=null;
|
||||
for(int i=0;i<MARGIN*2+GRID_SPAN*COLS;i++) {
|
||||
for (int j = 0; j < MARGIN*2+GRID_SPAN*COLS; j++) {
|
||||
board[i][j]="0";
|
||||
}
|
||||
}
|
||||
start=true;
|
||||
GameOver=false;
|
||||
chessCount=0;
|
||||
repaint();
|
||||
}
|
||||
public Dimension getPreferredSize(){//画矩形
|
||||
return new Dimension(MARGIN*2+GRID_SPAN*COLS,MARGIN*2+GRID_SPAN*ROWS);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package 五子棋;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ChessJFrame extends JFrame {
|
||||
|
||||
private ChessBord chessbord;//声明一个棋盘对象
|
||||
private Panel tool; //声明一个面板对象
|
||||
private Button StartButton;//声明开始按钮
|
||||
private Button BackButton;//声明悔棋按钮
|
||||
private Button exitButton;//声明退出按钮
|
||||
public ChessJFrame() {//构造函数
|
||||
|
||||
setTitle("单机版五子棋");//设置标题
|
||||
MyButtonLister mb=new MyButtonLister();//按钮事件处理对象
|
||||
tool=new Panel();//面板对象
|
||||
chessbord=new ChessBord();//棋盘对象
|
||||
StartButton=new Button("Reopen");//设置开始按钮
|
||||
BackButton=new Button("Regret");//设置悔棋按钮
|
||||
//exitButton=new Button("EXIT");//设置退出游戏按钮
|
||||
tool.setLayout(new FlowLayout(FlowLayout.CENTER ));//流式布局
|
||||
tool.add(StartButton);
|
||||
tool.add(BackButton);
|
||||
// tool.add(exitButton);//将三个按钮添加到面板对象
|
||||
StartButton.addActionListener(mb);
|
||||
BackButton.addActionListener(mb);
|
||||
// exitButton.addActionListener(mb);//将三个按钮添加到事件监听
|
||||
add(tool,BorderLayout.SOUTH);//按钮所在的位置
|
||||
add(chessbord);//添加棋盘对象
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭
|
||||
pack();//自适应
|
||||
}
|
||||
private class MyButtonLister implements ActionListener {
|
||||
//按钮处理事件类
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
Object obj=e.getSource();//获取事件源
|
||||
if(obj==StartButton) {//事件源是重新开始按钮
|
||||
System.out.println("重新开始");
|
||||
chessbord.restartGame();
|
||||
}
|
||||
else if(obj==BackButton) {//事件源是悔棋按钮
|
||||
System.out.println("悔棋!");
|
||||
chessbord.goback();
|
||||
}
|
||||
else if(obj==exitButton) {//事件源是退出按钮
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
ChessJFrame jf = new ChessJFrame();//声明框架对象
|
||||
jf.setLocationRelativeTo(null);//居中显示
|
||||
jf.setVisible(true);//设置为可见
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue