在标准绘图中有一个isKeyPressed()
功能。该函数返回一个boolean
指示参数是否被按下。
在我正在制作的基于文本的游戏中,用户将按下y
或n
确定结果。有时,但并非总是如此,会跳过以下故事文本。这是我的代码。我在eclipse中运行这个。这不是我的全部代码,但我认为问题出在哪里。
while(true){
else if(stage == 6){
StdDraw.textLeft(0, 700,"'so, ya name's "+ name + ", huh?'");
StdDraw.textLeft(0, 680,"'What an odd name if i do say so.'");
StdDraw.textLeft(0, 660,"'you're lucky i found you when i did, the dark forest is dangerous!'");
StdDraw.textLeft(0, 620,"'So, you heading to Ivangard, right?'(y/n)");
counter = 1;
if(StdDraw.isKeyPressed('Y')&&frame%8==0){
stage = 7;
}
else if (StdDraw.isKeyPressed('N')&&frame%8==0){
stage = 9;
}
}
else if(stage == 7){
StdDraw.textLeft(0, 700,"'well lucky you! i'm going in the same direction!'");
StdDraw.textLeft(0, 680,"'Well i'm Program "+ random +", nice to meet you.'");
StdDraw.textLeft(0, 660,"'take this rusty dagger. may be of use!'");
StdDraw.textLeft(0, 640,"'ill see you in Ivangaurd!'");
StdDraw.textLeft(0, 500,"continue?(O)");
if(StdDraw.isKeyPressed('O')&&frame%12==0){
stage = 11;
programn = random;
fist = 0;
rustyd = 1;
}
}
else if(stage == 9){
StdDraw.textLeft(0, 700,"'Well, if you need me, ill be in Ivangaurd'");
StdDraw.textLeft(0, 680,"'I'm Program #"+ random +", nice to meet you.'");
StdDraw.textLeft(0, 660,"'take this rusty dagger. may be of use!'");
StdDraw.textLeft(0, 620,"continue?(O)");
counter = 1;
programn = random;
fist = 0;
rustyd = 1;
if(StdDraw.isKeyPressed('O')&&frame%12==0){
stage = 11;
}
}
else if(stage == 11){
StdDraw.textLeft(0, 700,"Part 2: The virus");
StdDraw.textLeft(0, 660,"as you leave the dark forest, The voice comes back");
StdDraw.textLeft(0, 640,"A great evil is coming to this land.");
StdDraw.textLeft(0, 620,"a virus, a plague the program...");
StdDraw.textLeft(0, 600,"unlike the program, all the virus does is eat.");
StdDraw.textLeft(0, 580,"That is why we need you.");
StdDraw.textLeft(0, 560,"you are human, uneatable to the virus. All other warriors would fall were you stand.");
StdDraw.textLeft(0, 540,"continue?(0)");
if(StdDraw.isKeyPressed('O')&&frame%12==0){
stage = 10;
}
}
}
问题出在 y/n 选项之后,它会跳过以下文本。
新文本在这里。我是新手编码员,所以我可能不明白你告诉我要做什么。
else if(stage == 6){
StdDraw.textLeft(0, 700,"'so, ya name's "+ name + ", huh?'");
StdDraw.textLeft(0, 680,"'What an odd name if i do say so.'");
StdDraw.textLeft(0, 660,"'you're lucky i found you when i did, the dark forest is dangerous!'");
StdDraw.textLeft(0, 620,"'So, you heading to Ivangard, right?'(y/n)");
counter = 1;
if(StdDraw.isKeyPressed('Y')&&frame%8==0){
stage = 7;
}
if(StdDraw.isKeyPressed('N')&&frame%8==0){
stage = 9;
}
}