怎么使用c++编程实现简单的打字小游戏

发布时间:2021-10-15 17:24:58 作者:小新
来源:亿速云 阅读:228

这篇文章主要介绍怎么使用c++编程实现简单的打字小游戏,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

你是否对键盘熟悉?

“qwertyuiopasdfghjklzxcvbnm”是否已经印在你的脑海里?

NO?        

没有关系,今天,让我来帮你对键盘有一个更深一步的了解吧!

#include"stdio.h"
#include"stdlib.h"
#include"windows.h"
#include"conio.h"
void entry_place(int num)
{
 for(int i;i<num;i++)
 printf(" ");
}
void enter_line(int num)
{
 int i;
 for(i=0;i<num;i++)
 {
  printf("\n");
 }
}
int main()
{
 enter_line(15);
 entry_place(40);
 printf("press anykey to start");
 getchar();
 system("cls");
 int  levels=0,score=0,lines=0,num=0,col=0;
    while(1)
    {
     system("cls");
    for(int i=0;i<20;i++)
 {
  printf(" ");
 }
 printf("levels:%d",levels);
 entry_place(10);
 printf("score:%d",score);
    printf("\n");
 entry_place(20);
 printf("1---Pause");
 entry_place(9);
    printf("0---Exit");
    printf("\n");
 for(int i=0;i<80;i++)
 {
  printf("_");
 }
 enter_line(1);
 num=rand()%26;
 col=rand()%80;
 while(1)
 {
 lines++;
 if(lines>25)
 {
  lines=0;
  score-=10;
  if(score<-50)
  {
   system("cls");
   enter_line(15);
   entry_place(40);
   printf("sorry,you faile!");
   getch();
   exit(0);
  }
  break;
 }
 entry_place(col);
 printf("%c",'a'+num); 
 Sleep(180);
 printf("\b \n");
 
 if(kbhit())
 {
  char c=getch();
  if(c=='a'+num)
  {
   score+=10;
   break;
  }
 }
   }
   }
 return 0;
 }

以上是“怎么使用c++编程实现简单的打字小游戏”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. js实现打字小游戏的方法
  2. javascript实现简单打字游戏的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

c++

上一篇:Android如何实现简单计算器

下一篇:SpringBoot如何集成Redis

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》