⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapedit.c

📁 一个C做的蛇蛇游戏阿
💻 C
字号:
/******************************************/
/*        mapedit.c of goldenbugs         */
/*                                        */
/*            to edit the map             */
/*                                        */
/*           Cat Tom 3.28.2003            */
/******************************************/


#include <stdio.h>
#include <graphics.h>


#define UP    18432
#define DOWN  20480
#define LEFT  19200
#define RIGHT 19712
#define ESC   283
#define ENTER 7181


char Map[39][27];


void drawwindow(int xx1,int yy1,int xx2,int yy2,int mode)
{
 switch(mode)
 {
    case 0:setcolor(LIGHTGRAY);
           line(xx2+1,yy1-1,xx2+1,yy2+1);
           line(xx1-1,yy2+1,xx2,yy2+1);
           setcolor(WHITE);
           line(xx2+2,yy1-2,xx2+2,yy2+2);
           line(xx1-2,yy2+2,xx2+1,yy2+2);
           setcolor(BLACK);
           line(xx1-1,yy1-1,xx1-1,yy2);
           line(xx1,yy1-1,xx2,yy1-1);
           setcolor(DARKGRAY);
           line(xx1-2,yy1-2,xx1-2,yy2+1);
           line(xx1-1,yy1-2,xx2+1,yy1-2);
           break;
    case 1:setcolor(BLACK);
           line(xx1,yy2,xx2-1,yy2);
           line(xx2,yy1,xx2,yy2);
           setcolor(DARKGRAY);
           line(xx1+1,yy2-1,xx2-2,yy2-1);
           line(xx2-1,yy1+1,xx2-1,yy2-1);
           setcolor(LIGHTGRAY);
           line(xx1,yy1,xx1,yy2-1);
           line(xx1+1,yy1,xx2-1,yy1);
           setcolor(WHITE);
           line(xx1+1,yy1+1,xx1+1,yy2-2);
           line(xx1+2,yy1+1,xx2-2,yy1+1);
           break;
    default:closegraph();printf("draw window error!\n");exit(0);
 }
}

void refreash(int xx,int yy)
{
 static int tempx=1,tempy=1;
 setcolor(GREEN);
 rectangle(27+15*tempx,24+15*tempy,42+15*tempx,39+15*tempy);
 setcolor(YELLOW);
 rectangle(27+15*xx,24+15*yy,42+15*xx,39+15*yy);
 tempx=xx;
 tempy=yy;
}

void chgmap(int xx,int yy)
{
 switch(Map[xx][yy])
 {
  case 0:Map[xx][yy]=1;
         setfillstyle(1,LIGHTGRAY);
         bar(28+15*xx,25+15*yy,41+15*xx,38+15*yy);
         drawwindow(28+15*xx,25+15*yy,41+15*xx,38+15*yy,1);
         break;
  case 1:Map[xx][yy]=3;
         setfillstyle(9,BLUE);
         bar(28+15*xx,25+15*yy,41+15*xx,38+15*yy);
         break;
  case 3:Map[xx][yy]=0;
         setfillstyle(1,BLACK);
         bar(28+15*xx,25+15*yy,41+15*xx,38+15*yy);
  default:;
 }
}

void mapedit()
{
 int i,j,key,xx=1,yy=1;

 for(i=0;i<39;i++)
   {
    Map[i][0]=1;
    Map[i][26]=1;
   }
 for(i=1;i<26;i++)
   {
    Map[0][i]=1;
    Map[38][i]=1;
   }

 setcolor(GREEN);
 rectangle(42,39,597,414);
 for(i=1;i<=24;i++)
   line(43,39+15*i,596,39+15*i);
 for(i=1;i<=36;i++)
   line(42+15*i,40,42+15*i,413);

 while(key!=ESC)
 {
  if(xx>37)xx=1;
  if(xx<1)xx=37;
  if(yy>25)yy=1;
  if(yy<1)yy=25;
  refreash(xx,yy);

  key=bioskey(0);
  switch(key)
  {
   case UP:yy--;break;
   case DOWN:yy++;break;
   case LEFT:xx--;break;
   case RIGHT:xx++;break;
   case ENTER:chgmap(xx,yy);break;
   default:;
  }
 }

}

void mapsave()
{
 char str[10];
 FILE *fp;
 char speed;
 int max_body_len;
 printf("Input the Max_body_len:");
 scanf("%d",&max_body_len);
 printf("Enter the filename(*.map):");
 scanf("%s",str);
 if((fp=fopen(str,"wb"))==NULL)
 {
  printf("map file open error!!!\n");
  exit(0);
 }

 fwrite(Map,1,1053,fp);
 fwrite(&max_body_len,sizeof(int),1,fp);
 fclose(fp);
}


main()
{
 int gd=VGA,gm=VGAHI;
 initgraph(&gd,&gm,"");
 mapedit();
 closegraph();
 mapsave();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -