C语言 扫雷

作者在 2008-01-31 09:17:53 发布以下内容

/*********************************
作者:HungryAnt
姓名:孙麟
E-mail:ljsunlin@126.com
QQ:517377100
blog:http://hi.baidu.com/zhongji/blog
*********************************/

 

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

int m_poly[8]={0,0,5,7,0,9,0,0};/*鼠标*/
int m_now_poly[8]={0,0,5,7,0,9,0,0};
int re[10][6];/*储存鼠标经过前的像素颜色*/
int m_s[93-40+1][52-2+1];

int n1=-1,n2=-1;
int hard=1;/*0:易 1:中 2: 难*/
int count=40;/*地雷数量*/
int mx=16,my=16;/*地图宽高*/
char map[16][30];/*0位存放是否有地雷,1有0无,1位存放是否打开,1打开0没有打开,2位表示是否插旗,1有0无*/
int ha_x=320-120,ha_y=240-100;/*游戏栏*/
int dead=0;/*1:死亡 2:生*/
int score=0;

void menu_window();

char sao16S[]={
/* 以下是 '扫' 的 16点阵宋体 字模,32 byte */
  0x10,0x00,0x10,0x00,0x11,0xFC,0x10,0x04,
  0xFE,0x04,0x10,0x04,0x14,0x04,0x18,0xFC,
  0x30,0x04,0xD0,0x04,0x10,0x04,0x10,0x04,
  0x11,0xFC,0x50,0x00,0x20,0x00,0x00,0x00,
};

char lei16S[]={
    /* 以下是 '雷' 的 16点阵宋体 字模,32 byte */
    0x1F,0xF8,0x01,0x00,0x7F,0xFE,0x41,0x04,
    0x1D,0x70,0x01,0x00,0x1D,0x70,0x01,0x00,
    0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
    0x21,0x08,0x21,0x08,0x3F,0xF8,0x20,0x08,
};

char you12S[]={
/* 以下是 '游' 的 12点阵宋体 字模,24 byte */
  0x91,0x00,0x49,0xE0,0x3E,0x00,0x93,0xE0,
  0x5C,0x40,0x54,0x80,0x55,0xE0,0x94,0x80,
  0x94,0x80,0xA4,0x80,0x4D,0x80,0x00,0x00,
};

char xi12S[]={
/* 以下是 '戏' 的 12点阵宋体 字模,24 byte */
  0x02,0x80,0xF2,0x40,0x12,0x40,0x13,0xE0,
  0x9E,0x00,0x52,0x40,0x22,0x80,0x31,0x00,
  0x49,0x20,0x42,0xA0,0x8C,0x60,0x00,0x00,
};

char kai12S[]={
/* 以下是 '开' 的 12点阵宋体 字模,24 byte */
  0x00,0x40,0x7F,0xE0,0x11,0x00,0x11,0x00,
  0x11,0x00,0xFF,0xE0,0x11,0x00,0x11,0x00,
  0x11,0x00,0x21,0x00,0xC1,0x00,0x00,0x00,
};

char ju12S[]={
/* 以下是 '局' 的 12点阵宋体 字模,24 byte */
  0x3F,0xC0,0x20,0x40,0x3F,0xC0,0x20,0x00,
  0x3F,0xE0,0x20,0x20,0x2F,0x20,0x29,0x20,
  0x4F,0x20,0x49,0x20,0x80,0xC0,0x00,0x00,
};

char tui12S[]={
/* 以下是 '退' 的 12点阵宋体 字模,24 byte */
  0x8F,0xC0,0x48,0x40,0x4F,0xC0,0x08,0x40,
  0xCF,0xC0,0x48,0x00,0x4B,0x40,0x48,0x80,
  0x4E,0x40,0xB0,0x00,0x8F,0xE0,0x00,0x00,
};

char chu12S[]={
/* 以下是 '出' 的 12点阵宋体 字模,24 byte */
  0x04,0x00,0x44,0x40,0x44,0x40,0x44,0x40,
  0x7F,0xC0,0x04,0x00,0x44,0x40,0x44,0x40,
  0x44,0x40,0x44,0x40,0x7F,0xC0,0x00,0x00,
};

