1)选择棋子 |
目标 |
2)画棋子 |
✔️ |
3)判断胜负 |
|
4)交换行棋方 |
前面,我们已经画好的棋盘和棋子,接下来,我们要通过鼠标点击屏幕获取落子位置并落子(先不考虑行棋方和胜负判断)。
步骤:
1)捕捉鼠标按下的位置
2)经过坐标变换(由像素位置->0-19的棋盘位置)
3)更新记录棋盘状态的二维数组
4)重新渲染绘制棋盘。
-----------------------------------------------------落子动作代码示例如下-----------------------------------------------------
一个棋子类Chessman.java
package xchen.test.simpleGobang;
public class Chessman {
private int color;//1-white,0-black
private boolean placed = false;
public Chessman(int color,boolean placed){
this.color=color;
this.placed=placed;
}
public boolean getPlaced() {