Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA:Switch语句似乎每秒钟都在跳过一次Case条件_Java_Eclipse - Fatal编程技术网

JAVA:Switch语句似乎每秒钟都在跳过一次Case条件

JAVA:Switch语句似乎每秒钟都在跳过一次Case条件,java,eclipse,Java,Eclipse,我被难住了,我正在使用EclipseIDE,并且正在使用ATW和Swing构建一个游戏。然而,一个随机的bug潜入了我的脚本,我不知道如何或者为什么,因为这部分代码已经很久没有被触及了。本质上,我使用switch语句来确定在什么时候加载哪些图像以创建一种介绍序列,下面是脚本: // condition that only runs once within the print function if (gameState == "start")

我被难住了,我正在使用EclipseIDE,并且正在使用ATW和Swing构建一个游戏。然而,一个随机的bug潜入了我的脚本,我不知道如何或者为什么,因为这部分代码已经很久没有被触及了。本质上,我使用switch语句来确定在什么时候加载哪些图像以创建一种介绍序列,下面是脚本:


        // condition that only runs once within the print function

        if (gameState == "start")
        {
            //gameAudio.loopMusic(false);




            //intro animation
            switch(startCounter) 
            {
                //3 and a half seconds of buffer split into 10 parts to allow for updating screen during startup of app
              case 0:
              case 1:
              case 2:
              case 3:
              case 4:
              case 5:
              case 6:
              case 7:
              case 8:
              case 9:
                wait(350);

                break;

              case 10:  
                gameAudio.playMusic("src/res/audio/JackEditedIntro.wav");
                gameAudio.setVolume(0.6);
                wait(300);
                samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/SwingUpSam.png");

                break;

              case 11:
                  wait(40);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/HighFiveSam.png");
                  samPow = new ImageIcon("src/res/SamAssets/SamFullBody/PowSam.png");

                  break;

              case 12:
                  wait(100);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/HighFiveSam.png");
                  samPow = new ImageIcon("");

                  break;


              case 13:
                  wait(1200);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/WaveSam.png");

                  break;
              case 14:
                  wait(1200);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/SwingUpSam.png");

                  break;

              case 15:
                  wait(40);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/IdleSam.png");

                  break;

              case 16:

                  wait(500);
                  samIcon = new ImageIcon("");

                  break;

              case 17:

                  wait(300);
                  gameAudio.playMusic("src/res/audio/BattleStart.wav");

                  wait(2000);

                  break;

              default:
               wait(5);
               System.out.println("Default start up switch statement");
            }



            setBackground(Color.BLACK);
            samIcon.paintIcon(this,  g,  540, 20);
            samPow.paintIcon(this, g, 720, 20);



            //samIcon.ImageIcon();









            if (startCounter < 17)
            {
                startCounter += 1;


            }


            else
            {
                //start the actual game
                gameState = "menu";

                //play the song

                gameAudio.playMusic("src/res/audio/AllTheWay.wav");
                gameAudio.setVolume(0.2);
                gameAudio.loopMusic(true);


                // default Sam
                samIcon = new ImageIcon("src/res/SamAssets/IdleSam.png");

            }


        }


//在打印功能中只运行一次的条件
如果(游戏状态=“开始”)
{
//gameAudio.loopMusic(错误);
//介绍动画
开关(启动计数器)
{
//3.5秒的缓冲区分为10个部分,以便在应用程序启动期间更新屏幕
案例0:
案例1:
案例2:
案例3:
案例4:
案例5:
案例6:
案例7:
案例8:
案例9:
等待(350);
打破
案例10:
播放音乐(“src/res/audio/JackEditedIntro.wav”);
gameAudio.setVolume(0.6);
等待(300);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/SwingUpSam.png”);
打破
案例11:
等待(40);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/HighFiveSam.png”);
samPow=newimageicon(“src/res/SamAssets/SamFullBody/PowSam.png”);
打破
案例12:
等待(100);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/HighFiveSam.png”);
samPow=新图像图标(“”);
打破
案例13:
等待(1200);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/WaveSam.png”);
打破
案例14:
等待(1200);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/SwingUpSam.png”);
打破
案例15:
等待(40);
samIcon=newimageicon(“src/res/SamAssets/SamFullBody/IdleSam.png”);
打破
案例16:
等待(500);
samIcon=新图像图标(“”);
打破
案例17:
等待(300);
播放音乐(“src/res/audio/BattleStart.wav”);
等待(2000年);
打破
违约:
等待(5);
System.out.println(“默认启动开关语句”);
}
挫折背景(颜色:黑色);
samIcon.paintIcon(这个,g,540,20);
samPow.paintIcon(这个,g,720,20);
//samIcon.ImageIcon();
如果(起始计数器<17)
{
startCounter+=1;
}
其他的
{
//开始真正的游戏
gameState=“菜单”;
//播放歌曲
播放音乐(“src/res/audio/AllTheWay.wav”);
gameAudio.setVolume(0.2);
gameAudio.loopMusic(真实);
//默认Sam
samIcon=newimageicon(“src/res/SamAssets/IdleSam.png”);
}
}
问题是并不是我所有的图像都被加载,一些声音文件没有播放(我对源文件进行了五次检查,这些源文件已经很久没有接触过了,不应该是问题的一部分)。脚本似乎跳过了案例11、案例13、案例15和案例17,因此我最好的猜测是脚本每秒钟都会跳过一次案例条件(我很难验证它是否在语句的前面部分跳过),但我还不清楚原因。如果有人能对我的问题有所了解,我将不胜感激

PS:这只是我一生中第二个庞大的编码项目,所以我为这种可怕的编码风格深表歉意,希望你能原谅我,谢谢


更新:我在每个案例增量中添加了System.out.println,每个数字都出现在控制台中,尽管这些案例中没有加载图像和音频。让我更困惑200%,我极度需要帮助。

< P>你是否停留在一个有条件的“时间”中,而任何时候变量都是1的, 我相信你的逻辑,有一个条件,实现+1。请删除它:

if (startCounter < 17)
            {
                startCounter += 1;


            }
if(起始计数器<17)
{
startCounter+=1;
}

或者回顾一下这个逻辑,因为在任何时刻,如果输入了if块,你都会加上1。

if(gameState==“start”)
。啊,是的,这是一个很好的注释。我把它改为:gameState.equals(“开始”),但它似乎并没有解决这个问题。谢谢你的推荐!我不确定“我在每个案例增量中添加了System.out.println”是什么意思。您现在可以准确地显示您的代码,删除空行,并显示您看到的确切输出吗?您好,谢谢您的评论。我对我的变量做了一个单词搜索,变量唯一被更改的时间是在if语句中。。。不幸的是,我不认为这是我剧本中的罪魁祸首。请分享整个剧本