打字小游戏(天降字母)Visual Studio+EasyX

 
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#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 <graphics.h>
#include <conio.h>
#include <time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#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();
}


 

  • 7
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include"head.h" void PlayMusic(const char* FileName) { char cmdString[50] = "open "; strcat_s(cmdString, FileName); strcat_s(cmdString, " alias bkmusic"); mciSendString(cmdString, NULL, 0, NULL); //打开音乐 mciSendString("play bkmusic repeat", NULL, NULL, NULL); //循环播放次音乐 } int main() { PlayMusic("111.mp3 ");//播放 initgraph(600,480); int Easy = 0, General = 0, Hard = 0, *EasyScore = &Easy;, *GeneralScore = &General;, *HardScore = &Hard; Enter_Interface(EasyScore,GeneralScore,HardScore); system("pause"); return 0; } //开始界面 void Enter_Interface(int*EasyScore, int*GeneralScore, int*HardScore) { char s[5]; cleardevice();//清屏 IMAGE bk; loadimage(&bk;,"sk1.jpg",600,480); putimage(0,0,&bk;); setbkmode(TRANSPARENT); int r = rand() % 256; int g = rand() % 256; int b = rand() % 256; settextstyle(48, 0, "楷体"); setcolor(RGB(r, g, b)); // outtextxy(125, 130, "按对应数字进入游戏"); setcolor(RED); settextstyle(64, 0, "新宋体"); BeginBatchDraw(); IMAGE bk; for(int y=0;y<40;y++) { putimage(0,0,&bk;); outtextxy(172, y, "字"); outtextxy(172+64, y, "母"); outtextxy(172+64+64, y, "游"); outtextxy(172+64+64+64, y, "戏"); FlushBatchDraw(); Sleep(50);//设置延时 } EndBatchDraw(); //outtextxy(172, 40, "字母游戏"); setcolor(WHITE); settextstyle(40, 0, "宋体"); outtextxy(125, 130, "按对应字母进入游戏"); settextstyle(30, 0, "宋体"); outtextxy(202, 194, "1、简单"); outtextxy(202, 283, "2、一般"); outtextxy(202, 372, "3、困难"); settextstyle(24, 0, "新宋体"); outtextxy(334, 259, "最高分:"); _itoa_s(*EasyScore, s, 10);//将整形数据转为字符串 outtextxy(440, 259, s); outtextxy(334, 348, "最高分:"); _itoa_s(*GeneralScore, s, 10); outtextxy(440, 348, s); outtextxy(334, 437, "最高分:"); _itoa_s(*HardScore, s, 10); outtextxy(440, 437, s); char choose;
要学习C#,你可以使用Visual Studio(VStudio)作为开发环境。VStudio是由微软提供的最佳C#开发环境,而且还是免费的。你可以从微软的官方网站上下载Visual Studio 2022 IDE。下载地址是:https://visualstudio.microsoft.com/zh-hans/vs/1.1 下载。安装完成后,你就可以开始使用VStudio来学习C#编程了。 在VStudio中,你可以创建C#项目,并且借助强大的编辑器和调试器进行代码编写、调试和运行。通过VStudio的集成开发环境(IDE),你可以编写C#程序,并将其编译为可独立运行的程序(.exe文件)或可被其他程序调用的库(.dll文件)。VStudio还提供了丰富的代码补全、调试工具和开发人员社区等功能,可以帮助你更高效地学习和开发C#程序。 通过VStudio学习C#,你可以参考一些入门教程和教学资源,比如《C#,入门教程(02)—— Visual Studio 2022开发环境搭建图文教程》这篇博文。这个教程可以帮助你了解如何在Visual Studio 2022中搭建C#开发环境,并给出了详细的步骤和图文说明。你可以按照这个教程的指导来配置和使用VStudio进行C#学习。 总的来说,VStudio是学习和开发C#的理想工具,它提供了强大的功能和友好的界面,可以帮助你更加便捷地进行C#编程。通过下载和安装Visual Studio 2022 IDE,你就可以开始学习C#并开发自己的应用程序了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [C#,入门教程(01)—— Visual Studio 2022 免费安装的详细图文与动画教程](https://blog.csdn.net/beijinghorn/article/details/123350910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值