共有回帖数 0 个
- 感谢【VC绘图/游戏简易教程】,通过它我做出了一个记忆游戏
-
只看楼主
收藏
回复
-
/*请各位大虾多多指教,现学现卖,肯定不足,
我的Q:921919503*/
#include graphics.h
#include stdlib.h
#include conio.h
#include time.h
#include stdio.h
char s[2]=" ";
char a[100],c[100]; //有危险,待改进
int x,y,v,h,j,w;
int q=0,i=0;
int speech=200;
//欢迎界面
void welcome()
{
// 输出屏幕提示
for(int t=0;t640;t++)
{setcolor(RGB(t,t+10,t*10));
line(t,0,t,480);
}//画屏幕
setcolor(YELLOW);
setfont(64, 0, "黑体");
outtextxy(200, 60, "记忆游戏");
setcolor(WHITE);
setfont(20, 0, "宋体");
outtextxy(100, 200, "游戏规则:");
outtextxy(100, 240, "游戏运行后,屏幕随机出现字母");
outtextxy(100, 280, "玩者在记忆范围内按任意键随时停止");
outtextxy(100, 320, "按顺续输入刚才记忆的字母按回车键看结果");
setcolor(BLUE);
setlinestyle(PS_SOLID,0,5); //设置线型
for(j=40;j=610;j+=10) //画围墙
{
rectangle(j,40,j+10,49); //上边
rectangle(j,451,j+10,460); //下边
}
for(j=10;j=450;j+=10)
{
rectangle(50,i,59,j+10); //左边
rectangle(590,i,601,j+10); //右边
}
// 实现闪烁的“按任意键继续”
int c=255;
while(!kbhit())
{
setfont(30,0," ");
setcolor(RGB(c, 0, 0));
outtextxy(280, 400, "按任意键继续");
c-=8;
if (c0) c=255;
Sleep(20);
}
getch();
cleardevice();
}
void goodbye()
{
cleardevice();
for(int t=0;t320;t++)
{setcolor(RGB(t*20,t*10,0));
line(t,0,t,480);
int p=640;
p=p-t;
setcolor(RGB(t*20,t*10,0));
line(p,0,p,480);
Sleep(1);
}
setcolor(YELLOW);
setfont(48, 0, "黑体");
outtextxy(180, 200, " 游戏结束");
getch();
closegraph();
}
void show() //随机字母的函数
{
while(!kbhit())
{ cleardevice();
//继续画图
for(int m=0;m640;m++)
{
setcolor(RGB(0,m,0));
line(m,0,m,480);
}
s[0]=(rand()%26)+65;
a=s[0];
i++;
setcolor(WHITE);
setfont(20,0," ");
outtextxy(200,20,"按任意键停止记忆,开始测试");
x=rand()%580;
y=rand()%430;
setcolor(RGB(i*225,i*100,i*180));
circle(x+10,y+20,30);
setfont(50,0," ");
outtextxy(x,y,s);
Sleep(speech);
}
}
void check()
{
char str[10];
cleardevice();
getch();
for(int v=0;v480;v++)
{setcolor(RGB(v*1,v*2,v*3));
line(0,v,640,v);
}
bar3d(90,125,103,480,15,1);
bar3d(450,90,580,480,20,1);
for(int u=1;u18;u++)
{
bar3d(90+13*u,125+20*u,103+13*u,480,15,1);
}
setcolor(YELLOW);
setfont(30, 0, "宋体");
outtextxy(100, 30, "输入连续输入您刚才记忆的字母");
outtextxy(180, 70, "以ESC键结束");
setcolor(RED);
setfillstyle(YELLOW);
bar(400,65,600,100);
sprintf(str,"总个数:%d",i);
outtextxy(450,70,str);
w=0;
while(kbhit()!=27)
{ setcolor(RGB(w*100,w*225,w*180));
setfont(30, 0, "宋体");
c[w]=getch();
outtextxy(90, w*20+100, c); //
if(c[w]==a[w]||c[w]==a[w]+32)
outtextxy(450,w*20+100,"right!");
else
outtextxy(450,w*20+100,"not right!!!");
w=w+1;
if(w=i)
break;
}
getch();
}
void setspeech()
{
initgraph(640,480);
cleardevice();
for(int t=0;t480;t++)
{setcolor(RGB(0,t,0));
line(0,t,640,t);
}
setcolor(YELLOW);
setfont(40, 0, "黑体");
outtextxy(200, 60, "速度设置:");
setcolor(WHITE);
setfont(30, 0, "宋体");
outtextxy(100, 200, "A、慢速 三秒一个字母");
outtextxy(100, 240, "B、中速 二秒一个字母");
outtextxy(100, 280, "C、快速 一秒一个字母");
outtextxy(100, 320, "任意键默认值");
outtextxy(200, 360, "开始速度设置:_ _");
switch (getch())
{
case 'A':speech=3000;break;
case 'B':speech=2000;break;
case 'C':speech=1000;break;
case 'a':speech=3000;break;
case 'b':speech=2000;break;
case 'c':speech=1000;break;
default:speech=2000;
}
cleardevice();
}
void main()
{
srand(time(NULL));
initgraph(640,480);
welcome();
setspeech();
show(); //输出随机字母
check(); //检查随机字母
goodbye();
closegraph();
cleardevice();
}
楼主 2015-12-17 16:20 回复
Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
意见反馈 |
关于直线 |
版权声明 |
会员须知