char nan12S[]={
/* 以下是 '难' 的 12点阵宋体 字模,24 byte */
  0x02,0x80,0x02,0x80,0xF7,0xE0,0x14,0x80,
  0x9F,0xE0,0x54,0x80,0x24,0x80,0x27,0xE0,
  0x54,0x80,0x94,0x80,0x07,0xE0,0x00,0x00,
};

char du12S[]={
/* 以下是 '度' 的 12点阵宋体 字模,24 byte */
  0x02,0x00,0x7F,0xE0,0x48,0x80,0x7F,0xE0,
  0x48,0x80,0x4F,0x80,0x40,0x00,0x5F,0x80,
  0x45,0x00,0x87,0x00,0xB8,0xE0,0x00,0x00,
};

char yi12S[]={
/* 以下是 '易' 的 12点阵宋体 字模,24 byte */
  0x3F,0x80,0x20,0x80,0x3F,0x80,0x20,0x80,
  0x3F,0x80,0x10,0x00,0x3F,0xC0,0xC9,0x40,
  0x12,0x40,0x64,0x40,0x19,0x80,0x00,0x00,
};

char zhong12S[]={
/* 以下是 '中' 的 12点阵宋体 字模,24 byte */
  0x04,0x00,0x04,0x00,0x7F,0xC0,0x44,0x40,
  0x44,0x40,0x44,0x40,0x7F,0xC0,0x04,0x00,
  0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00,
};

void drawmat(char *mat,int matsize,int x,int y,int color){/*点阵字显示函数*/
    int i,j,k,n;
    n=(matsize-1)/8+1;/*有几个字符位*/
    for(j=0;j<matsize;j++)/*行*/
        for(i=0;i<n;i++)
            for(k=0;k<8;k++)
                if(mat[j*n+i]&0x80>>k)
                    putpixel(x+i*8+k,y+j,color);
}

void game_over(){
    int x,y;

    setcolor(BLACK);
    for(y=0;y<my;y++)
        for(x=0;x<mx;x++)
            if(map[y][x]&1){
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10+8);

                circle(ha_x+2+x*10+4,ha_y+2+y*10+4,3);/*地雷图*/
                setfillstyle(SOLID_FILL,BLACK);
                floodfill(ha_x+2+x*10+4,ha_y+2+y*10+4,BLACK);/*黑色填充*/
            }
}

void win(){
    setviewport(0,0,639,479,0);
    settextstyle(0,0,3);
    setcolor(WHITE);
    outtextxy(216,211,"you win!!!");/****************显示you win****************/
    setcolor(GREEN);
    outtextxy(215,210,"you win!!!");/****************显示you win****************/
}

void box_open(int x,int y,int control){/*方格被打开,control用于判断是否是鼠标点击打开,1表示鼠标点击,0表示自动*/
    int sum=0;
    char num[2];

    if(map[y][x]>>2&1 && control)return;/*标记过,点击无效*/

    if(map[y][x]>>1&1)return;/*检查是否被打开过*/
    map[y][x]+=1<<1;

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10+8);

    if(map[y][x]&1==1){/*踩到地雷,游戏失败*/
        game_over();
        dead=1;/*死亡*/
        return;
    }
    score++;/*加分*/
    if(score==mx*my-count){
        win();
        dead=1;
        return;
    }

    if(x!=0)sum+=map[y][x-1]&1;
    if(x!=mx-1)sum+=map[y][x+1]&1;
    if(y!=0)sum+=map[y-1][x]&1;
    if(y!=my-1)sum+=map[y+1][x]&1;
    if(x!=0 && y!=0)sum+=map[y-1][x-1]&1;
    if(x!=mx-1 && y!=0)sum+=map[y-1][x+1]&1;
    if(x!=mx-1 && y!=my-1)sum+=map[y+1][x+1]&1;
    if(x!=0 && y!=my-1)sum+=map[y+1][x-1]&1;

    settextstyle(0,0,1);
    if(sum!=0){
        sprintf(num,"%d",sum);
        setcolor(sum%6);/*确定颜色*/
        outtextxy(ha_x+2+x*10+1,ha_y+2+y*10+1,num);/*显示周围雷数*/
    }
    else{
        if(x!=0 && !map[y][x-1]&1)box_open(x-1,y,0);/*0表示自动打开*/
        if(x!=mx-1 && !map[y][x+1]&1)box_open(x+1,y,0);
        if(y!=0 && !map[y-1][x]&1)box_open(x,y-1,0);
        if(y!=my-1 && !map[y+1][x]&1)box_open(x,y+1,0);
        if(x!=0 && y!=0 && !map[y-1][x-1]&1)box_open(x-1,y-1,0);
        if(x!=mx-1 && y!=0 && !map[y-1][x+1]&1)box_open(x+1,y-1,0);
        if(x!=mx-1 && y!=my-1 && !map[y+1][x+1])box_open(x+1,y+1,0);
        if(x!=0 && y!=my-1 && !map[y+1][x-1])box_open(x-1,y+1,0);
    }
}

