询问关于引用心型函数后,有[Error] expected unqualified-id before '{' token错误如何解决(问题所在由//!!!后标注)
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <mmsystem.h>
#include <tchar.h>
void HideCursor(int x) { // x=0隐藏光标,x=1显示光标
CONSOLE_CURSOR_INFO cursor_info = {1, x};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//设置光标位置函数 教材p313
void GotoXY(int x, int y) {
COORD pos;
pos.X = x - 1;
pos.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
//绘制矩形函数 教材p334
void DrawRectangle(int x1, int x2, int y1, int y2) {
int i;
for (i = x1; i <= x2; i = i + 2) {
GotoXY(i, y1);
printf("█");
GotoXY(i, y2);
printf("█");
}
for (i = y1; i < y2; i = i + 1) {
GotoXY(x1, i);
printf("█");
GotoXY(x2, i);
printf("█");
}
}
void SetColor(int color) {
HANDLE consolehwnd;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(consolehwnd, &csbiInfo);
color = color + (csbiInfo.wAttributes & 0xf);
SetConsoleTextAttribute(consolehwnd, color);
}
void SetColorBk(int color) {
HANDLE consolehwnd;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(consolehwnd, &csbiInfo);
color = (color << 4) + (csbiInfo.wAttributes & 0xf);
SetConsoleTextAttribute(consolehwnd, color);
}
//字符雨主函数 教材p338
float f(float x, float y, float z) {
float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
}
float h(float x, float z) {
for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
if (f(x, y, z) <= 0.0f)
return y;
return 0.0f;
}
int main() {
HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
_TCHAR buffer[25][80] = { _T(' ') };
_TCHAR ramp[] = _T(".:-=+*#%@");
for (float t = 0.0f;; t += 0.1f) {
int sy = 0;
float s = sinf(t);
float a = s * s * s * s * 0.2f;
for (float z = 1.3f; z > -1.2f; z -= 0.1f) {
_TCHAR* p = &buffer[sy++][0];
float tz = z * (1.2f - a);
for (float x = -1.5f; x < 1.5f; x += 0.05f) {
float tx = x * (1.2f + a);
float v = f(tx, 0.0f, tz);
if (v <= 0.0f) {
float y0 = h(tx, tz);
float ny = 0.01f;
float nx = h(tx + ny, tz) - y0;
float nz = h(tx, tz + ny) - y0;
float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
*p++ = ramp[(int)(d * 5.0f)];
} else
*p++ = ' ';
}
}
for (sy = 0; sy < 25; sy++) {
COORD coord = { 0, sy };
SetConsoleCursorPosition(o, coord);
WriteConsole(o, buffer[sy], 79, NULL, 0);
}
Sleep(33);
}
}//心型函数封面
_**int { //!!!!!!!!!!!![Error] expected unqualified-id before '{' token**_
printf("字符雨游戏点此进入");
getchar();
system("cls");
int x1 = 50, y1 = 1, x2 = x1 + 26 + 2, y2 = y1 + 26, score = 0;
int i, t, d, ch, color, colour;
char c;
printf("欢迎来到字符雨的世界\n");
printf("游戏即将开始!\n");
printf("冒险者,你准备好了嘛?\n");
system("pause");
system("cls");
printf("请输入1-5来选择你喜欢的字符颜色\n");
printf("1为灰色\n") ;
printf("2为蓝色\n") ;
printf("3为绿色\n") ;
printf("4为湖蓝色\n");
printf("5为红色\n") ;
printf("经我亲身测试多年(bushi)建议选择红色哦亲\n");
scanf("%d", &color);
if (color <= 5) {
SetColor(color);
}
system("cls");
printf("请再输入数字来选择你想要的的背景颜色\n");
printf("0为黑色\n") ;
printf("1为蓝色\n") ;
printf("2为绿色\n") ;
printf("3为湖蓝色\n");
printf("4为红色\n") ;
printf("5为紫色\n") ;
printf("6为黄色\n") ;
printf("7为白色\n") ;
printf("8为灰色\n") ;
printf("9为淡蓝色\n") ;
printf("10为淡绿色\n") ;
printf("11为淡浅绿色\n") ;
printf("12为淡红色\n") ;
printf("13为淡紫色\n") ;
printf("14为淡黄色\n") ;
printf("15为亮白色\n") ;
printf("经丰某人测试建议选择亮白色搭配红色最为醒目哦\n");
scanf("%d", &colour);
if (colour <= 15) {
SetColorBk(colour);
}
system("cls");//清屏保持整洁 fcs超级爱干净.jpg
printf("请输入1 2 3中一个来选择游戏难度\n");
printf("难度1为简单\n");
printf("难度2为普通\n");
printf("难度3为困难\n");
printf("请用【A】、【D】来改变字符下坠方向,\n按【W】暂停,按【S】继续和回到原方向\n");
scanf("%d", &t);
if (t == 1) {
system("cls");
printf("准备好了吗,要开始喽\n");
system("pause");
HideCursor(0);
system("cls");
HideCursor(0);
DrawRectangle(x1, x2, y1, y2);
GotoXY(x1 + 2, y2 - 1); //定位到坐标系的某个位置
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
do {
c = rand() % 26 + 'A';
d = x1 + rand() % 26 + 2;
for (i = y1 + 1; i < y2 - 1; i = i + 1) {
GotoXY(d, i);
printf("%c", c);
Sleep(1000);
GotoXY(d, i);
printf(" ");
if (kbhit())
ch = getch();
switch (ch) {
case 'w':
i = i - 1;
break;
case 'a':
if (d > x1 + 2)
d = d - 1;
break;
case 'd':
if (d < x2 - 1)
d = d + 1;
break;
}
}
if (d == x1 + c - 'A' + 2 && i == y2 - 1) {
score = score + 10;
GotoXY(x1, y2 + 3);
printf("得分 ");
printf("%d", score);
continue;
}
if (d != x1 + c - 'A' + 2 && i == y2 - 1) {
GotoXY(x1, y2 + 2);
printf("GAME OVER");
GotoXY(x1, y2 + 3);
printf("得分");
printf("%d", score);
exit(0);
}
} while (ch != 'o');
return 0;
}
if (t == 2) {
system("cls");
printf("相信你一定行!\n");
printf("准备好了吗,要开始喽\n");
system("pause");
HideCursor(0);
system("cls");
HideCursor(0);
DrawRectangle(x1, x2, y1, y2);
GotoXY(x1 + 2, y2 - 1);
if (kbhit())
ch = getch();
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
do {
c = rand() % 26 + 'A';
d = x1 + rand() % 26 + 2;
for (i = y1 + 1; i < y2 - 1; i = i + 1) {
GotoXY(d, i);
printf("%c", c);
Sleep(800);
GotoXY(d, i);
printf(" ");
if (kbhit())
ch = getch();
switch (ch) {
case 'w':
i = i - 1;
break;
case 's':
i = i;
break;
case 'a':
if (d > x1 + 2)
d = d - 1;
break;
case 'd':
if (d < x2 - 1)
d = d + 1;
break;
}
}
if (d == x1 + c - 'A' + 2 && i == y2 - 1) {
score = score + 10;
GotoXY(x1, y2 + 3);
printf("得分 ");
printf("%d", score);
continue;
}
if (d != x1 + c - 'A' + 2 && i == y2 - 1) {
GotoXY(x1, y2 + 2);
printf("就这?");
GotoXY(x1, y2 + 3);
printf("得分");
printf("%d", score);
exit(0);
}
} while (ch != 'o');
return 0;
}
if (t == 3) {
system("cls");
printf("要坚强要加油哦!\n");
printf("准备好了吗,要开始喽\n");
HideCursor(0);
system("pause");
system("cls");
HideCursor(0);
DrawRectangle(x1, x2, y1, y2);
GotoXY(x1 + 2, y2 - 1);
if (kbhit())
ch = getch();
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
do {
c = rand() % 26 + 'A';
d = x1 + rand() % 26 + 2;
for (i = y1 + 1; i < y2 - 1; i = i + 1) {
GotoXY(d, i);
printf("%c", c);
Sleep(400);
GotoXY(d, i);
printf(" ");
if (kbhit())
ch = getch();
switch (ch) {
case 'w':
i = i - 1;
break;
case 's':
i = i;
break;
case 'a':
if (d > x1 + 2)
d = d - 1;
break;
case 'd':
if (d < x2 - 1)
d = d + 1;
break;
}
}
if (d == x1 + c - 'A' + 2 && i == y2 - 1) {
score = score + 10;
GotoXY(x1, y2 + 3);
printf("得分");
printf("%d", score);
continue;
}
if (d != x1 + c - 'A' + 2 && i == y2 - 1) {
GotoXY(x1, y2 + 2);
printf("别气馁,下次再来");
GotoXY(x1, y2 + 3);
printf("得分");
printf("%d", score);
exit(0);
}
} while (ch != 'o');
return 0;
}
return 0;
}
偶遇到类似问题都是用
“每次用/.../注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。