#include#include #include #include #include #include #define WIRD 50 #define HIGH 25 struct Word{ int x; int y; char ch; bool flag; }; int count = 0; //分数 void gotoxy(int x, int y); void graph(void); //初始地图 void gamestart(void); //开始游戏 void inword(struct Word *pw, int n); //初始化字符数据 int main(void) { srand((unsigned int)time(0)); graph(); // 地图 gamestart(); //开始 ,按掉了的字符正确输入,不分大小写; getch(); gotoxy(0,0); printf("游戏得分%d,拜拜",count); return 0; } void inword(struct Word *pw, int n) { int i, m; pw[0].ch = rand()%26 + 'A'; //随机26个大写字母 pw[0].x = rand()%WIRD +10; //随机出现的位置 pw[0].y = rand()%HIGH; //随机高度 if(pw[0].y > 19) pw[0].y = 19; pw[0].flag = true; for(i=1;i 19) pw[i].y = 19; pw[i].flag = true; for(m=0;m 19) word[i].y = 19; for(m=0;m<3;++m) // 防止出现重复的字符 { if(word[m].flag && (word[i].ch == word[m].ch || word[i].x == word[m].x)) { word[i].ch = rand()%26 + 'A'; word[i].x = rand()%WIRD +10; word[i].y = rand()%HIGH; if(word[i].y > 19) word[i].y = 19; m = -1; } } y = word[0].y; for(m=1;m<3;++m) //找到离底线最近的坐标 { if(y < word[m].y) y = word[m].y; } y--; break; } } if(i == 3) //如果有正确输入 ,i 不会等于 3 { gotoxy((WIRD+10)/2,HIGH/2); printf("按错字母,游戏结束n"); return; } } } if(y > HIGH) //超过高度结束 { gotoxy((WIRD+10)/2,HIGH/2); printf("超出底线,游戏结束n"); return; } } } void graph(void) { int x; for(x = 10; x <=WIRD+10; x+=2) //打印一条线 { gotoxy(x,HIGH); printf("_"); } } void gotoxy(int x, int y) { COORD pos = {x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄 SetConsoleCursorPosition(hOut, pos);//两个参数分别是指定哪个窗体,具体位置 }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)