?? 手機(jī)上的記憶力游戲.txt
字號:
//在tc3.0++在運行
//a數(shù)組用于隨機(jī)產(chǎn)生1-6數(shù)表示每個方格后面的圖形.用inita()函數(shù)來實現(xiàn)
//c數(shù)組用于記錄方格的狀態(tài),用字符L(lock)表示沒有打開的方格
//D(delete)表示已消去的方格.O(open)表示打開的方格.
//變量m表示按回車鍵的有效次數(shù).也是記憶力參數(shù),越小記憶力越好
//變量xpos,ypos用于表示當(dāng)前光標(biāo)所在的位置
//(x1,y1),(x2,y2)用于記錄打開的兩個方格的位置
//judge()函數(shù)用于控制光標(biāo)范圍,使其不能移出長方形
//win()函數(shù)用于判斷游戲是否過關(guān),通過判斷每個方格是否全是'D'狀態(tài)
//xago,yago 用于記錄移動前的位置
//ax,ay表示行列式的行與列,用它們來控制游戲的關(guān)數(shù),ax位于3-6之間,ay位于4-7之間
//z來控制方格后的圖形
//第一關(guān)后面的圖形用1-6代表的圖形.第二關(guān)后面的圖形用0-9十個數(shù)。第三關(guān)后面的圖形用A-O十五個字母,
//第四關(guān)后面的圖形用A-T二十一個字母
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#include<bios.h>
#define KEY_ENTER 0x1c0d
#define KEY_ESC 0x11b
#define KEY_UP 0x4800
#define KEY_DOWN 0x5000
#define KEY_F1 0x3b00
#define KEY_LEFT 0x4b00
#define KEY_RIGHT 0x4d00
#define KEY_P 0x1970
#define KEY_R 0x1372
char far *screen=(char far* )0xb8000000;
void putchxy(int y,int x,char ch,char fc,char bc)
{
screen[(x*160)+(y<<1)+0]=ch;
screen[(x*160)+(y<<1)+1]=(bc*16)+fc;
}
/*declare the functions*/
void help();
void inita();
void initpic();
int win();
void recover();
void initc();
int judge(int *,int *);
/*define the variables*/
int victory,xago,yago,xpos,ypos;
int ax=3,ay=4,z=0;
int c[6][7];
int a[6][7];
/*main function*/
void main()
{
int i,j,key,m=0,insure;
int x1,y1,x2,y2;
clrscr();
_AL=3;
_AH=0;
geninterrupt(0x10);
help();
getch();
clrscr();
initpic();
inita();
initc();
do{
key=bioskey(0);
xago=xpos;yago=ypos;
switch(key){
case KEY_UP: {
ypos--;
if(judge(&xpos,&ypos))
{ypos++;
continue;}
putchxy(xpos,ypos,177,YELLOW,BLACK);
recover();
break;
}
case KEY_DOWN: {
ypos++;
if(judge(&xpos,&ypos))
{ypos--;
continue;}
putchxy(xpos,ypos,177,YELLOW,BLACK);
recover();
break;
}
case KEY_LEFT: {
xpos--;
if(judge(&xpos,&ypos))
{xpos++;
continue;}
putchxy(xpos,ypos,177,YELLOW,BLACK);
recover();
break;
}
case KEY_RIGHT: {
xpos++;
if(judge(&xpos,&ypos))
{xpos--;
continue;}
putchxy(xpos,ypos,177,YELLOW,BLACK);
recover();
break;
}
case KEY_ENTER:{
if(c[ypos-10][xpos-30]=='O'||c[ypos-10][xpos-30]=='D') continue;
m++;
gotoxy(47,7);
printf("%d",m);
switch(m%2) /*0表示打開的方格數(shù)為2個,1表示打開的方格數(shù)為1個*/
{
case 1: {
x1=xpos;y1=ypos;
putchxy(x1,y1,a[y1-10][x1-30],YELLOW,BLACK);
c[y1-10][x1-30]='O';
break;
} /*把打開的第一個方格位置記錄下來*/
case 0: {
x2=xpos;y2=ypos; /*把打開的第二個方格位置記錄下來*/
putchxy(x2,y2,a[y2-10][x2-30],YELLOW,BLACK);
delay(500);
if(a[y1-10][x1-30]==a[y2-10][x2-30])/*判斷第一個方格與第二個方格后的圖形是否一樣*/
{
c[y1-10][x1-30]='D';
c[y2-10][x2-30]='D'; /*把要消去的方格的狀態(tài)改為'D'*/
putchxy(x2,y2,32,YELLOW,BLACK);
putchxy(x1,y1,32,YELLOW,BLACK);
}
else /*方格后的圖形不一樣.所以把打開的方格的狀態(tài)改為'L'*/
{
c[y1-10][x1-30]='L';
c[y2-10][x2-30]='L';
putchxy(x2,y2,219,YELLOW,BLACK);
putchxy(x1,y1,219,YELLOW,BLACK);
}
break;
}
}
break;
}
case KEY_P:
{
m=0;
ax++;ay++;
if(ax>6) {ax=3;ay=4;}
switch(ax)
{
case 3: z=0; break;
case 4: z=47;break;
case 5: z=64;break;
case 6: z=64;break;
}
clrscr();
initpic();
inita();
initc();
break;
}
case KEY_R:
{
m=0;
clrscr();
initpic();
inita();
initc();
break;
}
case KEY_F1:
{
clrscr();
help();
getch();
clrscr();
initpic();
inita();
initc();
break;
}
case KEY_ESC:
{
gotoxy(30,20);
cprintf("QUIT(Y/N)");
while(1)
{
insure=getch();
if(insure=='Y'||insure=='y') exit(1);
if(insure=='N'||insure=='n')
{
delline();
gotoxy(48,7);
break;
}
}
break;
}
}
victory=1; /*先假定游戲已經(jīng)結(jié)束*/
victory=win();
if(victory==0) continue;
else /*已過關(guān), 開始下一關(guān)*/
{ clrscr();
gotoxy(20,8);
printf("\n\t\t\tYOU HAVE PASSED THIS MISSION!\n");
printf("\n\t\t\twait for next mission........");
sleep(4);
clrscr();
m=0;
ax++;ay++;
if(ax>6) {ax=3;ay=4;}
switch(ax)
{
case 3: z=0; break;
case 4: z=47;break;
case 5: z=64;break;
case 6: z=64;break;
}
textcolor(random(6)+2);
initpic();
inita();
initc();
}
}while(1);
}
void initpic()
{
int i,j;
xpos=30;ypos=10;
for(j=10;j<10+ax;j++)
for(i=30;i<30+ay;i++)
putchxy(i,j,219,YELLOW,BLACK);
putchxy(30,10,177,YELLOW,BLACK);
gotoxy(23,7);
printf("the steps you used are: 0");
gotoxy(26,8);
printf("press F1 to get help");
gotoxy(30,9);
printf("MISSION:%d",ax-2);
}
void help()
{
randomize();
textcolor(random(6)+2);
char *p=
"\n\n\
\twelcome to play this game. there are four missons.\n\
\tpress 'left' 'right' 'up' and 'down' key to move the pane.\n\
\tpress the 'enter' key to open the pane. \n\
\t\tif the opened two panes are the same will be deleted.\n\
\tpress the 'r' key to restart the game.\n\
\tpress the 'p' key to pass the current misson and play the next misson.\n\
\tpress the 'esc' key to exit the game.\n\n\n\n\n\
\t\t\t\t****************\n\
\t\t\t\t***GOOD LUCK!***\n\
\t\t\t\t****************\n\
\n\n\n\n\
\t\t\t\t\t\t\tauthor: litigo\n\
\t\t\t\t\t\t\ttime: 9/23/2003\n\
\t\t\t\t\t\t\te-mail: litigo@sohu.com\n\
\t\t\t\t\t\t\toicq: 25317747";
while(*p++)
{
printf("%c",*p);
delay(30);
}
}
void inita()
{
int b[6][7]={0},x,y,i;
long int t;
srand(time(&t));
for(i=1;i<=ax*ay;i++)
{
do{
x=random(ax);
y=random(ay);
}while(b[x][y]==1);
if(i<=ax*ay/2) a[x][y]=i+z;
else a[x][y]=i-ax*ay/2+z;
b[x][y]=1;
}
}
void initc()
{
int i,j;
for(i=0;i<6;i++)
for(j=0;j<7;j++)
c[i][j]='L';
}
int judge(int *xp,int *yp)
{
if(*xp<30||*xp>(29+ay)||*yp<10||*yp>(9+ax)) return 1;
else return 0;
}
void recover()
{
switch(c[yago-10][xago-30])
{
case 'O':putchxy(xago,yago,a[yago-10][xago-30],YELLOW,BLACK);break;
case 'L':putchxy(xago,yago,219,YELLOW,BLACK);break;
case 'D':putchxy(xago,yago,32,YELLOW,BLACK);break;
}
}
int win()
{
int i,j;
for(i=0;i<ax;i++)
for(j=0;j<ay;j++)
if(c[i][j]!='D') victory=0; /*有一個沒有消去就認(rèn)為游戲沒有結(jié)束*/
return victory;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -