使用c++編程實(shí)現(xiàn)簡(jiǎn)單的打字小游戲
你是否對(duì)鍵盤熟悉?
“qwertyuiopasdfghjklzxcvbnm”是否已經(jīng)印在你的腦海里?
NO?
沒(méi)有關(guān)系,今天,讓我來(lái)幫你對(duì)鍵盤有一個(gè)更深一步的了解吧!
#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;
}
這樣,不論你是什么人,你都會(huì)對(duì)鍵盤的了解更深刻。
ok了,今天的內(nèi)容就是這樣,我們下章再見(jiàn)!
更多關(guān)于c++實(shí)現(xiàn)小游戲的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C++使用chrono庫(kù)處理日期和時(shí)間的實(shí)現(xiàn)方法
C++11 中提供了日期和時(shí)間相關(guān)的庫(kù) chrono,通過(guò) chrono 庫(kù)可以很方便地處理日期和時(shí)間,本文主要介紹了C++使用chrono庫(kù)處理日期和時(shí)間的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2021-09-09
C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)之Hash散列表
這篇文章主要介紹了C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)之Hash散列表,散列表(哈希表)其思想主要是基于數(shù)組支持按照下標(biāo)隨機(jī)訪問(wèn)數(shù)據(jù),時(shí)間復(fù)雜度為O(1)的特性,可以說(shuō)是數(shù)組的一種拓展,需要的朋友可以參考下2023-08-08
C/C++ 動(dòng)態(tài)數(shù)組的創(chuàng)建的實(shí)例詳解
這篇文章主要介紹了C/C++ 動(dòng)態(tài)數(shù)組的創(chuàng)建的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家掌握這樣的功能,需要的朋友可以參考下2017-10-10
詳解C語(yǔ)言中的fopen()函數(shù)和fdopen()函數(shù)
這篇文章主要介紹了詳解C語(yǔ)言中的fopen()函數(shù)和fdopen()函數(shù),注意其之間指針功能相關(guān)的區(qū)別,需要的朋友可以參考下2015-08-08
C語(yǔ)言實(shí)現(xiàn)txt數(shù)據(jù)讀入內(nèi)存/CPU緩存實(shí)例詳解
這篇文章主要介紹了C語(yǔ)言實(shí)現(xiàn)txt數(shù)據(jù)讀入內(nèi)存/CPU緩存實(shí)例詳解的相關(guān)資料,這里對(duì)實(shí)現(xiàn)該函數(shù)進(jìn)行了代碼實(shí)現(xiàn),需要的朋友可以參考下2017-01-01

