前幾天剛學了點東西,所以就乘熱打鐵編了個小游戲,希望大家多多指教,你只要可以走到下面的小人那裡就可以了,可要快奧(不過我那個計時器根本沒派上用處,只不過是看看而已的)
#define WIN if(x==60&&y==20) break; /*勝利條件*/
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#include "conio.h"
#include "time.h"
main()
{int key,x,y,a,b,i,j,n=0;
int t;
clrscr();
textcolor(GREEN); /*圖象初始化*/
gotoxy(22,1);
cprintf("%c(UP) %c(DOWN) %c(LEFT) %c(RIGHT) ESC(QU99v)
",24,25,27,26);
textcolor(RED);
for(i=20;i<=60;i++)
{
for(j=4;j<=18;j+=2)
{
gotoxy(i,j);
cprintf("%c",219);
}
gotoxy(i,21);
cprintf("%c",219);
}
for(i=4;i<=21;i++)
{
gotoxy(19,i);
cprintf("%c",219);
gotoxy(61,i);
cprintf("%c",219);
gotoxy(62,i);
cprintf("%c",219);
gotoxy(18,i);
cprintf("%c",219);
}
textcolor(YELLOW);
gotoxy(20,5);
cprintf("1");
textcolor(12);
gotoxy(60,20);
cprintf("2");
gotoxy(20,5);
x=20;
y=5;
textcolor(YELLOW);
t=0;
gotoxy(37,2);
cprintf("TIME:"); /*圖象初始化結束*/
for(;;)
{
for(;!kbhit();) /*計時器*/
{
gotoxy(42,2);
if(t%500==0)
cprintf("%d",t/500);
t++;
delay(100);
} /*計時器結束*/
++n;
a=x;
b=y;
key=bioskey(0);
if(key==UP) /*判定按鍵*/
{
if(y==5)
continue;
gotoxy(x,--y);
WIN;
}
else if(key==DOWN)
{
if(y==20)
continue;
else if(y==5&&x!=60)
continue;
else if(y==7&&x!=50)
continue;
else if(y==9&&x!=40)
continue;
else if(y==11&&x!=30)
continue;
else if(y==13&&x!=20)
continue;
else if(y==15&&x!=25)
continue;
else if(y==17&&x!=55)
continue;
gotoxy(x,++y);
WIN;
}
else if(key==LEFT)
{
if(x==20)
continue;
gotoxy(--x,y);
WIN;
}
else if(key==RIGHT)
{
if(x==60)
continue;
gotoxy(++x,y);
WIN;
}
else if(key==0x11b)
exit(0);
else continue; /*判定結束*/
cprintf("1"); /*輸出圖形*/
gotoxy(a,b);
printf(" ");
gotoxy(x,y);
sound(300); /*輸出聲音*/
delay(1000);
nosound();
}
clrscr(); /*輸出結果*/
textcolor(12);
gotoxy(40,10);
cprintf("%c",2);
textcolor(RED);
gotoxy(22,11);
cprintf("After %d days, I will be your wife. %c",n,3);
getch();
}