void box_mark(int x,int y){/*给小方块插旗标记*/
    int nx=ha_x+2+x*10,ny=ha_y+2+y*10;
    if(map[y][x]>>1&1)return;/*已经打开*/
    if(map[y][x]>>2&1)map[y][x]-=1<<2;/*有旗拔旗*/
    else map[y][x]+=1<<2;/*插旗*/

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    setcolor(WHITE);
    line(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10);/*一横,使之有立体感*/
    line(ha_x+2+x*10,ha_y+2+y*10+1,ha_x+2+x*10,ha_y+2+y*10+8);/*一竖*/

    bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8);


    if(map[y][x]>>2&1){
        setcolor(RED); /*绘制小旗帜*/
        line(nx+3,ny+2,nx+7,ny+4);
        line(nx+3,ny+4,nx+7,ny+4);
        setcolor(BLACK);
        line(nx+3,ny+2,nx+3,ny+7);
        line(nx+2,ny+7,nx+4,ny+7);
    }
}

void map_window(){/*地图绘制*/
    int x,y;
    setfillstyle(SOLID_FILL,BLACK);/*清除屏幕*/
    bar(1,40,638,478);/*清除屏幕*/

    setcolor(WHITE);
    rectangle(ha_x,ha_y,ha_x+1+mx*10+1,ha_y+1+my*10+1);
    setfillstyle(SOLID_FILL,DARKGRAY);
    bar(ha_x+1,ha_y+1,ha_x+1+mx*10,ha_y+1+my*10);/*扫雷部分背景*/

    rectangle(ha_x,ha_y-30,ha_x+1+mx*10+1,ha_y);/*扫雷上部分*/
    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(ha_x+1,ha_y-29,ha_x+1+mx*10,ha_y-1);/*扫雷上部分*/

    setfillstyle(SOLID_FILL,LIGHTGRAY);/*绘制开局框--*/
    setcolor(WHITE);
    line((ha_x+ha_x+2+mx*10)/2-16,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2-16,(ha_y+ha_y-30)/2+8);/*竖*/
    line((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2-9);/*横*/
    setcolor(DARKGRAY);
    line((ha_x+ha_x+2+mx*10)/2+16,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2+16,(ha_y+ha_y-30)/2+9);/*竖*/
    line((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2+9,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2+9);/*横*/
    bar((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2-8,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2+8);/*--绘制开局框*/

    drawmat(kai12S,12,(ha_x+ha_x+2+mx*10)/2-13,(ha_y+ha_y-30)/2-6,BLACK);
    drawmat(ju12S,12,(ha_x+ha_x+2+mx*10)/2+1,(ha_y+ha_y-30)/2-6,BLACK);

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    for(y=0;y<my;y++)/*显示小方格*/
        for(x=0;x<mx;x++){
            setcolor(WHITE);
            line(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10);/*一横,使之有立体感*/
            line(ha_x+2+x*10,ha_y+2+y*10+1,ha_x+2+x*10,ha_y+2+y*10+8);/*一竖*/

            /*setcolor(DARKGRAY);
            line(ha_x+2+x*10,ha_y+2+y*10+8,ha_x+2+x*10+8,ha_y+2+y*10+8); 一横
            line(ha_x+2+x*10+8,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8); 一竖

            bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+7,ha_y+2+y*10+7);
            */
            bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8);
        }
}

void initmap(){/*地图初始化*/
    int i=0,x,y;
    dead=0;
    score=0;

    switch(hard){
    case 0:
        mx=9;
        my=9;
        count=10;
        break;
    case 1:
        mx=16;
        my=16;
        count=40;
        break;
    case 2:
        mx=30;
        my=16;
        count=99;
        break;
    }

    for(y=0;y<my;y++)/*地图数组设为0*/
        for(x=0;x<mx;x++)
            map[y][x]=0;
           
    for(;i<count;){/*随机埋雷*/
        y=rand()%my;
        x=rand()%mx;
        if(map[y][x]==0){
            map[y][x]++;
            i++;
        }
    }
    map_window();
}

void m_save(){/*储存menu挡住的部分*/
    int i,j;
    for(j=40;j<=93;j++)
        for(i=2;i<=52;i++)
            m_s[j-40][i-2]=getpixel(i,j);
}

void m_load(){/*恢复menu挡住的部分*/
    int i,j;
    for(j=40;j<=93;j++)
        for(i=2;i<=52;i++)
            putpixel(i,j,m_s[j-40][i-2]);
}


void ha_mouse(){
    int i,j,k,x=-1,y=-1,flag=0,color;
    int tx1,ty1,tx2,ty2,tbx;
    int new_x=ha_x,new_y=ha_y;
    /*char tgraph[193][303],tg=0;*/
    union REGS inregs,outregs,regs2;

 

    inregs.x.ax=0x03;

    while(!bioskey(1)){

        int86(0x33,&inregs,&outregs);/*调用鼠标中断*/

        regs2.x.ax=0x06;
        regs2.x.bx=0x00;
        int86(0x33,?s2,?s2);/*CX=水平位置(最后释放时),DX=垂直位置(最后释放时)*/
        tx2=regs2.x.cx;
        ty2=regs2.x.dx;

        if(x!=outregs.x.cx || y!=outregs.x.dx || tbx!=outregs.x.bx){
            /*printf("%d",outregs.x.bx);*/
            if(flag){
                for(j=0;j<10;j++)/*恢复上次鼠标一定范围内的像素颜色*/
                    for(i=0;i<6;i++)
                        putpixel(x+i,y+j,re[j][i]);
            }
            flag=1;
            /*====================================================================================================================扩充功能部分*/

            if(outregs.x.bx & 0x01){/*鼠标左键按下------------------------鼠标点击判断*/
                if(outregs.x.cx>=639-19 && outregs.x.cx<=638 && outregs.x.dx>=1 && outregs.x.dx<=18)exit(0);/*关闭按钮*/
                else if(outregs.x.cx>=1 && outregs.x.cx<=32 && outregs.x.dx>=21 && outregs.x.dx<=38){/*主菜单-游戏*/
                    if(n1==-1)m_save();
                    else if(n1==1)m_load();
                    n1=0;
                    n2=-1;
                    menu_window();
                }
                else if(outregs.x.cx>=33 && outregs.x.cx<=64 && outregs.x.dx>=21 && outregs.x.dx<=38){/*主菜单-难度*/
                    if(n1==-1)m_save();
                    else if(n1==0)m_load();
                    n1=1;
                    n2=-1;
                    menu_window();
                }
                else if(n1==0 && n2==1)exit(0);

                /*开局*/
                else if((n1==0 && n2==0) || (outregs.x.cx>=(ha_x+ha_x+2+mx*10)/2-16 && outregs.x.cx<=(ha_x+ha_x+2+mx*10)/2+16 && outregs.x.dx>=(ha_y+ha_y-30)/2-9 && outregs.x.dx<=(ha_y+ha_y-30)/2+8)){/*开局*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    initmap();
                }
                else if(n1==1 && n2==0){/*易*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=0;
                    initmap();
                }
                else if(n1==1 && n2==1){/*中*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=1;
                    initmap();
                }
                else if(n1==1 && n2==2){/*难*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=2;
                    initmap();
                }

                /*
                else if(outregs.x.cx>=new_x && outregs.x.cx<=new_x+1+mx*10+1 && outregs.x.dx>+new_y-30 && outregs.x.dx<=new_y){ 拖动扫雷图标扫雷
                    if(tg==0){ 扫雷部分存储
                        tg++;
                        for(j=0;j<=1+my*10+1+30;j++)
                            for(i=0;i<=mx*10+2;i++)
                                tgraph[j][i]=getpixel(ha_x+i,ha_y+j-30);
                    }

                    if(tbx&1 && x>=new_x && x<=new_x+1+mx*10+1 && y>=new_y-30 && y<=new_y){
                        setcolor(YELLOW);
                        rectangle(new_x,new_y-29,new_x+1+mx*10,new_y+1+my*10);
                        rectangle(new_x,new_y-30,new_x+1+mx*10+1,new_y+1+my*10+1);
                        new_x+=outregs.x.cx-x;
                        new_y+=outregs.x.dx-y;
                        tg=2;
                    }
                    else if(tg=2 && x>=new_x && x<=new_x+1+mx*10+1 && y>=new_y-30 && y<=new_y){
                        tg=0;
                        ha_x=new_x;
                        ha_y=new_y;
                        for(j=0;j<=1+my*10+1+30;j++)
                            for(i=0;i<=mx*10+2;i++)
                                putpixel(ha_x+i,ha_y+j-30,tgraph[j][i]);
                    }
                }
                */

                else{/*没有点击到按钮*/
                    if(n1!=-1)m_load();
                    n1=n2=-1;
                    menu_window();
                }

            }

            if(n1==0 && outregs.x.cx>=2 && outregs.x.cx<=31 && outregs.x.dx>=40 && outregs.x.dx<=75){/*游戏下级菜单操作*/
                n2=(outregs.x.dx-40)/18;
                menu_window();
            }
            if(n1==1 && outregs.x.cx>=34 && outregs.x.cx<=52 && outregs.x.dx>=40 && outregs.x.dx<=93){/*难度下级菜单操作*/
                n2=(outregs.x.dx-40)/18;
                menu_window();
            }

            /*-----------------------------左键点击控制部分*/
            if(tx2-ha_x-2>=0 && ty2-ha_y-2>=0 && (tx2-ha_x-2)/10>=0 && (tx2-ha_x-2)/10<=mx-1 && (ty2-ha_y-2)/10>=0 && (ty2-ha_y-2)/10<=my-1 && dead==0 && (tx1!=tx2 || ty1!=ty2)){
                box_open((tx2-ha_x-2)/10,(ty2-ha_y-2)/10,1);
            }

            if(outregs.x.bx>>1 & 0x01 && dead==0){/*鼠标右键按下------------------------鼠标点击判断*/
                if((outregs.x.cx-ha_x-2)/10>=0 && (outregs.x.cx-ha_x-2)/10<=mx-1 && (outregs.x.dx-ha_y-2)/10>=0 && (outregs.x.dx-ha_y-2)/10<=my-1){
                    box_mark((outregs.x.cx-ha_x-2)/10,(outregs.x.dx-ha_y-2)/10);/*插旗标记*/
                }
            }

 

            /*================================================================================================================================*/
            for(j=0;j<10;j++)/*储存鼠标一定范围内的像素颜色*/
                for(i=0;i<6;i++)
                    re[j][i]=getpixel(outregs.x.cx+i,outregs.x.dx+j);

            for(i=0;i<8;i++){/*确定鼠标各顶点位置*/
                m_now_poly[i]=m_poly[i]+outregs.x.cx;
                i++;
                m_now_poly[i]=m_poly[i]+outregs.x.dx;
            }

            setcolor(GREEN);
            drawpoly(4,m_now_poly);/*显示鼠标框架*/
            setfillstyle(SOLID_FILL,WHITE);/*填充鼠标,注意以白色填充,当遇到白色背景时会不能完全填充*/
            floodfill(m_now_poly[0]+1,m_now_poly[1]+5,GREEN);
            setcolor(LIGHTRED);
            drawpoly(4,m_now_poly);/*显示鼠标框架*/
        }
        x=outregs.x.cx;/*存鼠标坐标,供恢复使用*/
        y=outregs.x.dx;
        tbx=outregs.x.bx;
        tx1=tx2;/*暂存鼠标释放的位置*/
        ty1=ty2;
    }
}

void full_window(){/*整体部分,包括标题栏的绘制*/


    setbkcolor(BLACK);
    setcolor(WHITE);

    line(0,20,639,20);
    rectangle(0,0,639,479);

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(1,1,638,19);

    drawmat(sao16S,16,6,3,BLACK);/*标题部分-汉字*/
    drawmat(lei16S,16,25,3,BLACK);

    setcolor(BLACK);
    settextstyle(0,0,1);
    outtextxy(44,8,"- made by HungryAnt");

    setfillstyle(SOLID_FILL,RED);/*显示关闭图标*/
    bar(639-19,1,638,18);

    setcolor(WHITE);
    setlinestyle(0,0,3);/*X*/
    line(639-19+2,1+2,638-2,18-2);
    line(639-19+2,18-2,638-2,1+2);
    setlinestyle(0,0,1);
}
  
void menu_window(){/*------------------------------------------菜单栏*/
    int i;

    setcolor(BLACK);
    for(i=0;i<2;i++){/*主菜单*/
        if(i==n1)setfillstyle(SOLID_FILL,DARKGRAY);
        else setfillstyle(SOLID_FILL,LIGHTGRAY);
        bar(32*i+1,21,32*(i+1),38);
    }

    drawmat(you12S,12,4,21+3,BLACK);/*游戏*/
    drawmat(xi12S,12,4+12+2,21+3,BLACK);
    drawmat(nan12S,12,32+4,21+3,BLACK);/*难度*/
    drawmat(du12S,12,32+4+12+2,21+3,BLACK);

 

    if(n1==0){/*------------------包括菜单----------------游戏菜单*/
        for(i=0;i<2;i++){
            if(i==n2)setfillstyle(SOLID_FILL,DARKGRAY);
            else setfillstyle(SOLID_FILL,LIGHTGRAY);
            bar(2,39+(i*(12+6))+1,2+2+12*2+3,39+((i+1)*(12+6)));
        }
        drawmat(kai12S,12,4,39+3,BLACK);/*开局*/
        drawmat(ju12S,12,4+12+2,39+3,BLACK);

        drawmat(tui12S,12,4,39+6+3+12,BLACK);/*退出*/
        drawmat(chu12S,12,4+12+2,39+6+3+12,BLACK);
    }
    else if(n1==1){/*-------------------------------------难度菜单*/
        for(i=0;i<3;i++){
            if(i==n2)setfillstyle(SOLID_FILL,DARKGRAY);
            else setfillstyle(SOLID_FILL,LIGHTGRAY);
            bar(2+32,39+(i*(12+6))+1,2+32+12+6,39+((i+1)*(12+6)));
        }
        drawmat(yi12S,12,2+32+4,39+3,BLACK);/*易中难*/
        drawmat(zhong12S,12,2+32+4,39+18+3,BLACK);
        drawmat(nan12S,12,2+32+4,39+36+3,BLACK);
    }

}

 

ha_graph(){/*图形模式初始化*/
    int gd=DETECT,gm,errorcode;
    initgraph(&gd,&gm,"");
    errorcode = graphresult();
    if (errorcode != grOk){
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Author:HungryAnt");
        getch();
        exit(1);
    }   
}

int main(){
    int i;

    srand((unsigned)time(NULL));/*使每次执行程序得到的结果不一样*/
    ha_graph();
    full_window();
    menu_window(-1,-1);/*菜单*/
    initmap();/*地图初始化*/

    ha_mouse();/*鼠标*/
}


 

文章评论,共0条
游客请输入验证码
浏览474955次