打字游戏-第一个小项目
来源:互联网 发布:网站源码网 编辑:程序博客网 时间:2024/04/26 13:41
话不多说,直接上代码
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <windows.h>#include <time.h>int levels = 1, score = 0, lines = 0, num = 0, col = 0;void EnterSpace(int num){ for (int i=0;i<num;i++) { printf(" "); }}void EnterLine(int num){ for (int i = 0; i < num; i++) { printf("\r\n"); }}void EnterUnline(int num){ for (int i = 0; i < num; i++) { printf("_"); } EnterLine(1);}// 游戏的初始化--画出打字的简易界面void initialize(int score){ levels = score / 50; system("cls"); EnterSpace(35); printf("levels:%d\t ", levels); printf("\tscore:%d\n", score); EnterSpace(35); printf("1---Pause\t"); printf("\t0---Exit\r\n"); EnterUnline(100); //EnterLine(16); //EnterUnline(100);}// 处理按键int keydown(char c){ if (c == 'A' + num) { lines = 0; score += 10; return 1; } else if (c == '1') { getchar(); return 0; } else if (c == '0') { exit(0); return 0; }}void BeforeStart(){ EnterLine(15); EnterSpace(40); printf("press anykey to start"); getchar();}// 游戏结束void End(){ system("cls"); EnterLine(15); EnterSpace(40); printf("sorry,you faile!"); getch(); exit(0);}void Speed(int score){ if (score <= 50) Sleep(1000); else if (score <= 100) Sleep(500); else Sleep(200);}int main(){ BeforeStart(); srand(time(NULL)); while (true) { initialize(score); col = rand() % 100; num = rand() % 26; while (true) { lines++; if (lines > 15) { lines = 0; score -= 10; if (score < -50) { End(); } break; } EnterSpace(col); printf("%c", 'A'+num); Speed(score); printf("\b \n"); if (kbhit()) { char c = getch(); int book=keydown(c); if (book==1) break; } } } return 0;}
这是效果图
0 0
- 打字游戏-第一个小项目
- 第一个小项目
- 第一个小项目
- 第一个小项目
- 第一个小项目
- 第一个项目(游戏)
- tp5第一个小项目
- 第一个ssm小项目
- 打字游戏小编程(java)
- QuickHit(打字游戏)项目源代码
- 第一个android游戏项目eyesight总结
- 我的第一个小项目
- 小猴子的第一个项目感想
- 今天接到了第一个小项目
- 自己的第一个小项目
- 【Dubbo】第一个dubbo小项目
- 第一个Spring MVC小项目
- 一个小打字游戏java源码
- 图片路径L:While reading /Volumes/data2/project/ChildStory/ChildStory/nav_bar.png pngcrush caught libpng
- OSI参考模型
- Android开机启动流程
- <今年你不能错过的事>
- C++中类的构造函数
- 打字游戏-第一个小项目
- C++的函数重载
- Xcode运行出现:The Operation couldn't be completed.(LaunchServicesError error 0.)
- 数据库事物
- 第一次使用cmd调用python敲出i love acm
- java笔试总结
- Java网页数据抓取实例
- tinyxml2源码分析-3
- hive体系结构和hive作业形式