#include <graphics.h>
#include <conio.h>
#include <time.h>// 歡迎界面
#include <iostream>
#include <thread>
using namespace std;
void welcome()
{
// 輸出螢屏提示
cleardevice();
setcolor(YELLOW);
setfont(50, 0, "黑體");
outtextxy(160, 10, "打字母游戲");
// 實作閃爍的“按任意鍵繼續”
int c=255;
while(!kbhit())
{
setcolor(RGB(c, 0, 0));
outtextxy(280, 400, "游戲開始"); c-=8;
if (c<0) c=255;
Sleep(20);
}
getch();
cleardevice();
}// 退出界面
void goodbye()
{
int s;
cleardevice();
setcolor(YELLOW);
setfont(48, 0, "黑體");
outtextxy(110, 150, "最終成績是:");
outtextxy(110, 250, s);
getch();
}
void time()
{
int a,b;
for(a=1;a!=61;a++)
{
char q[5];
sprintf(q,"%d",b-a);
outtextxy(20,20,q);
Sleep(1000);
if(b-a==0)
{
goto EXIT;
}
}
}// 主函式
void program()
{
int s;
char target[2] = "s"; // 定義字母字串
char key; // 定義用戶按鍵變數
srand(time(NULL)); // 設定隨機種子
setfont(50, 0, "Arial"); // 設定字母的字體和大小
outtextxy(380,20,"分數:");
outtextxy(550,20,s); // 主回圈
while(true)
{
target[0] = 65 + rand() % 26; // 產生任意大寫字母
int x = rand()%630;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 設定字母的顏色
outtextxy(x, y, target); // 顯示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
// 設定清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
/// int i++;
break; // 跳出回圈,進行下一個字符
}
else if (key == 27)
{ goto EXIT; // 如果按ESC,退出游戲主回圈
} int a;
// sprintf(i, "%d", a);
/// outtextxy(520,20,i);
}
// 延時,并清除原字符
Sleep(10);
setcolor(BLACK);
outtextxy(x, y, target);
}
}
}
int main()
{
// 初始化螢屏為640x480
initgraph(640, 480);
welcome(); // 顯示歡迎界面
std::thread first (time);
std::thread second (program);
first.join();
second.join();
EXIT: goodbye(); // 退出部分
// 關閉圖形界面
closegraph();
}
uj5u.com熱心網友回復:
TC實在是太老了。我win7都裝不上去了。
可以學VC6.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/97260.html
標籤:基礎類
