qq_38326782 2017-05-09 05:12
浏览 534

javafx相同的调用函数被跳过执行

这是一个想要实现三消的源代码(主要是想把三消游戏的小方块用按钮来处理,然后点击后为相应按钮设置一条轨迹使之运动),但是遇到了如下问题。
if(((twoButtonsPos.get(0)==twoButtonsPos.get(2))&&(Math.abs((twoButtonsPos.get(1)-twoButtonsPos.get(3)))==1))||((twoButtonsPos.get(1)==twoButtonsPos.get(3))&&(Math.abs((twoButtonsPos.get(0)-twoButtonsPos.get(2)))==1))){
ExchangableButton.ExchangeButton(gameView, primaryStage, scene, pane);
gameView[twoButtonsPos.get(0)][twoButtonsPos.get(1)]=twoButtons.get(1);
gameView[twoButtonsPos.get(2)][twoButtonsPos.get(3)]=twoButtons.get(0);
//交换的动画和实际引用的交换同时发生
if(DetectMatch.ExistMatch(gameView)){
gameView[twoButtonsPos.get(0)][twoButtonsPos.get(1)].removable=true;
gameView[twoButtonsPos.get(2)][twoButtonsPos.get(3)].removable=true;//这两行应该来说也是不需要的,在DetectMatch.ExustMatch里就已经解决了
return true;}
else{
ExchangableButton.ExchangeButton(gameView, primaryStage, scene, pane);
gameView[twoButtonsPos.get(0)][twoButtonsPos.get(1)]=twoButtons.get(0);
gameView[twoButtonsPos.get(2)][twoButtonsPos.get(3)]=twoButtons.get(1);//交换的动画和实际引用的交换同时发生
gameView[twoButtonsPos.get(0)][twoButtonsPos.get(1)].clicked=false;
gameView[twoButtonsPos.get(2)][twoButtonsPos.get(3)].clicked=false;
return false;
}
}
else{
gameView[twoButtonsPos.get(0)][twoButtonsPos.get(1)].clicked=false;
gameView[twoButtonsPos.get(2)][twoButtonsPos.get(3)].clicked=false;
return false;}
其中第一个if else是判断点击的两个按钮是否相邻,如果相邻就把两个按钮的位置交换
Line path1=new Line(40,40,(40+(temp.get(1).col-temp.get(0).col)*80),(40+(temp.get(1).row-temp.get(0).row)*80));
Line path2=new Line(40,40,(40-(temp.get(1).col-temp.get(0).col)*80),(40-(temp.get(1).row-temp.get(0).row)*80));
//每个节点的轨迹的开始和结束坐标都是相对于自己的中心点的坐标而言的

    path1.setStroke(Color.BLACK);
    path2.setStroke(Color.BLACK);

    PathTransition pt1=new PathTransition();
    pt1.setPath(path1);
    pt1.setNode(gameView[temp.get(0).row][temp.get(0).col]);
    pt1.setOrientation(OrientationType.NONE);
    pt1.setDuration(Duration.seconds(3));
    pt1.play();


    PathTransition pt2=new PathTransition();
    pt2.setPath(path2);
    pt2.setNode(gameView[temp.get(1).row][temp.get(1).col]);
    pt2.setOrientation(OrientationType.NONE);
    pt2.setDuration(Duration.seconds(3));
    pt2.play();

    primaryStage.show();

这是交换动画的源码。gameView是我用来储存按钮的数组。交换之后再用我自己写的判断是否存在满足条件的三个button 可以消除,如果可以就消除,不能的话就再调用函数换回去。
但是运行的时候出现了问题,就是我点了两个相邻但是交换后不能消除的button后,它会直接跳过 不执行第一个if判断里的动画,而是直接执行第二个if else 判断的else的动画

  • 写回答

0条回答 默认 最新

      报告相同问题?

      悬赏问题

      • ¥20 用Power Query整合的问题
      • ¥20 基于python进行多背包问题的多值编码
      • ¥15 相同型号电脑与配置,发现主板有一台貌似缺少了好多元器件似的,会影响稳定性和使用寿命吗?
      • ¥15 要求编写稀疏矩阵A的转置矩阵的算法
      • ¥15 编写满足以下要求的停车场管理程序,设停车场只有一个可停放n辆车的狭窄通道且只有一个大门可供车辆进出。
      • ¥15 C语言:数据子序列基础版
      • ¥20 powerbulider 导入excel文件,显示不完整
      • ¥15 用keil调试程序保证结果进行led相关闪烁
      • ¥15 paddle训练自己的数据loss降不下去
      • ¥20 用matlab的pdetool解决以下三个问题