📄 chesspad.java
字号:
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
chessLink = 1;
chessLinkTest = 1;
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if ((a * 20 == chessWhite_x[chessCompare])
&& ((b + step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if ((a * 20 == chessWhite_x[chessCompare])
&& ((b - step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
chessLink = 1;
chessLinkTest = 1;
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if (((a - step) * 20 == chessWhite_x[chessCompare])
&& ((b + step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if (((a + step) * 20 == chessWhite_x[chessCompare])
&& ((b - step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
chessLink = 1;
chessLinkTest = 1;
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if (((a + step) * 20 == chessWhite_x[chessCompare])
&& ((b + step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
else
break;
}
for (step = 1; step <= 4; step++)
{
for (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare++)
{
if (((a - step) * 20 == chessWhite_x[chessCompare])
&& ((b - step) * 20 == chessWhite_y[chessCompare]))
{
chessLink++;
if (chessLink == 5)
{
return (true);
}
}
}
if (chessLink == (chessLinkTest + 1))
chessLinkTest++;
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 chessPaint(int chessPoint_a, int chessPoint_b, int color)
{
chessPoint_black chesspoint_black = new chessPoint_black(this);
chessPoint_white chesspoint_white = new chessPoint_white(this);
if (color == 1 && isMouseEnabled)
{
getLocation(chessPoint_a, chessPoint_b, color);
isWin = checkWin(chessPoint_a, chessPoint_b, color);
if (isWin == false)
{
chessthread.sendMessage("/" + chessPeerName + " /chess "
+ chessPoint_a + " " + chessPoint_b + " " + color);
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
statusText.setText("黑(第" + chessBlackCount + "步)"
+ chessPoint_a + " " + chessPoint_b + ",请白棋下子");
isMouseEnabled = false;
}
else
{
chessthread.sendMessage("/" + chessPeerName + " /chess "
+ chessPoint_a + " " + chessPoint_b + " " + color);
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
chessVictory(1);
isMouseEnabled = false;
}
}
else
if (color == -1 && isMouseEnabled)
{
getLocation(chessPoint_a, chessPoint_b, color);
isWin = checkWin(chessPoint_a, chessPoint_b, color);
if (isWin == false)
{
chessthread.sendMessage("/" + chessPeerName + " /chess "
+ chessPoint_a + " " + chessPoint_b + " " + color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
statusText.setText("白(第" + chessWhiteCount + "步)"
+ chessPoint_a + " " + chessPoint_b + ",请黑棋下子");
isMouseEnabled = false;
}
else
{
chessthread.sendMessage("/" + chessPeerName + " /chess "
+ chessPoint_a + " " + chessPoint_b + " " + color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
chessVictory(-1);
isMouseEnabled = false;
}
}
}
public void netChessPaint(int chessPoint_a, int chessPoint_b, int color)
{
chessPoint_black chesspoint_black = new chessPoint_black(this);
chessPoint_white chesspoint_white = new chessPoint_white(this);
getLocation(chessPoint_a, chessPoint_b, color);
if (color == 1)
{
isWin = checkWin(chessPoint_a, chessPoint_b, color);
if (isWin == false)
{
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
statusText.setText("黑(第" + chessBlackCount + "步)"
+ chessPoint_a + " " + chessPoint_b + ",请白棋下子");
isMouseEnabled = true;
}
else
{
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
chessVictory(1);
isMouseEnabled = true;
}
}
else
if (color == -1)
{
isWin = checkWin(chessPoint_a, chessPoint_b, color);
if (isWin == false)
{
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
statusText.setText("白(第" + chessWhiteCount + "步)"
+ chessPoint_a + " " + chessPoint_b + ",请黑棋下子");
isMouseEnabled = true;
}
else
{
chessthread.sendMessage("/" + chessPeerName + " /victory "
+ color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a * 20 - 7,
chessPoint_b * 20 - 7, 16, 16);
chessVictory(-1);
isMouseEnabled = true;
}
}
}
public void mousePressed(MouseEvent e)
{
if (e.getModifiers() == InputEvent.BUTTON1_MASK)
{
chessPoint_x = (int) e.getX();
chessPoint_y = (int) e.getY();
int a = (chessPoint_x + 10) / 20, b = (chessPoint_y + 10) / 20;
if (chessPoint_x / 20 < 2 || chessPoint_y / 20 < 2
|| chessPoint_x / 20 > 19 || chessPoint_y / 20 > 19)
{
}
else
{
chessPaint(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)
{
}
}
class chessPoint_black extends Canvas implements MouseListener
{
chessPad chesspad = null;
chessPoint_black(chessPad p)
{
setSize(20, 20);
chesspad = p;
addMouseListener(this);
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillOval(0, 0, 14, 14);
}
public void mousePressed(MouseEvent e)
{
// if(e.getModifiers()==InputEvent.BUTTON3_MASK)
// {
// chesspad.remove(this);
// chesspad.chessColor=1;
// chesspad.text_2.setText("");
// chesspad.text_1.setText("请黑棋下子");
// }
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
}
class chessPoint_white extends Canvas implements MouseListener
{
chessPad chesspad = null;
chessPoint_white(chessPad p)
{
setSize(20, 20);
addMouseListener(this);
chesspad = p;
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillOval(0, 0, 14, 14);
}
public void mousePressed(MouseEvent e)
{
// if(e.getModifiers()==InputEvent.BUTTON3_MASK)
// {
// chesspad.remove(this);
// chesspad.chessColor=-1;
// chesspad.text_2.setText("请白旗下子");
// chesspad.text_1.setText("");
// }
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
// if(e.getClickCount()>=2)
// chesspad.remove(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -