blowup.zip

  • Haroon3
    了解作者
  • C/C++
    开发工具
  • 28KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2018-03-17 13:42
    上传日期
This is like minesweeper, but for DOS. There is some mouse support.
blowup.zip
  • MOUSE.C
    1.8KB
  • BLOWUP.COM
    25.5KB
  • BLOWUP.C
    15KB
  • BLOWUP.PIF
    967B
内容介绍
#include <conio.h> #include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> #include "d:\mouse.c" #define YES 1 #define NO 0 #define XPX 15 /* X pixels by square */ #define YPX 15 /* Y pixels by square */ #define DEFCX 30 /* Default number of squares */ #define DEFCY 28 #define MINE 255-'0' /* So that when it prints, it prints char 0xff */ #define STSQUARE struct stsquare STSQUARE { unsigned char value; /* Number of mines in the surround squares */ unsigned char sqopen; /* Square is open */ unsigned char sqpress; /* Square is pressed */ unsigned char sqmark; /* Square is marked */ } *psquare; #define value(x,y) (psquare+(x)*ncy+(y))->value #define sqopen(x,y) (psquare+(x)*ncy+(y))->sqopen #define sqpress(x,y) (psquare+(x)*ncy+(y))->sqpress #define sqmark(x,y) (psquare+(x)*ncy+(y))->sqmark int XST, /* Offset of first pixel X */ YST, ncx, /* Number of squares in X */ ncy, cmines, /* Mines discovered */ initmines, /* Number of initial mines */ sqclosed, /* Squares still closed */ maxy; /* Max. number of y pixels of the screen */ void Graph_init(void); void Read_param(int argc, char *argv[]); void Set_mines(int nminas); void Set_square(int x, int y, int status); void Mouse_set(void); void Draw_squares(void); int Do_all(void); void Blow_up(void); void Open_square(int x, int y); int Open_near_squares(int x, int y); /************************************************************************/ void main(int argc, char *argv[]) { if (!mouse_reset()) { cputs(" ERROR: I can't find a mouse driver\r\n"); exit(2); } Graph_init(); Read_param(argc, argv); Mouse_set(); do { randomize(); cleardevice(); Set_mines(cmines=initmines); mouse_enable(); Draw_squares(); } while (Do_all() != '\x1b'); closegraph(); } /************************************************************************* * * * F U N C T I O N S * * * *************************************************************************/ /*----------------------------------------------------------------------*/ void Graph_init(void) { int graphdriver=DETECT, graphmode, errorcode; if(errorcode < 0) { cprintf("\n\rGraphics System Error: %s\n",grapherrormsg(errorcode)); exit(98); } initgraph(&graphdriver, &graphmode, ""); errorcode=graphresult(); if(errorcode!=grOk) { printf(" Graphics System Error: %s\n",grapherrormsg(errorcode)); exit(98); } maxy=getmaxy(); } /* Graph_init */ /*----------------------------------------------------------------------*/ void Read_param(int argc, char *argv[]) { int x, y, m; x=y=m=0; if (argc!=1) { if (!isdigit(*argv[1])) { closegraph(); cprintf("Usage is: %s [x] [y] [m]\r\n\n" "Where x is the horizontal size\r\n" " y is the vertical size\r\n" " m is the number of mines\r\n\n" " Left mouse button: Open the square\r\n" "Right mouse button: Mark the square\r\n" " -The first time puts a 'mine' mark\r\n" " -The second time puts a 'possible " "mine' mark\r\n" " -The third time unmarks the square\r\n" "Left+Right buttons: Open the surrounded squares only if " "the count of mines\r\n" " is equal to the number in the square",argv[0]); exit (1); } switch (argc) { case 4: m=atoi(argv[3]); case 3: y=atoi(argv[2]); case 2: x=atoi(argv[1]); } } XST=100; ncx=DEFCX; if (maxy==479) { YST=30; ncy=DEFCY; } else { YST=25; ncy=20; } if (x>0 && x<ncx) ncx=x; if (y>0 && y<ncy) { YST+=((ncy-y)*YPX)>>1; ncy=y; } initmines= m ? m : ncx*ncy*4/25; /* There are about 16% of mines */ if (((void near*)psquare=calloc(ncx*ncy, sizeof(STSQUARE)))==NULL) { closegraph(); cputs("ERROR: Not enought memory"); exit(3); } } /* Read_param */ /*----------------------------------------------------------------------*/ void Set_mines(int nminas) { STSQUARE *p; int i, x, y, a, b; sqclosed=ncx*ncy-nminas; p=psquare; for (i=ncx*ncy; i>0; i--, p++) p->value = p->sqopen = p->sqpress = p->sqmark = NO; for (i=nminas; i>0; i--) { while (value(x=random(ncx), y=random(ncy)) == MINE) ; value(x,y)=MINE; } for (x=ncx-1; x>=0; x--) { for (y=ncy-1; y>=0; y--) { if (value(x,y) == MINE) continue; a=x-1; b=y-1; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); a++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); a++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); b++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); a-=2; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); b++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); a++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); a++; if (a>=0 && b>=0 && a<ncx && b<ncy) value(x,y)+=(value(a,b) == MINE); } } } /* Set_mines */ /*----------------------------------------------------------------------*/ /* If status=1 then draw the square up, if it's 0 then draw it down */ void Set_square(int x, int y, int status) { int xl, xr, yt, yb; mouse_disable(); xl=XST+XPX*x; xr=xl+XPX-1; yt=YST+YPX*y; yb=yt+YPX-1; setfillstyle(SOLID_FILL, LIGHTGRAY); bar(xl, yt, xr, yb); if (status) { setcolor(WHITE); line(xl,yt,xl,yb-1); line(xl,yt,xr-1,yt); setcolor(DARKGRAY); line(xr,yb,xl,yb); line(xr,yb,xr,yt); switch (sqmark(x,y)) { case 2 : setfillstyle(SOLID_FILL, LIGHTBLUE); setcolor(LIGHTBLUE); break; case 1 : setfillstyle(SOLID_FILL, LIGHTRED); setcolor(LIGHTRED); break; default: setcolor(LIGHTGRAY); } fillellipse(XST+XPX*x+XPX/2, YST+YPX*y+YPX/2, 3, 3); switch (sqmark(x,y)) { case 2 : case 1 : setfillstyle(SOLID_FILL, YELLOW); setcolor(YELLOW); fillellipse(XST+XPX*x+XPX/2, YST+YPX*y+YPX/2, 1, 1); } } else { sqclosed--; setcolor(DARKGRAY); line(xl,yt,xl,yb); line(xl,yt,xr,yt); } mouse_enable(); } /* Set_square */ /*----------------------------------------------------------------------*/ void Mouse_set(void) { mouse_horizontal_range(XST, XST+XPX*ncx-3); mouse_vertical_range(YST, YST+YPX*ncy-3); } /* Mouse_set */ /*----------------------------------------------------------------------*/ void Draw_squares(void) { int x, y; mouse_disable(); for (x=0; x<ncx; x++) for (y=0; y<ncy; y++) Set_square(x,y,1); mouse_enable(); } /* Draw_squares */ /*----------------------------------------------------------------------*/ /* Here we do all the job */ int Do_all(void) { int x, y, xant=-1, yant, mlstant, mrstant, cminasant=0, ttrans, tant=0; long tst, tact; char str[] ="xxxxx: 0000", blk[] ="混混混混混�"; mouse_enable(); time(&tst); while (!kbhit()) { if (!sqclosed && !mouse_status) { /* All mines discovered */ settextjustify(LEFT_TEXT, CENTER_TEXT); setcolor(BLACK); outtextxy(0, maxy/2-10, blk); sprintf(str,"Mines: 0"); setcolor(LIGHTRED); outtextxy(0, maxy/2-10, str); settextjustify(L
评论
    相关推荐
    • Game Extract_201.zip
      converter dari cmp ke extesion data
    • tic-tac-toe-game.zip
      there are two codes of the game Noughts and Crosses.
    • NimGame.zip
      NimGame Two Players remove stones till there are no more left. The last player to remove stones wins.
    • necromine-game
      坏死游戏 necromine是一款3D等距游戏,您在其中扮演一个煤矿工人,目睹计划中的TNT爆炸发生错误并演变成煤矿灾难。 大规模爆炸导致大面积坍塌,从而打开了地下通道,催生了地狱般的生物,剧烈地散开了。...
    • TriviaGame
      TriviaGame 关于这个项目 在这个项目中,我创建了一个带有计时器功能的琐事游戏。 当玩家单击开始按钮时,计时器将启动,并且玩家将有10秒的时间回答每个问题。 游戏会根据分配的正确,不正确以及未回答的时间来计算...
    • doom game
      一款采用c语言做的小游戏
    • Beginning Game Audio Programming
      There’s even coverage of using DirectPlay Voice for real- time voice chat in your games! If you are comfortable with C++ and DirectX, then you’re ready to dive into the exciting world of audio with...
    • Gideros Mobile Game Development
      Have you ever had an interesting idea for a mobile game? Have you ever wanted to jump on the mobile app bandwagon? Developing a mobile game has never been so fun and easy, and with the vast amount of ...
    • dice_game
      Dice_Game 两人游戏,旨在与朋友一起玩或在计算机上玩。 在这个游戏中,使用了六个面的骰子。 玩家将轮流滚动六张面Kong的骰子,直到有人达到一百张并赢得比赛为止。 轮到玩家时,他们可以选择滚动或按住。 如果...
    • snowglobe-src-viewer-2.0.0-r0.tar.gz
      国外的开源游戏引擎,能够承载上千人,属于社交类的游戏