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

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记