- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是贪吃蛇游戏的部分代码。我想做的是制作关卡(大约3个),如果分数达到一定的分数(100或200),关卡就会改变。
在这段代码中,我尝试让分数达到 100 时进入第 2 阶段。但正如我编码的那样,它只是在 main 函数中循环并直接进入 stage3。
这是主要代码:
int main(){
title();
while(1)
{
if(kbhit()) do{key=getch();} while(key==224); // Key input
Sleep(speed);
switch(key) // Apprehend the key and runs the program
{
case LEFT:
case RIGHT:
case UP:
case DOWN:
if( (dir==LEFT&&key!=RIGHT)||(dir==RIGHT&&key!=LEFT)||(dir==UP&&key!=DOWN)||
(dir==DOWN&&key!=UP)) // Need for prevent the 180 degrees rotational movement
dir=key;
key=0; // Reset the key to 0
phá vỡ;
case PAUSE:
pause();
phá vỡ;
case 115: // input 'S', then status() activated
if(status_on==0) status_on=1;
else status_on=0;
key=0;
phá vỡ;
case ESC: // Program exits if the input value is ESC
thoát(0);
}
move(dir);
if(status_on==1) status();
}
如您所见,移动函数位于 while(1) 中。
这是 move(dir) 的代码:
void move(int dir)
{
int i, j;
if(x[0]==food_x&&y[0]==food_y) // Case when it hits with food
{
score+=10;
food();
length++;
x[length-1]=x[length-2];
y[length-1]=y[length-2];
}
for (j = 0; j < num_of_bombs; j++)
{
if (x[0] == bomb_x[j] && y[0] == bomb_y[j]) // Case when it hits with bomb
{
score -= 10;
for (j = 0; j < num_of_bombs; j++)
gotoxy(MAP_ADJ_X + bomb_x[j], MAP_ADJ_Y + bomb_y[j], " "); // Delets the lastest bombs
bomb();
gotoxy(MAP_ADJ_X + x[length - 1], MAP_ADJ_Y + y[length - 1], " "); // Delets the last body of the snake
length--;
}
}
if(x[0]==0||x[0]==MAP_X-1||y[0]==0||y[0]==MAP_Y-1) // Case when it hits the wall
{
game_over();
return;
}
for(i=1;i
{
if(x[0]==x[i]&&y[0]==y[i])
{
game_over();
return;
}
}
gotoxy(MAP_ADJ_X+x[length-1],MAP_ADJ_Y+y[length-1]," "); // Delets it's last one
for(i=length-1;i>0;i--) // Move the coordinates one by one
{
x[i]=x[i-1];
y[i]=y[i-1];
}
gotoxy(MAP_ADJ_X+x[0],MAP_ADJ_Y+y[0],"▣"); // Part that changes head to body. But in this code, it is unnecessery
if(dir==LEFT) --x[0];
if(dir==RIGHT) ++x[0];
if(dir==UP) --y[0];
if(dir==DOWN) ++y[0];
gotoxy(MAP_ADJ_X+x[i],MAP_ADJ_Y+y[i],"▣"); // Part that puts new head. But unnecessery in this code
if (length < 2) // If length goes down below 2, gmae is over
game_over();
switch (score)
{
case 100:
case 200:
++stage;
phá vỡ;
}
switch (stage)
{
case 2:
stage2();
case 3:
stage3();
}
}
有人可以帮我吗?
最好,
兰迪
1 Câu trả lời
默认情况下,công tắc
语句中的情况会失败,除非包含 phá vỡ
。在你的代码中你有
switch(stage)
{
case 2:
stage2();
// Here there is an implicit fall through because a break statement is missing.
case 3:
// This gets executed if stage == 3 but also if stage == 2
// because of the fall through you first go to stage2() and then immediately afterwards to stage3()
stage3();
}
解决方案是在调用 stage2()
之后添加 phá vỡ;
.
此行为会导致许多问题,以至于 gcc
等编译器具有选项 -Wimplicit-fallthrough
。使用该选项,每次您有意使用该行为时,都必须添加类似 //fall-through
的注释。
关于C/我如何从这里到达第 2 阶段?它只是循环并直接进入第 3 阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567511/
如果我在 C 中调用一个函数并传入一个结构(对那些 C++ 读者来说不是通过指针或引用),它会复制该对象。如果我传入一个包含数组的结构,它会复制该数组(如教授在类里面所说)。但是,如果我传入一个包含对
在 vim 等中,您可以使用 CTRLA 和 CTRLX 增加或减少光标所在的数字。然而,这会增加总数,但我想简单地增加光标正下方的数字。这有点难以描述,所以这就是我的意思: Ctrl+A usage
我正在将 Spring 4.3.2 项目升级到 Spring 5.1.5。我的一个测试用例开始因错误而失败。 ClassNotFoundException: org.hibernate.propert
我想在 Java 中分配一个直接 IntBuffer,比如说 10 亿个元素(64 位系统)。我知道的唯一方法是创建一个直接 ByteBuffer 并将其视为直接 IntBuffer。但是,4*1,0
我正在寻找特定的打印机或某些打印机上存在的技术(接口(interface)、标准、协议(protocol)),这使得可以使用 AJAX 从 Web 浏览器实现直接打印。 这意味着打印机必须: 网络接口
我正在寻求实现删除确认表单的最佳实践建议。 除其他选项外,以下页面包含删除按钮... /website/features/f/123 ...当点击一个简单的表单时,会在以下 url 下加载: /web
我正在使用直接 Web 远程处理库在我的应用程序中执行一些 ajax 调用。我有一个问题,我认为归结为服务调用的延迟响应。以下是我认为有问题的部分代码。问题出在 getDefaultReviewerT
我想替换 Javascript confirm() 函数以允许自定义按钮而不是 Yes/Cancel。我尝试搜索,但所有解决方案都是事件驱动的,例如 jquery 对话框(代码不等待响应但它是事件驱动
我知道有几个类似的问题,但是,其中的示例并没有说明问题,或者我无法从中获利 - 我真可耻。 所以我的问题是在带有 GUI 的简单应用程序中加载图像。例如: 我在 "D:\javaeclipseprog
我想用不同的颜色为表格的行着色,所以我正在使用它 table#news tr:nth-child(even) { background-color: red; } table#news
下面的测试代码不起作用 from("direct:start").setExchangePattern(ExchangePattern.InOnly).threads(5).delay(2000).b
我在 python 中实现的第一个项目之一是对棒渗流进行蒙特卡罗模拟。代码不断增长。第一部分是棍子渗滤的可视化。在宽度*长度的区域中,使用随机起始坐标和方向绘制具有一定长度的直棒的定义密度(棒/面积)
跟踪直接文件下载的最佳方法是什么?我找到了一些解决方案,例如这个: http://www.gayadesign.com/diy/download-counter-in-php-using-htacce
我在一个线程中有一个直接的 ByteBuffer(堆外),并使用 JMM 给我的一种机制将它安全地发布到另一个线程。 happens-before 关系是否扩展到由 ByteBuffer 包装的 na
当我测试直接 java.nio.ByteBuffer 的读取性能时,我注意到绝对读取平均比相对读取快 2 倍。此外,如果我比较相对读取与绝对读取的源代码,除了相对读取维护和内部计数器外,代码几乎相同。
我知道这个问题已经被问了无数次,并且在很多情况下都得到了答案。我相信我已经阅读了其中的大部分内容。不幸的是,我在这上面能找到的一切 简单说明 ElementRef.nativeElement不好,不要
回到一些 C 语言工作。 我的许多函数看起来像这样: int err = do_something(arg1, arg2, arg3, &result); 根据意图,结果由函数填充,返回值是调用的状态
当我将 XML 提交到 https://secure-test.WorldPay.com/jsp/merchant/xml/paymentService.jsp 时: Personalised
Hiện tại, câu hỏi này không phù hợp với định dạng Hỏi & Đáp của chúng tôi. Chúng tôi mong đợi câu trả lời được hỗ trợ bằng sự kiện, trích dẫn hoặc chuyên môn, nhưng câu hỏi này có thể gây ra tranh luận, tranh cãi, thăm dò ý kiến hoặc thảo luận mở rộng. Nếu bạn cảm thấy câu hỏi này có thể được cải thiện và có thể mở lại, hãy truy cập
我的 Angular 路由行为有问题。刷新或输入的 url 像/user 总是将我重定向到/home。我还在 index.html 文件中设置了 。通过单击导航菜单按钮一切正常。但是一旦我尝试刷新页面
Tôi là một lập trình viên xuất sắc, rất giỏi!