使用c++編程實(shí)現(xiàn)簡單的打字小游戲
你是否對鍵盤熟悉?
“qwertyuiopasdfghjklzxcvbnm”是否已經(jīng)印在你的腦海里?
NO?
沒有關(guān)系,今天,讓我來幫你對鍵盤有一個更深一步的了解吧!
#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;
}
這樣,不論你是什么人,你都會對鍵盤的了解更深刻。
ok了,今天的內(nèi)容就是這樣,我們下章再見!
更多關(guān)于c++實(shí)現(xiàn)小游戲的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
模擬鼠標(biāo)事件的實(shí)現(xiàn)思路及代碼
這篇文章主要介紹了模擬鼠標(biāo)事件的實(shí)現(xiàn)思路及代碼,有需要的朋友可以參考一下2013-12-12
C++?重載運(yùn)算符在HotSpot?VM中的應(yīng)用小結(jié)
C++支持運(yùn)算符重載,對于Java開發(fā)者來說,這個可能比較陌生一些,因?yàn)镴ava不支持運(yùn)算符重載,下面介紹一下HotSpot?VM中的運(yùn)算符重載,感興趣的朋友跟隨小編一起看看吧2023-09-09
C++設(shè)置超時時間的簡單實(shí)現(xiàn)方法
這篇文章主要介紹了C++設(shè)置超時時間的簡單實(shí)現(xiàn)方法,涉及系統(tǒng)函數(shù)setsockopt對套接口的操作,具有一定的實(shí)用價值,需要的朋友可以參考下2014-10-10
C語言實(shí)現(xiàn)點(diǎn)餐系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)點(diǎn)餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-11-11

