我想要写一个小游戏可是中途遇到了一些问题 如果 @ 碰到了石头就死了 所以我就弹出 是否继续玩 我按n不要继续玩了(你运行看看就知道了) 我的那个最下面的死了就把sum变成100 main是如果sum变成100就return 0 可是最后并没有停止而是继续进行 这是怎么回事,求mogul解决一下 thank you
#include
#include
#include<Windows.h>
int sum = 1;
using namespace std;
void condition();
void game();
int main() {
if (sum == 100)
{
return 0;
}
game();
}
void game() {
int x = 1, y = 1;
char a[10][11] = { '*','*','*','*','*','*','*','*','*','*','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ','',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',
'*','*','*','*','*','*','*','*','*','*','*', };
char kb;
a[x][y] = '@';
while (1)
{
cout << a[0][0] << a[0][1] << a[0][2] << a[0][3] << a[0][4] << a[0][5] << a[0][6] << a[0][7] << a[0][8] << a[0][9] << a[0][10] << endl;
cout << a[1][0] << a[1][1] << a[1][2] << a[1][3] << a[1][4] << a[1][5] << a[1][6] << a[1][7] << a[1][8] << a[1][9] << a[1][10] << endl;
cout << a[2][0] << a[2][1] << a[2][2] << a[2][3] << a[2][4] << a[2][5] << a[2][6] << a[2][7] << a[2][8] << a[2][9] << a[2][10] << endl;
cout << a[3][0] << a[3][1] << a[3][2] << a[3][3] << a[3][4] << a[3][5] << a[3][6] << a[3][7] << a[3][8] << a[3][9] << a[3][10] << endl;
cout << a[4][0] << a[4][1] << a[4][2] << a[4][3] << a[4][4] << a[4][5] << a[4][6] << a[4][7] << a[4][8] << a[4][9] << a[4][10] << endl;
cout << a[5][0] << a[5][1] << a[5][2] << a[5][3] << a[5][4] << a[5][5] << a[5][6] << a[5][7] << a[5][8] << a[5][9] << a[5][10] << endl;
cout << a[6][0] << a[6][1] << a[6][2] << a[6][3] << a[6][4] << a[6][5] << a[6][6] << a[6][7] << a[6][8] << a[6][9] << a[6][10] << endl;
cout << a[7][0] << a[7][1] << a[7][2] << a[7][3] << a[7][4] << a[7][5] << a[7][6] << a[7][7] << a[7][8] << a[7][9] << a[7][10] << endl;
cout << a[8][0] << a[8][1] << a[8][2] << a[8][3] << a[8][4] << a[8][5] << a[8][6] << a[8][7] << a[8][8] << a[8][9] << a[8][10] << endl;
cout << a[9][0] << a[9][1] << a[9][2] << a[9][3] << a[9][4] << a[9][5] << a[9][6] << a[9][7] << a[9][8] << a[9][9] << a[9][10] << endl;
kb = _getch();
if (kb == 'a' || kb == 'A') {
if (a[x][y-1] == '')
{
condition();
}
if (a[x][y - 1] == ' ') {
a[x][y - 1] = a[x][y]; a[x][y] = ' ';
y--;
}
}
if (kb == 'd' || kb == 'D') {
if (a[x][y+1] == '')
{
condition();
}
if (a[x][y + 1] == ' ') {
a[x][y + 1] = a[x][y]; a[x][y] = ' ';
y++;
}
}
if (kb == 's' || kb == 'S') {
if (a[x + 1][y] == '')
{
condition();
}
if (a[x + 1][y] == ' ') {
a[x + 1][y] = a[x][y]; a[x][y] = ' ';
x++;
}
}
if (kb == 'w' || kb == 'W') {
if (a[x - 1][y] == '')
{
condition();
}
if (a[x - 1][y] == ' ') {
a[x - 1][y] = a[x][y]; a[x][y] = ' ';
x--;
}
}
system("cls");
}
}
void condition() {
system("cls");
printf("\n\n\n笨死了 都死了你还玩 去你的!!\n\n\n");
system("color c");
printf("\n\n\n\n\n 还想不想玩了 想(y) 不想(n) \n");
char ch;
ch = _getch();
if (ch == 'y')
{
system("cls");
game();
}
else if (ch == 'n')
{
system("cls");
system("color c");
printf("正在结束.......");
Sleep(600);
system("cls");
printf("正在结束......");
Sleep(600);
system("cls");
printf("正在结束.......");
Sleep(600);
system("cls");
printf("正在结束......");
Sleep(600);
system("cls");
printf("正在结束.......");
Sleep(600);
system("cls");
printf("正在结束......");
Sleep(600);
system("cls");
printf("正在结束.......");
Sleep(600);
system("cls");
printf("正在结束......");
Sleep(600);
system("cls");
sum = 100;
system("cls");
}
else
{
sum = 100;
printf("aaa");
main();
}
}
你这是相当于在main函数里面调用了main函数,sum=100退出的是你里面调用的main函数,程序启动的第一个main函数并没有退出