我想制作一个抽卡模拟的系统,但是一旦进入了单抽或者十连的循环后无法从中跳出进入另一个循环体。
例如:
我运行后按下A键,进入了单抽循环体,但是接下来无论按下哪个按键,都不会终止单抽循环体,也不能通过按下S键进入十连循环体。
但我希望实现的效果是:
按下A键进入单抽循环,按下S键进入十连循环,其他按键均不会触发任何事件,或者通过按下指定按键回到最初始状态(即界面上显示“按A键开始单次招募,按S键开始十连招募”
以下是代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include<string.h>
#include <iostream>
#include<conio.h>
#define random(x) (rand()%x)
using namespace std;
void display(int x);
int main() {
srand((int)time(0));
int Num = 0;
int Dig = 0;
int i = 0;
cout << endl << endl << "按A键开始单次招募,按S键开始十连招募" << endl << "Press the key 'A' or 'S' to Start";
_getch();
system("cls");
char c;
if (GetAsyncKeyState('A')) {
while(1){
Num = random(99);
display(Num);
Sleep(50);
system("pause");
system("cls");
}
}else
if (GetAsyncKeyState('S')) {
while(2){
while (i<10) {
Dig = random(99);
display(Dig);
i=i+1;
}
i = 0;
system("pause");
system("cls");
}
}
}
void display(int x) {
if(89 < x){
cout << endl << endl << "管理员招募结果:金币" << x << endl << endl << endl;
}
else if(49 < x && x <= 89){
cout << endl << endl << "管理员招募结果:升级材料" << x << endl << endl << endl;
}
else if(34 < x && x <= 49){
cout << endl << endl << "管理员招募结果:外加武装构件图纸" << x << endl << endl << endl;
}
else if(9 < x && x <= 34){
cout << endl << endl << "管理员招募结果:三星级管理员" << x << endl << endl << endl;
}
else if(1 < x && x <= 9){
cout << endl << endl << "管理员招募结果:四星级管理员" << x << endl << endl << endl;
}
else if(1 >= x){
cout << endl << endl << "管理员招募结果:五星级管理员" << x << endl << endl << endl;
}
}
//版本:1.1
//功能:实现抽奖结果二次分类。 添加单次招募与十连招募功能。
//概率:
//金币:10%
//升级材料:40%
//外加武装构件图纸:25%
//三星级管理员:25%
//四星级管理员:8%
//五星级管理员:2%
请问我该如何修改我的代码才能实现我的目的?