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

本文介绍如何利用Visual Studio集成开发环境和EasyX图形库,创建一款有趣的打字小游戏——天降字母。通过这个项目,你将学习到游戏编程基础以及结合打字练习的软件设计技巧。
摘要由CSDN通过智能技术生成
 
#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
#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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值