📄 firpad.java
字号:
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& (yPos * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的左边4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的上边4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的下边4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的左上方向4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的右下方向4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的右上方向4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 判断当前下的棋子的左下方向4个棋子是否都为白棋
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return (true);
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
}
return false;
}
// 画棋盘
public void paint(Graphics g)
{
for (int i = 40; i <= 380; i = i + 20)
{
g.drawLine(40, i, 400, i);
}
g.drawLine(40, 400, 400, 400);
for (int j = 40; j <= 380; j = j + 20)
{
g.drawLine(j, 40, j, 400);
}
g.drawLine(400, 40, 400, 400);
g.fillOval(97, 97, 6, 6);
g.fillOval(337, 97, 6, 6);
g.fillOval(97, 337, 6, 6);
g.fillOval(337, 337, 6, 6);
g.fillOval(217, 217, 6, 6);
}
// 画棋子
public void paintFirPoint(int xPos, int yPos, int chessColor)
{
FIRPointBlack firPBlack = new FIRPointBlack(this);
FIRPointWhite firPWhite = new FIRPointWhite(this);
if (chessColor == 1 && isMouseEnabled)
{ // 黑棋
// 设置棋子的位置
setLocation(xPos, yPos, chessColor);
// 取得当前局面状态
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{ // 非胜利状态
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPBlack); // 将棋子添加到棋盘中
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16); // 设置棋子边界
statusText.setText("黑(第" + chessBlackCount + "步)"
+ xPos + " " + yPos + ",轮到白方.");
isMouseEnabled = false; // 将鼠标设为不可用
}
else
{ // 胜利状态
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(1); // 调用胜利方法,传入参数为黑棋胜利
isMouseEnabled = false;
}
}
else if (chessColor == -1 && isMouseEnabled)
{ // 白棋
setLocation(xPos, yPos, chessColor);
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText("白(第" + chessWhiteCount + "步)"
+ xPos + " " + yPos + ",轮到黑方.");
isMouseEnabled = false;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(-1); // 调用胜利方法,传入参数为白棋
isMouseEnabled = false;
}
}
}
// 画网络棋盘
public void paintNetFirPoint(int xPos, int yPos, int chessColor)
{
FIRPointBlack firPBlack = new FIRPointBlack(this);
FIRPointWhite firPWhite = new FIRPointWhite(this);
setLocation(xPos, yPos, chessColor);
if (chessColor == 1)
{
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText("黑(第" + chessBlackCount + "步)"
+ xPos + " " + yPos + ",轮到白方.");
isMouseEnabled = true;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /victory "
+ chessColor);//djr
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(1);
isMouseEnabled = true;
}
}
else if (chessColor == -1)
{
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText("白(第" + chessWhiteCount + "步)"
+ xPos + " " + yPos + ",轮到黑方.");
isMouseEnabled = true;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /victory "
+ chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(-1);
isMouseEnabled = true;
}
}
}
// 捕获下棋事件
public void mousePressed(MouseEvent e)
{
if (e.getModifiers() == InputEvent.BUTTON1_MASK)
{
chessX_POS = (int) e.getX();
chessY_POS = (int) e.getY();
int a = (chessX_POS + 10) / 20, b = (chessY_POS + 10) / 20;
if (chessX_POS / 20 < 2 || chessY_POS / 20 < 2
|| chessX_POS / 20 > 19 || chessY_POS / 20 > 19)
{
// 下棋位置不正确时,不执行任何操作
}
else
{
paintFirPoint(a, b, chessColor); // 画棋子
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -