作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <stdio.h>
#include <time.h>
#include <windows.h>
int intSlot1, intSlot2, intSlot3;
void fnGotoXY(short x, short y);
void fnSlotMachine();
void fnSlot1();
void fnSlot2();
void fnSlot3();
int main(){
srand( time(0) );
fnSlotMachine();
fnSlot1();
fnSlot2();
fnSlot3();
}
void fnGotoXY(short x, short y){
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void fnSlotMachine(){
fnGotoXY(5, 5);
printf(" x^---------------------------^x\n");
printf(" |oOoOoOoOoOoOoOoOoOoOoOoOoOoOo|\n");
printf(" \\_____________________________/\n");
printf(" /__$$$__\\ /__$$$__\\ /__$$$__\\");
fnGotoXY(5, 12);
printf(" <*^*^*^*> <*^*^*^*> <*^*^*^*>");
}
void fnSlot1(){
while(1){
Sleep(50);
fnGotoXY(5, 9);
intSlot1 = rand() % 9;
printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
fnGotoXY(2, 10);
printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
fnGotoXY(2, 11);
printf(" | %i %i %i |", intSlot1, intSlot1, intSlot1);
}
}
void fnSlot2(){
while(1){
Sleep(50);
fnGotoXY(17, 9);
intSlot2 = rand() % 9;
printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
fnGotoXY(17, 10);
printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
fnGotoXY(17, 11);
printf("| %i %i %i |", intSlot2, intSlot2, intSlot2);
}
}
void fnSlot3(){
while(1){
Sleep(50);
fnGotoXY(27, 9);
intSlot3 = rand() % 9;
printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
fnGotoXY(27, 10);
printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
fnGotoXY(27, 11);
printf("| %i %i %i |", intSlot3, intSlot3, intSlot3);
}
}
所以,我的问题是关于 gotoxy
的。在我放置 while(1)
循环后,其他插槽不会打印。希望得到一些回应。提前致谢!
最佳答案
所有函数中都有无限循环。如果您输入一个函数,您将永远不会返回。
考虑将其放在主函数中。
#include <stdio.h>
#include <time.h>
...
int main(){
srand( time(0) );
fnSlotMachine();
while(1) {
fnSlot1();
fnSlot2();
fnSlot3();
}
}
...
void fnSlot1(){
Sleep(50);
fnGotoXY(5, 9);
intSlot1 = rand() % 9;
printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
fnGotoXY(2, 10);
printf(" | %i %i %i |\n", intSlot1, intSlot1, intSlot1);
fnGotoXY(2, 11);
printf(" | %i %i %i |", intSlot1, intSlot1, intSlot1);
}
void fnSlot2(){
Sleep(50);
fnGotoXY(17, 9);
intSlot2 = rand() % 9;
printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
fnGotoXY(17, 10);
printf("| %i %i %i |\n", intSlot2, intSlot2, intSlot2);
fnGotoXY(17, 11);
printf("| %i %i %i |", intSlot2, intSlot2, intSlot2);
}
void fnSlot3(){
Sleep(50);
fnGotoXY(27, 9);
intSlot3 = rand() % 9;
printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
fnGotoXY(27, 10);
printf("| %i %i %i |\n", intSlot3, intSlot3, intSlot3);
fnGotoXY(27, 11);
printf("| %i %i %i |", intSlot3, intSlot3, intSlot3);
}
关于c - C 语言老虎机 (gotoxy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27685617/
代码运行良好。然而有一个小问题,如果后两个数字相同,则代码表示没有数字匹配。例如: 0 2 2没有匹配的数字再玩一次? (是/否?) 显然应该说: 0 2 2两个数字匹配再玩一次? (是/否?) 如何
我是一名 Python 新手,正在尝试创建一个模拟真机支出的老虎机模拟器。我在计算线路支出时遇到了问题,我确信有一种更智能的方法可以遍历线路并计算它们。 定义一些我将要使用的常量: SymbolMap
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我是一名优秀的程序员,十分优秀!