首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跳棋瓷砖不能正常工作

跳棋瓷砖不能正常工作
EN

Stack Overflow用户
提问于 2015-01-18 22:28:05
回答 1查看 37关注 0票数 0

我正在做一项跳棋作业,即使我把它设置成只使相应的米色变成绿色,角落的部分仍然会使棕色的部分发光,如下所示:

http://i.stack.imgur.com/SFggh.png

这是它的代码:

代码语言:javascript
复制
for(int x=0; x<64; x++)
  {
    if (e.getSource()==board[x] && board[x].getText().equals("0") && board[x].getForeground().equals(Color.WHITE))
    {
        board[x].setBackground(Color.YELLOW);
        board[x-7].setBackground(Color.GREEN);
        board[x-9].setBackground(Color.GREEN);
        clickSteps=2;
      }

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-18 22:36:04

如果您需要将board保持为一个单一维度,这可能有效(未经测试):

代码语言:javascript
复制
for(int x = 0; x < 64; x++) {
    if(e.getSource() == board[x] &&
       board[x].getText().equals("0") &&
       board[x].getForeground().equals(Color.WHITE)) {
       board[x].setBackground(Color.YELLOW);
       int myPos = x % 8;
       if(myPos < 7) {
          // Up and to the right, only if we are not rightmost.
          board[x-7].setBackground(Color.GREEN);
       }
       if(myPos > 0) {
          // Up and to the left, only if we are not leftmost.
          board[x-9].setBackground(Color.GREEN);
       }
    }       
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28015552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档