#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib,"WinMM.Lib")
// 欢迎界面
void welcome()
{
// 输出屏幕提示
cleardevice();
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\start.jpg", 1200, 800);
putimage(0, 0, &img);
setcolor(WHITE);
//setfont(16, 0, "宋体");
// 实现闪烁的“按任意键继续”
int c = 255;
TCHAR s[] = _T("黑体");
settextstyle(50, 0, s);
while (!kbhit())
{
setcolor(RGB(c, 0, 0));
TCHAR ax[] = _T("按任意键继续");
outtextxy(690, 630,ax);
c -= 8;
if (c < 0) c = 255;
Sleep(20);
}
getch();
cleardevice();
}
void regulation1()
{
cleardevice();
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\规则new.jpg", 1200, 800);
putimage(0,0,&img);
/* setcolor(WHITE);
TCHAR s[] = _T("黑体");
settextstyle(50, 0, s);
TCHAR ch[] = _T("游戏规则:");
outtextxy(110, 50, ch);
TCHAR ch1[] = _T("按Esc键退出");
outtextxy(110, 110, ch1);
TCHAR ch2[] = _T("字母掉落到红线则失去一条命");
outtextxy(110, 170, ch2);
TCHAR ch3[] = _T("玩家共有三条命,用尽则游戏结束");
outtextxy(110, 230, ch3); */
getch();
cleardevice();
}
// 退出界面
void goodbye(time_t end,time_t start,int flag)
{
time_t timep;
int i = end - start;
char a[10] = {'\0'};
TCHAR s[100] = {0};
char ff[10] = {0};
TCHAR fff[100] = { 0 };
cleardevice();
setcolor(RED);
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\GAMEOVER.jpg", 1200, 800);
putimage(0, 0, &img);
//setfont(48, 0, "黑体");
TCHAR style[] = _T("黑体");
settextstyle(40, 0, style);
TCHAR ch[] = _T("游戏时间:");
outtextxy(104, 180,ch);
TCHAR chf[] = _T("失败次数:");
outtextxy(854, 180,chf);
sprintf(a, "%d", i);
sprintf(ff, "%d", flag);
#ifdef UNICODE
MultiByteToWideChar(CP_ACP, 0, a, -1, s, 100);
#else
strcpy(a, s);
#endif
#ifdef UNICODE
MultiByteToWideChar(CP_ACP, 0, ff, -1, fff, 100);
#else
strcpy(ff, fff);
#endif
//s = (TCHAR*)a;
outtextxy(200, 220, s);
outtextxy(950, 220, fff);
getch();
}
//键盘
void keybroad()
{
int i,k,j,m;
char one[] = {'q','w','e','r','t','y','u','i','o','p'};
char two[] = {'a','s','d','f','g','h','j','k','l'};
char three[] = { 'z', 'x', 'c', 'v', 'b', 'n', 'm' };
char four[] = {'~','!','@','#','$','%','^','&','*','(',')','_','+'};
char five[] = {'`','1','2','3','4','5','6','7','8','9','0','-','='};
char oneend[] = { '{', '}', '|' }; //800 start
char oneend1[] = { '[', ']', '\\' };
char three1[] = {':','"'};
char three2[] = { ';','\'' };
char h1[] = {'','?'};
char h2[] = {',','.','/'};
setcolor(WHITE);
rectangle(220, 600, 290, 640); //Tab (220,600),(290,640)
line(220, 600, 220 - 3, 603);
line(220 - 3, 603, 220 - 3, 643);
line(220, 640, 220 - 3, 643);
line(290, 640, 293, 643);
line(220 - 3, 643, 293, 643);
line(290, 600, 293, 603);
line(293, 603, 293, 643);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
TCHAR tab[]= _T("Tab");
outtextxy(230, 610, tab);
rectangle(220, 650, 300, 690); //CapsLock (220,650),(300,690)
line(220, 650, 220 - 3, 653);
line(220 - 3, 653, 220 - 3, 693);
line(220, 690, 220 - 3, 693);
line(300, 690, 303, 693);
line(220 - 3, 693, 303, 693);
line(300, 650, 303, 653);
line(303, 653, 303, 693);
settextstyle(17, 0, ch);
TCHAR CapsLock[] = _T("CapsLock");
outtextxy(230, 660, CapsLock);
rectangle(870, 550, 940, 590); //Backspace (870,550),(940,590)
line(870, 550, 870 - 3, 553);
line(870 - 3, 553, 870 - 3, 593);
line(870, 590, 870 - 3, 593);
line(940, 590, 943, 593);
line(870 - 3, 593, 943, 593);
line(940, 550, 943, 553);
line(943, 553, 943, 593);
settextstyle(16, 0, ch);
TCHAR Backspace[] = _T("Backspace");
outtextxy(875, 560, Backspace);
rectangle(220, 700, 330, 740); //Shift (220,700),(330,740)
line(220, 700, 220 - 3, 703);
line(220 - 3, 703, 220 - 3, 743);
line(220, 740, 220 - 3, 743);
line(330, 740, 333, 743);
line(220 - 3, 743, 333, 743);
line(330, 700, 333, 703);
line(333, 703, 333, 743);
settextstyle(20, 0, ch);
TCHAR Shift[] = _T("Shift");
outtextxy(230, 710, Shift);
for (i = 220; i < 860; i = i + 50) // 键盘第零行13个键
{
rectangle(i, 550, i + 40, 590); //键盘第一个字母坐标(220,550),(260,590)
line(i, 550, i - 3, 553);
line(i - 3, 553, i - 3, 593);
line(i, 590, i - 3, 593);
line(i + 40, 590, i + 43, 593);
line(i - 3, 593, i + 43, 593);
line(i + 40, 550, i + 43, 553);
line(i + 43, 553, i + 43, 593);
settextstyle(10, 0, ch);
k = (i - 220) / 50;
outtextxy(i + 5, 555, four[k]);
settextstyle(16, 0, ch);
outtextxy(i + 20, 570, five[k]);
}
for (i = 300; i < 800;i=i+50) // 键盘第一行10个键
{
rectangle(i, 600, i+40, 640); //键盘第一个字母坐标(300,600),(340,640)
line(i, 600, i - 3, 603);
line(i - 3, 603, i - 3, 643);
line(i, 640, i - 3, 643);
line(i + 40, 640, i + 43, 643);
line(i - 3, 643, i + 43, 643);
line(i + 40, 600, i + 43, 603);
line(i + 43, 603, i + 43, 643);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (i - 300) / 50;
outtextxy(i + 10, 610, one[k]);
}
for (i = 800; i < 940; i = i + 50)
{
rectangle(i, 600, i + 40, 640); //键盘第一个字母坐标(800,600),(850,640)
line(i, 600, i - 3, 603);
line(i - 3, 603, i - 3, 643);
line(i, 640, i - 3, 643);
line(i + 40, 640, i + 43, 643);
line(i - 3, 643, i + 43, 643);
line(i + 40, 600, i + 43, 603);
line(i + 43, 603, i + 43, 643);
settextstyle(15, 0, ch);
k = (i - 800) / 50;
outtextxy(i + 5, 605, oneend[k]);
outtextxy(i + 20, 620, oneend1[k]);
}
for (j = 310; j < 760; j = j + 50)
{
rectangle(j, 650, j + 40, 690); //键盘第一个字母坐标(310,650),(350,690)
line(j, 650, j - 3, 653);
line(j - 3, 653, j - 3, 693);
line(j, 690, j - 3, 693);
line(j + 40, 690, j + 43, 693);
line(j - 3, 693, j + 43, 693);
line(j + 40, 650, j + 43, 653);
line(j + 43, 653, j + 43, 693);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (j - 310) / 50;
outtextxy(j + 10, 660, two[k]);
}
for (j = 760; j < 850; j = j + 50)
{ // 310,650 350,690
rectangle(j, 650, j + 40, 690); //键盘第一个字母坐标(760,650),(800,690)
line(j, 650, j - 3, 653);
line(j - 3, 653, j - 3, 693);
line(j, 690, j - 3, 693);
line(j + 40, 690, j + 43, 693);
line(j - 3, 693, j + 43, 693);
line(j + 40, 650, j + 43, 653);
line(j + 43, 653, j + 43, 693);
settextstyle(20, 0, ch);
k = (j - 760) / 50;
outtextxy(j + 7, 655, three1[k]);
outtextxy(j + 20, 669, three2[k]);
}
rectangle(860, 650, 940, 690); //Enter(860,650),(940,690)
line(860, 650, 860 - 3, 653);
line(860 - 3, 653, 860 - 3, 693);
line(860, 690, 860 - 3, 693);
line(940, 690, 943, 693);
line(860 - 3, 693, 943, 693);
line(940, 650, 943, 653);
line(943, 653, 943, 693);
settextstyle(20, 0, ch);
TCHAR Enter[] = _T("Enter");
settextstyle(20, 0, ch);
outtextxy( 870, 660, Enter);
for (m = 340; m < 690; m = m + 50)
{
rectangle(m, 700, m + 40, 740); //键盘第一个字母坐标(340,700),(380,740)
line(m, 700, m - 3, 703);
line(m - 3, 703, m - 3, 743);
line(m, 740, m - 3, 743);
line(m + 40, 740, m + 43, 743);
line(m - 3, 743, m + 43, 743);
line(m + 40, 700, m + 43, 703);
line(m + 43, 703, m + 43, 743);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (m - 310) / 50;
outtextxy(m + 10, 710, three[k]);
}
for (m = 690; m < 830; m = m + 50)
{
rectangle(m, 700, m + 40, 740); //(690,700),(830,740)
line(m, 700, m - 3, 703);
line(m - 3, 703, m - 3, 743);
line(m, 740, m - 3, 743);
line(m + 40, 740, m + 43, 743);
line(m - 3, 743, m + 43, 743);
line(m + 40, 700, m + 43, 703);
line(m + 43, 703, m + 43, 743);
settextstyle(20, 0, ch);
k = (m - 690) / 50;
outtextxy(m + 5, 706, h1[k]);
outtextxy(m + 23, 717, h2[k]);
}
rectangle(840, 700, 940, 740); // Shift(840,700),(940,740)
line(840, 700, 840 - 3, 703);
line(840 - 3, 703, 840 - 3, 743);
line(840, 740, 840 - 3, 743);
line(940, 740, 943, 743);
line(840 - 3, 743, 943, 743);
line(940, 700, 943, 703);
line(943, 703, 943, 743);
settextstyle(20, 0, ch);
outtextxy(850, 710, Shift);
}
//高亮
void highlight(char c)
{
int x, y;
if (c >= 'A'&&c <= 'Z')
c = c + 32;
if (c >= 'a'&&c <= 'z') //若为小写
{
switch (c)
{
case 'q':
x = 300; y = 600; break;
case 'w':
x = 350; y = 600; break;
case 'e':
x = 400; y = 600; break;
case 'r':
x = 450; y = 600; break;
case 't':
x = 500; y = 600; break;
case 'y':
x = 550; y = 600; break;
case 'u':
x = 600; y = 600; break;
case 'i':
x = 650; y = 600; break;
case 'o':
x = 700; y = 600; break;
case 'p':
x = 750; y = 600; break;
case 'a':
x = 310; y = 650; break;
case 's':
x = 360; y = 650; break;
case 'd':
x = 410; y = 650; break;
case 'f':
x = 460; y = 650; break;
case 'g':
x = 510; y = 650; break;
case 'h':
x = 560; y = 650; break;
case 'j':
x = 610; y = 650; break;
case 'k':
x = 660; y = 650; break;
case 'l':
x = 710; y = 650; break;
case 'z':
x = 340; y = 700; break;
case 'x':
x = 390; y = 700; break;
case 'c':
x = 440; y = 700; break;
case 'v':
x = 490; y = 700; break;
case 'b':
x = 540; y = 700; break;
case 'n':
x = 590; y = 700; break;
case 'm':
x = 640; y = 700; break;
}
fillrectangle(x, y, x + 40, y + 40);
Sleep(20);
clearrectangle(x, y, x + 40, y + 40);
}
}
// 主函数
void main()
{
initgraph(1200, 800); // 初始化屏幕为 1200x900
PlaySound(L"E:\\代码\\作业\\c语言作业\\photo\\Falcom Sound Team jdk - 星の在り処 Instrumental Ver.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
welcome(); // 显示欢迎界面
regulation1();
srand(time(NULL));// 设置随机种子
TCHAR ch[] = _T("Arial");
settextstyle(25,0, ch); // 设置字母的字体和大小
setfillstyle(BLACK); // 设置清除字母的填充区域颜色
char target; // 目标字母
char key; // 用户的按键
int x, y; // 字母的位置
keybroad();
time_t start, end;
setcolor(RED);
line(0, 475, 1200, 475);
int flag = 0;
int endgame = 0;
int wt, ht, wf, hf;
IMAGE imgt, imgf,*t,*f;
loadimage(&imgt,L"E:\\代码\\作业\\c语言作业\\photo\\true.jpg",300,400);
loadimage(&imgf, L"E:\\代码\\作业\\c语言作业\\photo\\false.jpg",300,400);
wt = imgt.getwidth();
ht = imgt.getheight();
wf = imgf.getwidth();
hf = imgf.getheight();
t = &imgt;
f = &imgf;
// 主循环
while (true)
{
target = 65 + rand() % 26; // 产生任意大写字母
x = rand() % 880; // 产生任意下落位置
start = time(NULL); //计时开始
for (y = 0; y<450; y++)
{
settextcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if (kbhit())
{
key = getch(); // 获取用户按键
highlight(key);
keybroad();
if ((key == target) || (key == target + 32))
{
// 按键正确,“击落”字母(擦除)
clearrectangle(x, y, x + 20, y + 25);
putimage(900, 0, &imgt);
break; // 跳出循环,进行下一个字母
}
else if (key == 27)
{
end = time(NULL);
goto EXIT; // 如果按 ESC,退出游戏主循环
}
else if ((key != target) && (key != target + 32))
{
flag = flag + 1;
putimage(900, 0, &imgf);
} //其他键错误
}
// 延时,并清除字母
Sleep(10);
clearrectangle(x, y, x + 20, y + 25);
}//for
if (y == 450) endgame++;
if (endgame == 3) { end = time(NULL); goto EXIT; }
}//while
EXIT:
// 退出部分
goodbye(end,start,flag);
// 关闭图形界面
closegraph();
}
#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib,"WinMM.Lib")
// 欢迎界面
void welcome()
{
// 输出屏幕提示
cleardevice();
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\start.jpg", 1200, 800);
putimage(0, 0, &img);
setcolor(WHITE);
//setfont(16, 0, "宋体");
// 实现闪烁的“按任意键继续”
int c = 255;
TCHAR s[] = _T("黑体");
settextstyle(50, 0, s);
while (!kbhit())
{
setcolor(RGB(c, 0, 0));
TCHAR ax[] = _T("按任意键继续");
outtextxy(690, 630,ax);
c -= 8;
if (c < 0) c = 255;
Sleep(20);
}
getch();
cleardevice();
}
void regulation1()
{
cleardevice();
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\规则new.jpg", 1200, 800);
putimage(0,0,&img);
/* setcolor(WHITE);
TCHAR s[] = _T("黑体");
settextstyle(50, 0, s);
TCHAR ch[] = _T("游戏规则:");
outtextxy(110, 50, ch);
TCHAR ch1[] = _T("按Esc键退出");
outtextxy(110, 110, ch1);
TCHAR ch2[] = _T("字母掉落到红线则失去一条命");
outtextxy(110, 170, ch2);
TCHAR ch3[] = _T("玩家共有三条命,用尽则游戏结束");
outtextxy(110, 230, ch3); */
getch();
cleardevice();
}
// 退出界面
void goodbye(time_t end,time_t start,int flag)
{
time_t timep;
int i = end - start;
char a[10] = {'\0'};
TCHAR s[100] = {0};
char ff[10] = {0};
TCHAR fff[100] = { 0 };
cleardevice();
setcolor(RED);
IMAGE img;
loadimage(&img, L"E:\\代码\\作业\\c语言作业\\photo\\GAMEOVER.jpg", 1200, 800);
putimage(0, 0, &img);
//setfont(48, 0, "黑体");
TCHAR style[] = _T("黑体");
settextstyle(40, 0, style);
TCHAR ch[] = _T("游戏时间:");
outtextxy(104, 180,ch);
TCHAR chf[] = _T("失败次数:");
outtextxy(854, 180,chf);
sprintf(a, "%d", i);
sprintf(ff, "%d", flag);
#ifdef UNICODE
MultiByteToWideChar(CP_ACP, 0, a, -1, s, 100);
#else
strcpy(a, s);
#endif
#ifdef UNICODE
MultiByteToWideChar(CP_ACP, 0, ff, -1, fff, 100);
#else
strcpy(ff, fff);
#endif
//s = (TCHAR*)a;
outtextxy(200, 220, s);
outtextxy(950, 220, fff);
getch();
}
//键盘
void keybroad()
{
int i,k,j,m;
char one[] = {'q','w','e','r','t','y','u','i','o','p'};
char two[] = {'a','s','d','f','g','h','j','k','l'};
char three[] = { 'z', 'x', 'c', 'v', 'b', 'n', 'm' };
char four[] = {'~','!','@','#','$','%','^','&','*','(',')','_','+'};
char five[] = {'`','1','2','3','4','5','6','7','8','9','0','-','='};
char oneend[] = { '{', '}', '|' }; //800 start
char oneend1[] = { '[', ']', '\\' };
char three1[] = {':','"'};
char three2[] = { ';','\'' };
char h1[] = {'','?'};
char h2[] = {',','.','/'};
setcolor(WHITE);
rectangle(220, 600, 290, 640); //Tab (220,600),(290,640)
line(220, 600, 220 - 3, 603);
line(220 - 3, 603, 220 - 3, 643);
line(220, 640, 220 - 3, 643);
line(290, 640, 293, 643);
line(220 - 3, 643, 293, 643);
line(290, 600, 293, 603);
line(293, 603, 293, 643);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
TCHAR tab[]= _T("Tab");
outtextxy(230, 610, tab);
rectangle(220, 650, 300, 690); //CapsLock (220,650),(300,690)
line(220, 650, 220 - 3, 653);
line(220 - 3, 653, 220 - 3, 693);
line(220, 690, 220 - 3, 693);
line(300, 690, 303, 693);
line(220 - 3, 693, 303, 693);
line(300, 650, 303, 653);
line(303, 653, 303, 693);
settextstyle(17, 0, ch);
TCHAR CapsLock[] = _T("CapsLock");
outtextxy(230, 660, CapsLock);
rectangle(870, 550, 940, 590); //Backspace (870,550),(940,590)
line(870, 550, 870 - 3, 553);
line(870 - 3, 553, 870 - 3, 593);
line(870, 590, 870 - 3, 593);
line(940, 590, 943, 593);
line(870 - 3, 593, 943, 593);
line(940, 550, 943, 553);
line(943, 553, 943, 593);
settextstyle(16, 0, ch);
TCHAR Backspace[] = _T("Backspace");
outtextxy(875, 560, Backspace);
rectangle(220, 700, 330, 740); //Shift (220,700),(330,740)
line(220, 700, 220 - 3, 703);
line(220 - 3, 703, 220 - 3, 743);
line(220, 740, 220 - 3, 743);
line(330, 740, 333, 743);
line(220 - 3, 743, 333, 743);
line(330, 700, 333, 703);
line(333, 703, 333, 743);
settextstyle(20, 0, ch);
TCHAR Shift[] = _T("Shift");
outtextxy(230, 710, Shift);
for (i = 220; i < 860; i = i + 50) // 键盘第零行13个键
{
rectangle(i, 550, i + 40, 590); //键盘第一个字母坐标(220,550),(260,590)
line(i, 550, i - 3, 553);
line(i - 3, 553, i - 3, 593);
line(i, 590, i - 3, 593);
line(i + 40, 590, i + 43, 593);
line(i - 3, 593, i + 43, 593);
line(i + 40, 550, i + 43, 553);
line(i + 43, 553, i + 43, 593);
settextstyle(10, 0, ch);
k = (i - 220) / 50;
outtextxy(i + 5, 555, four[k]);
settextstyle(16, 0, ch);
outtextxy(i + 20, 570, five[k]);
}
for (i = 300; i < 800;i=i+50) // 键盘第一行10个键
{
rectangle(i, 600, i+40, 640); //键盘第一个字母坐标(300,600),(340,640)
line(i, 600, i - 3, 603);
line(i - 3, 603, i - 3, 643);
line(i, 640, i - 3, 643);
line(i + 40, 640, i + 43, 643);
line(i - 3, 643, i + 43, 643);
line(i + 40, 600, i + 43, 603);
line(i + 43, 603, i + 43, 643);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (i - 300) / 50;
outtextxy(i + 10, 610, one[k]);
}
for (i = 800; i < 940; i = i + 50)
{
rectangle(i, 600, i + 40, 640); //键盘第一个字母坐标(800,600),(850,640)
line(i, 600, i - 3, 603);
line(i - 3, 603, i - 3, 643);
line(i, 640, i - 3, 643);
line(i + 40, 640, i + 43, 643);
line(i - 3, 643, i + 43, 643);
line(i + 40, 600, i + 43, 603);
line(i + 43, 603, i + 43, 643);
settextstyle(15, 0, ch);
k = (i - 800) / 50;
outtextxy(i + 5, 605, oneend[k]);
outtextxy(i + 20, 620, oneend1[k]);
}
for (j = 310; j < 760; j = j + 50)
{
rectangle(j, 650, j + 40, 690); //键盘第一个字母坐标(310,650),(350,690)
line(j, 650, j - 3, 653);
line(j - 3, 653, j - 3, 693);
line(j, 690, j - 3, 693);
line(j + 40, 690, j + 43, 693);
line(j - 3, 693, j + 43, 693);
line(j + 40, 650, j + 43, 653);
line(j + 43, 653, j + 43, 693);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (j - 310) / 50;
outtextxy(j + 10, 660, two[k]);
}
for (j = 760; j < 850; j = j + 50)
{ // 310,650 350,690
rectangle(j, 650, j + 40, 690); //键盘第一个字母坐标(760,650),(800,690)
line(j, 650, j - 3, 653);
line(j - 3, 653, j - 3, 693);
line(j, 690, j - 3, 693);
line(j + 40, 690, j + 43, 693);
line(j - 3, 693, j + 43, 693);
line(j + 40, 650, j + 43, 653);
line(j + 43, 653, j + 43, 693);
settextstyle(20, 0, ch);
k = (j - 760) / 50;
outtextxy(j + 7, 655, three1[k]);
outtextxy(j + 20, 669, three2[k]);
}
rectangle(860, 650, 940, 690); //Enter(860,650),(940,690)
line(860, 650, 860 - 3, 653);
line(860 - 3, 653, 860 - 3, 693);
line(860, 690, 860 - 3, 693);
line(940, 690, 943, 693);
line(860 - 3, 693, 943, 693);
line(940, 650, 943, 653);
line(943, 653, 943, 693);
settextstyle(20, 0, ch);
TCHAR Enter[] = _T("Enter");
settextstyle(20, 0, ch);
outtextxy( 870, 660, Enter);
for (m = 340; m < 690; m = m + 50)
{
rectangle(m, 700, m + 40, 740); //键盘第一个字母坐标(340,700),(380,740)
line(m, 700, m - 3, 703);
line(m - 3, 703, m - 3, 743);
line(m, 740, m - 3, 743);
line(m + 40, 740, m + 43, 743);
line(m - 3, 743, m + 43, 743);
line(m + 40, 700, m + 43, 703);
line(m + 43, 703, m + 43, 743);
TCHAR ch[] = _T("Arial");
settextstyle(20, 0, ch);
k = (m - 310) / 50;
outtextxy(m + 10, 710, three[k]);
}
for (m = 690; m < 830; m = m + 50)
{
rectangle(m, 700, m + 40, 740); //(690,700),(830,740)
line(m, 700, m - 3, 703);
line(m - 3, 703, m - 3, 743);
line(m, 740, m - 3, 743);
line(m + 40, 740, m + 43, 743);
line(m - 3, 743, m + 43, 743);
line(m + 40, 700, m + 43, 703);
line(m + 43, 703, m + 43, 743);
settextstyle(20, 0, ch);
k = (m - 690) / 50;
outtextxy(m + 5, 706, h1[k]);
outtextxy(m + 23, 717, h2[k]);
}
rectangle(840, 700, 940, 740); // Shift(840,700),(940,740)
line(840, 700, 840 - 3, 703);
line(840 - 3, 703, 840 - 3, 743);
line(840, 740, 840 - 3, 743);
line(940, 740, 943, 743);
line(840 - 3, 743, 943, 743);
line(940, 700, 943, 703);
line(943, 703, 943, 743);
settextstyle(20, 0, ch);
outtextxy(850, 710, Shift);
}
//高亮
void highlight(char c)
{
int x, y;
if (c >= 'A'&&c <= 'Z')
c = c + 32;
if (c >= 'a'&&c <= 'z') //若为小写
{
switch (c)
{
case 'q':
x = 300; y = 600; break;
case 'w':
x = 350; y = 600; break;
case 'e':
x = 400; y = 600; break;
case 'r':
x = 450; y = 600; break;
case 't':
x = 500; y = 600; break;
case 'y':
x = 550; y = 600; break;
case 'u':
x = 600; y = 600; break;
case 'i':
x = 650; y = 600; break;
case 'o':
x = 700; y = 600; break;
case 'p':
x = 750; y = 600; break;
case 'a':
x = 310; y = 650; break;
case 's':
x = 360; y = 650; break;
case 'd':
x = 410; y = 650; break;
case 'f':
x = 460; y = 650; break;
case 'g':
x = 510; y = 650; break;
case 'h':
x = 560; y = 650; break;
case 'j':
x = 610; y = 650; break;
case 'k':
x = 660; y = 650; break;
case 'l':
x = 710; y = 650; break;
case 'z':
x = 340; y = 700; break;
case 'x':
x = 390; y = 700; break;
case 'c':
x = 440; y = 700; break;
case 'v':
x = 490; y = 700; break;
case 'b':
x = 540; y = 700; break;
case 'n':
x = 590; y = 700; break;
case 'm':
x = 640; y = 700; break;
}
fillrectangle(x, y, x + 40, y + 40);
Sleep(20);
clearrectangle(x, y, x + 40, y + 40);
}
}
// 主函数
void main()
{
initgraph(1200, 800); // 初始化屏幕为 1200x900
PlaySound(L"E:\\代码\\作业\\c语言作业\\photo\\Falcom Sound Team jdk - 星の在り処 Instrumental Ver.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
welcome(); // 显示欢迎界面
regulation1();
srand(time(NULL));// 设置随机种子
TCHAR ch[] = _T("Arial");
settextstyle(25,0, ch); // 设置字母的字体和大小
setfillstyle(BLACK); // 设置清除字母的填充区域颜色
char target; // 目标字母
char key; // 用户的按键
int x, y; // 字母的位置
keybroad();
time_t start, end;
setcolor(RED);
line(0, 475, 1200, 475);
int flag = 0;
int endgame = 0;
int wt, ht, wf, hf;
IMAGE imgt, imgf,*t,*f;
loadimage(&imgt,L"E:\\代码\\作业\\c语言作业\\photo\\true.jpg",300,400);
loadimage(&imgf, L"E:\\代码\\作业\\c语言作业\\photo\\false.jpg",300,400);
wt = imgt.getwidth();
ht = imgt.getheight();
wf = imgf.getwidth();
hf = imgf.getheight();
t = &imgt;
f = &imgf;
// 主循环
while (true)
{
target = 65 + rand() % 26; // 产生任意大写字母
x = rand() % 880; // 产生任意下落位置
start = time(NULL); //计时开始
for (y = 0; y<450; y++)
{
settextcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if (kbhit())
{
key = getch(); // 获取用户按键
highlight(key);
keybroad();
if ((key == target) || (key == target + 32))
{
// 按键正确,“击落”字母(擦除)
clearrectangle(x, y, x + 20, y + 25);
putimage(900, 0, &imgt);
break; // 跳出循环,进行下一个字母
}
else if (key == 27)
{
end = time(NULL);
goto EXIT; // 如果按 ESC,退出游戏主循环
}
else if ((key != target) && (key != target + 32))
{
flag = flag + 1;
putimage(900, 0, &imgf);
} //其他键错误
}
// 延时,并清除字母
Sleep(10);
clearrectangle(x, y, x + 20, y + 25);
}//for
if (y == 450) endgame++;
if (endgame == 3) { end = time(NULL); goto EXIT; }
}//while
EXIT:
// 退出部分
goodbye(end,start,flag);
// 关闭图形界面
closegraph();
}