WEB开发网
开发学院软件开发C++ 孔明棋,你玩过吗 阅读

孔明棋,你玩过吗

 2008-03-08 12:45:22 来源:WEB开发网   
核心提示://在tc3++下运行//游戏名孔明棋#define Up 0x4800#define Down 0x5000#define P 0x1970#define R 0x1372#define Enter 0x1c0d#define Esc 0x11b#define Right 0x4d00#define Le
//在tc3++下运行 //游戏名孔明棋 #define Up  0x4800
#define Down  0x5000
#define P   0x1970
#define R   0x1372
#define Enter  0x1c0d
#define Esc  0x11b
#define Right  0x4d00
#define Left  0x4b00 #include<bios.h>
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h> //定义核心数据
int LargeStartx,LargeStarty;  //大方格图形左上角坐标
int SmallStartx,SmallStarty;
int RedNum;  //红格子的个数。假如红格子的个数为1,则游戏过关
char State;  //按键的状态M(move)与S(select),M表示移动红格子。S表示选择要移动的红格子
int Attr[7][7];  //描述7*7矩阵格子的属性N(none),W(white),R(red).N表示没有格子,W表示有白色格子,R示           //有红色格子
int row,tier;   //7*7矩阵的行(row)与列(tier)
int Mission;   //表示第几关
int MissionNum;  //总的关数 typedef strUCt rect1  //描述大方格的属性
{
int startx;
int starty;
int nowx;
int nowy;
int agox;
int agoy;
char color;
int size;
}Large;
Large LargeRect; typedef struct rect2  //描述小方格的属性
{
int nowx;
int nowy;
char color;
int size;
}Small;
Small SmallRect; typedef struct add
{
int x;
int y;
}Add; //declare functions
void InitData1();
void InitData();
void InitMission(int );
void InitPic();
void Help();
void DrawSmallRect(int ,int ,int ,char );
void DrawLargeRect(int ,int ,int ,char );
void ChangeState();
void MoveLargeRect();
void MoveSmallRect(int ); void main()
{
int key;
int gdriver=DETECT, gmode;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver, &gmode, "");
setbkcolor(BLUE);
cleardevice();
InitData1(); 
InitData();   //随着关数的变化需要恢复的数据
Mission=1;
InitMission(Mission);  //初始化关数.主要是改变一些方格的属性
InitPic();
do
  {
  key=bioskey(0);
  LargeRect.agox=LargeRect.nowx;
  LargeRect.agoy=LargeRect.nowy;
  SmallRect.nowx=LargeRect.nowx+10;
  SmallRect.nowy=LargeRect.nowy+10;
  switch(key)
 {
 case Up:
   {
   if(State=='S')
     {
     if( (row-1)>=0&&Attr[row-1][tier]!='N' )
    {
    row--;
    MoveLargeRect();
    break;
    }
     }
   if(State=='M')
     {
     if(Attr[row-1][tier]=='R'&&Attr[row-2][tier]=='W')
    {
    MoveSmallRect(key);
    Attr[row][tier]='W';Attr[row-1][tier]='W';Attr[row-2][tier]='R';
    row-=2;
    MoveLargeRect();
    RedNum--;
    ChangeState();
    }
     }
   break;
   }
 case Down:
   {
   if(State=='S')
     {
     if( (row+1)<7&&Attr[row+1][tier]!='N' )
    {
    row++;
    MoveLargeRect();
    }
     }
   if(State=='M')
     {
     if(Attr[row+1][tier]=='R'&&Attr[row+2][tier]=='W')
    {
    MoveSmallRect(key);
    Attr[row][tier]='W';Attr[row+1][tier]='W';Attr[row+2][tier]='R';
    row+=2;
    MoveLargeRect();
    RedNum--;
    ChangeState();
    }
     }
   break;
   }
 case Left:
   {
   if(State=='S')
     {
     if( (tier-1)>=0&&Attr[row][tier-1]!='N' )
    {
    tier--;
    MoveLargeRect();
    }
     }
   if(State=='M')
     {
     if(Attr[row][tier-1]=='R'&&Attr[row][tier-2]=='W')
    {
    MoveSmallRect(key);
    Attr[row][tier]='W';Attr[row][tier-1]='W';Attr[row][tier-2]='R';
    tier-=2;
    MoveLargeRect();
    RedNum--;
    ChangeState();
    }
     }
   break;
   }
 case Right:
   {
   if(State=='S')
     {
     if( (tier+1)>=0&&Attr[row][tier+1]!='N' )
    {
    tier++;
    MoveLargeRect();
    }
     }
   if(State=='M')
     {
     if(Attr[row][tier+1]=='R'&&Attr[row][tier+2]=='W')
    {
    MoveSmallRect(key);
    Attr[row][tier]='W';Attr[row][tier+1]='W';Attr[row][tier+2]='R';
    tier+=2;
    MoveLargeRect();
    RedNum--;
    ChangeState();
    }
     }
   break;
   }
 case R:
   {
   InitData();
   InitMission(Mission);
   InitPic();
   break;
   }
 case P:
   {
   InitData();
   if(Mission<MissionNum)  Mission++;
   else Mission=1;
   InitMission(Mission);
   InitPic();
   break;
   }
 case Enter:
   {
   if(State=='S'&&Attr[row][tier]=='R')
     ChangeStat

Tags:孔明棋

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接