项目: 打字母游戏【c++/c】
生活随笔
收集整理的這篇文章主要介紹了
项目: 打字母游戏【c++/c】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 效果圖
- 代碼
- 資源地址
效果圖
代碼
#include<stdio.h> #include<stdlib.h> #include<Windows.h> #include<graphics.h>//圖形圖函數 #include<time.h>//隨機函數種子 #include<conio.h>//按鍵操作庫 #include<MMSystem.h> #pragma comment(lib,"Winmm.lib") int main(void) {PlaySound(TEXT("sounds\\1.wav"),NULL,SND_FILENAME | SND_ASYNC| SND_LOOP);srand((unsigned int)time(NULL));initgraph(800,600);//打開圖形化界面char ch = ' ';char UserKey = ' ';int x=0;int i;while(1){x = rand()%501+200;ch = rand()%26+'A';for(int y=0;y<=600;y+=10){outtextxy(x,y,ch);//圖形化界面的輸出if(_kbhit())//_kbhit():有按鍵返回一個非零值,沒按鍵返回0。{UserKey=_getch();//暫停程序if(UserKey==' '){while(!_getch());//如果不是空格,就死循環達到暫停效果}if(UserKey == ch || UserKey-('a'-'A') == ch)//字母相匹配就清屏{cleardevice();//清屏break;}}Sleep(100);cleardevice();//清屏}}_getch();//防閃屏closegraph();return 0; }資源地址
鏈接:https://pan.baidu.com/s/1X3bIbXcQ19NTTYMGUNcUGw 提取碼:1234 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的项目: 打字母游戏【c++/c】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 项目: 推箱子游戏【c/c++】
- 下一篇: 项目: 打字母游戏图形化【C++ / C