Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for games/mines/mines.c between version 1.11 and 1.12

version 1.11, 2003/07/17 21:44:29 version 1.12, 2003/07/20 12:18:56
Line 1 
Line 1 
 /* $Platon: games/mines/mines.c,v 1.10 2003/07/16 19:56:36 nepto Exp $ */  /* $Platon: games/mines/mines.c,v 1.11 2003/07/17 21:44:29 nepto Exp $ */
   
 #define PSQUARE_DYNAMIC_ALLOCATION      (0)  #define PSQUARE_DYNAMIC_ALLOCATION      (0)
   #define ASSERTION_USAGE                         (1)
   
 /* CONSTS */  /* CONSTS */
 #define EXENAME     "mines.exe"  #define EXENAME     "mines.exe"
Line 48 
Line 49 
 #define isininfo(x,y)   isinbar(x,y,infox,infoy,infox+INFOXSIZE,infoy+INFOYSIZE)  #define isininfo(x,y)   isinbar(x,y,infox,infoy,infox+INFOXSIZE,infoy+INFOYSIZE)
 #define underinfo(x,y)  (isininfo(xoff+x*barsize,yoff+y*barsize) \  #define underinfo(x,y)  (isininfo(xoff+x*barsize,yoff+y*barsize) \
                 ||isininfo(xoff-1+(x+1)*barsize,yoff+y*barsize) \                  ||isininfo(xoff-1+(x+1)*barsize,yoff+y*barsize) \
                 ||isininfo(xoff-1+(x+1)*barsize,yoff-1+(y+1)*barsize)||isininfo(xoff+x*barsize,yoff-1+(y+1)*barsize))                  ||isininfo(xoff-1+(x+1)*barsize,yoff-1+(y+1)*barsize) \
                   ||isininfo(xoff+x*barsize,yoff-1+(y+1)*barsize))
 #define HideInfo()      WriteInfo(0xffff,0xffff)  #define HideInfo()      WriteInfo(0xffff,0xffff)
 #define ShowInfo()      WriteInfo(infox,infoy)  #define ShowInfo()      WriteInfo(infox,infoy)
 #if PLATON_SYSTEM_WIN32  #if PLATON_SYSTEM_WIN32
Line 71 
Line 73 
 #include <string.h>  #include <string.h>
 #include <ctype.h>  #include <ctype.h>
 #include <time.h>  #include <time.h>
   #if ASSERTION_USAGE
   #  include <assert.h>
   #endif
   
 #include <system.h>  #include <system.h>
   
Line 109 
Line 114 
 #  define RAND_INT(__lo, __hi)  (__lo + (random() % (__hi - __lo + 1)))  #  define RAND_INT(__lo, __hi)  (__lo + (random() % (__hi - __lo + 1)))
 #endif  #endif
   
 /* NEW TYPES */  
 #define value(x,y)              ((psquare+(x)*ny+(y))->value)  
 #define sqopen(x,y)             ((psquare+(x)*ny+(y))->sqopen)  
 #define sqpress(x,y)    ((psquare+(x)*ny+(y))->sqpress)  
 #define sqmark(x,y)             ((psquare+(x)*ny+(y))->sqmark)  
   
 typedef struct stsquare  typedef struct stsquare
 {  {
         BYTE value;         /* Number of mines in the surround squares */          BYTE value;         /* Number of mines in the surround squares */
Line 169  char gastxt[]="\
Line 168  char gastxt[]="\
 Ý (p+a/Vý)(V-b)=RT ÷> Van_der_Waals Þ\n\r\  Ý (p+a/Vý)(V-b)=RT ÷> Van_der_Waals Þ\n\r\
 Ý                                   Þ\n\r\  Ý                                   Þ\n\r\
 ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß";  ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß";
   
   #if ASSERTION_USAGE
   BYTE value(int x, int y)   { assert(x>=0&&y>=0&&x<nx&&y<ny); return (psquare+(x)*ny+(y))->value;   }
   BYTE sqopen(int x, int y)  { assert(x>=0&&y>=0&&x<nx&&y<ny); return (psquare+(x)*ny+(y))->sqopen;  }
   BYTE sqpress(int x, int y) { assert(x>=0&&y>=0&&x<nx&&y<ny); return (psquare+(x)*ny+(y))->sqpress; }
   BYTE sqmark(int x, int y)  { assert(x>=0&&y>=0&&x<nx&&y<ny); return (psquare+(x)*ny+(y))->sqmark;  }
   void set_value(int x, int y, BYTE a)   { assert(x>=0&&y>=0&&x<nx&&y<ny); (psquare+(x)*ny+(y))->value   = a; }
   void set_sqopen(int x, int y, BYTE a)  { assert(x>=0&&y>=0&&x<nx&&y<ny); (psquare+(x)*ny+(y))->sqopen  = a; }
   void set_sqpress(int x, int y, BYTE a) { assert(x>=0&&y>=0&&x<nx&&y<ny); (psquare+(x)*ny+(y))->sqpress = a; }
   void set_sqmark(int x, int y, BYTE a)  { assert(x>=0&&y>=0&&x<nx&&y<ny); (psquare+(x)*ny+(y))->sqmark  = a; }
   #else
   #  define value(x, y)                   ((psquare + (x) * ny + (y))->value      )
   #  define sqopen(x, y)                  ((psquare + (x) * ny + (y))->sqopen     )
   #  define sqpress(x, y)                 ((psquare + (x) * ny + (y))->sqpress    )
   #  define sqmark(x, y)                  ((psquare + (x) * ny + (y))->sqmark     )
   #  define set_value(x, y, a)    ((psquare + (x) * ny + (y))->value   = a)
   #  define set_sqopen(x, y, a)   ((psquare + (x) * ny + (y))->sqopen  = a)
   #  define set_sqpress(x, y, a)  ((psquare + (x) * ny + (y))->sqpress = a)
   #  define set_sqmark(x, y, a)   ((psquare + (x) * ny + (y))->sqmark  = a)
   #endif
   
 /* /////////////////////////////////////////////////////////////////////// */  /* /////////////////////////////////////////////////////////////////////// */
 /* FUNCTIONS DECLARATION */  /* FUNCTIONS DECLARATION */
 int brkfnc(void);  int brkfnc(void);
Line 181  void SetData(void);
Line 201  void SetData(void);
 void SetMines();  void SetMines();
 void SetExcludeMines(int ex, int ey);  void SetExcludeMines(int ex, int ey);
 void SetSquare(WORD x,WORD y,BYTE status);  void SetSquare(WORD x,WORD y,BYTE status);
 void WriteInfo(WORD x,WORD y);  void WriteInfo(int x, int y);
 BYTE DoAll(void);  BYTE DoAll(void);
 void Help(void);  void Help(void);
 void ShowHelpText(WORD x,WORD y,WORD linesize,WORD defcolor,WORD inscolor,char*helpstr);  void ShowHelpText(WORD x,WORD y,WORD linesize,WORD defcolor,WORD inscolor,char*helpstr);
Line 258  int main(int argc,char*argv[])
Line 278  int main(int argc,char*argv[])
                                         SetMines();                                          SetMines();
                                 } while (DoAll());                                  } while (DoAll());
 #if PSQUARE_DYNAMIC_ALLOCATION  #if PSQUARE_DYNAMIC_ALLOCATION
                                 free(psquare);  #  if ASSERTION_USAGE
                                   assert(psquare != NULL)
   #  endif
                                           free(psquare);
                                 psquare = NULL;                                  psquare = NULL;
 #endif  #endif
                                 free(infosafe);                                  if (infosafe != NULL) {
                                 infosafe = NULL;                                          free(infosafe);
                                           infosafe = NULL;
                                   }
                                 break;                                  break;
                         case 2:                          case 2:
                                 HscTable();                                  HscTable();
Line 553  void SetExcludeMines(int ex, int ey) /*
Line 578  void SetExcludeMines(int ex, int ey) /*
                         x = RAND_INT(0, nx - 1);                          x = RAND_INT(0, nx - 1);
                         y = RAND_INT(0, ny - 1);                          y = RAND_INT(0, ny - 1);
                 } while ((x == ex && y == ey) || value(x, y) == MINE);                  } while ((x == ex && y == ey) || value(x, y) == MINE);
                 value(x, y) = MINE;                  set_value(x, y, MINE);
         }          }
         for (x=nx-1;x>=0;x--) {          for (x=nx-1;x>=0;x--) {
                 for (y=ny-1;y>=0;y--) {                  for (y=ny-1;y>=0;y--) {
                         if (value(x,y)==MINE)                          if (value(x,y)==MINE)
                                 continue;                                  continue;
                         a=x-1;                          a = x - 1;
                         b=y-1;                          b = y - 1;
                         if (a>=0 && b>=0 && a<nx && b<ny)                          i = 0;
                                 value(x,y)+=(value(a,b) == MINE);                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); a++;
                         a++;                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); a++;
                         if (a>=0 && b>=0 && a<nx && b<ny)                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); b++;
                                 value(x,y)+=(value(a,b) == MINE);                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); a--; a--;
                         a++;                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); b++;
                         if (a>=0 && b>=0 && a<nx && b<ny)                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); a++;
                                 value(x,y)+=(value(a,b) == MINE);                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE); a++;
                         b++;                          if (a>=0 && b>=0 && a<nx && b<ny) i += (value(a, b) == MINE);
                         if (a>=0 && b>=0 && a<nx && b<ny)                          set_value(x, y, value(x, y) + i);
                                 value(x,y)+=(value(a,b) == MINE);  
                         a-=2;  
                         if (a>=0 && b>=0 && a<nx && b<ny)  
                                 value(x,y)+=(value(a,b) == MINE);  
                         b++;  
                         if (a>=0 && b>=0 && a<nx && b<ny)  
                                 value(x,y)+=(value(a,b) == MINE);  
                         a++;  
                         if (a>=0 && b>=0 && a<nx && b<ny)  
                                 value(x,y)+=(value(a,b) == MINE);  
                         a++;  
                         if (a>=0 && b>=0 && a<nx && b<ny)  
                                 value(x,y)+=(value(a,b) == MINE);  
                 }                  }
         }          }
 } /* }}} */  } /* }}} */
Line 633  void SetSquare(WORD x,WORD y,BYTE status
Line 645  void SetSquare(WORD x,WORD y,BYTE status
   
 /*----------------------------------------------------------------------*/  /*----------------------------------------------------------------------*/
 /* this expect mouse turned on */  /* this expect mouse turned on */
 void WriteInfo(WORD x, WORD y) /* {{{ */  void WriteInfo(int x, int y) /* {{{ */
 {  {
         register BYTE k;          register BYTE k;
         char txt[8];          char txt[30];
         hidemouse();          if (infosafe != NULL) {
         if (infosafe==NULL) {                  hidemouse();
                 if ((infosafe=malloc(imagesize(infox,infoy,infox+INFOXSIZE,infoy+INFOYSIZE)))==NULL) {                  putimage(infox, infoy, infosafe, COPY_PUT);
                   showmouse();
           }
   
           /* HideInfo() */
           if (x == 0xffff && y == 0xffff) {
                   if (infosafe != NULL) {
                           free(infosafe);
                           infosafe = NULL;
                   }
                   return;
           }
   
           infox = max(0, min((int) x, getmaxx() - INFOXSIZE));
           infoy = max(0, min((int) y, getmaxy() - INFOYSIZE));
           if (infosafe == NULL) {
                   if ((infosafe = malloc(imagesize(infox, infoy, infox + INFOXSIZE,
                                                           infoy + INFOYSIZE))) == NULL) {
                         my_graph_close();                          my_graph_close();
                         puts(ERR_MEMORY);                          puts(ERR_MEMORY);
                         exit(1);                          exit(1);
                 }                  }
         } else          }
                 putimage(infox,infoy,infosafe,COPY_PUT);          hidemouse();
           getimage(infox, infoy, infox + INFOXSIZE, infoy + INFOYSIZE, infosafe);
         if (x==0xffff&&y==0xffff) {          DrawWindow(infox, infoy, infox + INFOXSIZE, infoy + INFOYSIZE,
                 free(infosafe);                          I_BCKCOLOR, I_RCTCOLOR);
                 infosafe=NULL;  
         } else {          for (k = 0; k < INFOLINES; k++) {
                 infox=max(0,min((int)x,getmaxx()-INFOXSIZE));                  setcolor(I_TXTCOLOR);
                 infoy=max(0,min((int)y,getmaxy()-INFOYSIZE));                  moveto(infox + INFOXSIZE / 2, textheight(infostr3[0]) / 2
                 getimage(infox,infoy,infox+INFOXSIZE,infoy+INFOYSIZE,infosafe);                                  + infoy + (k * textheight(infostr3[k])));
                 DrawWindow(infox,infoy,infox+INFOXSIZE,infoy+INFOYSIZE,                  outtext(infostr3[k]);
                                 I_BCKCOLOR,I_RCTCOLOR);                  switch (k) {
                           case 3:  sprintf(txt, " %02u %02u ", nx, ny);    break;
                 for (k=0;k<INFOLINES;k++) {                          case 9:  sprintf(txt, "  %03u  ", cmines);       break;
                         setcolor(I_TXTCOLOR);                          case 11: sprintf(txt, "%.3s    ", infostr3[k]);  break;
                         moveto(infox+INFOXSIZE/2,textheight(infostr3[0])/2+infoy+(k*textheight(infostr3[k])));                          case 12:
                         outtext(infostr3[k]);                          case 13: sprintf(txt, "%.2s     ", infostr3[k]); break;
                         switch (k) {                          default: txt[0] = EOS;
                                 case 3:sprintf(txt," %02u %02u ",nx,ny);break;  
                                 case 9:sprintf(txt,"  %03u  ",cmines);break;  
                                 case 11:sprintf(txt,"%.3s    ",infostr3[k]);break;  
                                 case 12:  
                                 case 13:sprintf(txt,"%.2s     ",infostr3[k]);break;  
                                 default:txt[0]=EOS;  
                         }  
                         setcolor(I_NUMCOLOR);  
                         outtext(txt);  
                 }                  }
                   setcolor(I_NUMCOLOR);
                   outtext(txt);
         }          }
         showmouse();          showmouse();
 } /* }}} */  } /* }}} */
Line 774  BYTE DoAll(void) /* {{{ */
Line 796  BYTE DoAll(void) /* {{{ */
                                                         hidemouse();                                                          hidemouse();
                                                         putimage(getmaxx()/2-150,getmaxy()/2-20,pictmp,COPY_PUT);                                                          putimage(getmaxx()/2-150,getmaxy()/2-20,pictmp,COPY_PUT);
                                                         showmouse();                                                          showmouse();
   #if ASSERTION_USAGE
                                                           assert(pictmp != NULL);
   #endif
                                                         free(pictmp);                                                          free(pictmp);
                                                 }                                                  }
                                                 settextstyle(0,0,itabsize+1);                                                  settextstyle(0,0,itabsize+1);
Line 790  BYTE DoAll(void) /* {{{ */
Line 815  BYTE DoAll(void) /* {{{ */
                         break;                          break;
                 } /* All mines discovered */                  } /* All mines discovered */
                 if (cminesold != cmines) { /* Update Mines */                  if (cminesold != cmines) { /* Update Mines */
                         char txt[6]=" ÛÛÛ ";                          char txt[30]=" ÛÛÛ ";
                         if (cminesold>999) {                          if (cminesold>999) {
                                 txt[0]=txt[1];                                  txt[0]=txt[1];
                                 txt[4]=EOS;                                  txt[4]=EOS;
Line 808  BYTE DoAll(void) /* {{{ */
Line 833  BYTE DoAll(void) /* {{{ */
                 }                  }
                 if ((unsigned)(curr/CLOCKS_PER_SEC)!=(unsigned)(clock()/CLOCKS_PER_SEC)) {                  if ((unsigned)(curr/CLOCKS_PER_SEC)!=(unsigned)(clock()/CLOCKS_PER_SEC)) {
                         /* Update Time */                          /* Update Time */
                         char txt[9] = "Û ÛÛ ÛÛ";                          char txt[30] = "Û ÛÛ ÛÛ";
                         curr = clock();                          curr = clock();
                         if (isininfo(x,y))                          if (isininfo(x,y))
                                 hidemouse();                                  hidemouse();
Line 825  BYTE DoAll(void) /* {{{ */
Line 850  BYTE DoAll(void) /* {{{ */
                         if (isininfo(x,y))                          if (isininfo(x,y))
                                 showmouse();                                  showmouse();
                 }                  }
                 if (but&&isininfo(x,y)) {                  if (but && isininfo(x, y)) {
                         WORD xx,yy;                          int xx,yy;
                         while (!releasebutton(but-1,&xx,&yy))                          while (! releasebutton(but - 1, (WORD *) &xx, (WORD *) &yy))
                                 if (kbhit()) /* catching characters */                                  if (kbhit()) /* catching characters */
                                         getch(); /* in keyboard buffer  */                                          getch(); /* in keyboard buffer  */
                         hidemouse();                          hidemouse();
                         if (xx!=x||yy!=y)                          if (xx!=x||yy!=y)
                                 WriteInfo(xx-(x-infox),yy-(y-infoy));                                  WriteInfo(xx - (int) (x - infox), yy - (int) (y - infoy));
                         showmouse();                          showmouse();
                         but=0;                          but=0;
                 }                  }
Line 846  BYTE DoAll(void) /* {{{ */
Line 871  BYTE DoAll(void) /* {{{ */
                 if ((x!=xold||y!=yold)) {                  if ((x!=xold||y!=yold)) {
                         /* Position change */                          /* Position change */
                         if (xold<nx&&yold<ny&&sqpress(xold,yold)&&!sqopen(xold,yold)) {                          if (xold<nx&&yold<ny&&sqpress(xold,yold)&&!sqopen(xold,yold)) {
                                 sqpress(xold,yold)=NO;                                  set_sqpress(xold, yold, NO);
                                 hidemouse();                                  hidemouse();
                                 SetSquare(xold,yold,1);                                  SetSquare(xold,yold,1);
                                 showmouse();                                  showmouse();
Line 864  BYTE DoAll(void) /* {{{ */
Line 889  BYTE DoAll(void) /* {{{ */
                                 /* Right button pressed */                                  /* Right button pressed */
                                 mlstant=but;                                  mlstant=but;
                                 switch (((sqmark(x,y)+(!sqmark(x,y)&&!cmines?2:1))%3)) {                                  switch (((sqmark(x,y)+(!sqmark(x,y)&&!cmines?2:1))%3)) {
                                         case 1:cmines--;sqmark(x,y)=1;break;                                          case 1:  cmines--; set_sqmark(x, y, 1); break;
                                         case 2:if (sqmark(x,y)==1)cmines++;sqmark(x,y)=2;break;                                          case 2:  if (sqmark(x, y) == 1) cmines++; set_sqmark(x, y, 2); break;
                                         default:sqmark(x,y)=0;break;                                          default: set_sqmark(x, y, 0); break;
                                 }                                  }
                                 hidemouse();                                  hidemouse();
                                 SetSquare(x,y,1);                                  SetSquare(x,y,1);
Line 874  BYTE DoAll(void) /* {{{ */
Line 899  BYTE DoAll(void) /* {{{ */
                         } else if (but == 1 &&                          } else if (but == 1 &&
                                         ! sqopen(x, y) && ! sqpress(x, y) && sqmark(x, y) != 1) {                                          ! sqopen(x, y) && ! sqpress(x, y) && sqmark(x, y) != 1) {
                                 /* Left button pressed and square not pressed */                                  /* Left button pressed and square not pressed */
                                 sqpress(x,y)=YES;                                  set_sqpress(x, y, YES);
                                 hidemouse();                                  hidemouse();
                                 SetSquare(x,y,0);                                  SetSquare(x,y,0);
                                 showmouse();                                  showmouse();
Line 1123  char ineprogtext[]="\
Line 1148  char ineprogtext[]="\
                                                 if (kbhit())                                                  if (kbhit())
                                                         getch();                                                          getch();
                                         hidemouse();putimage(229,374,safe,COPY_PUT);showmouse();                                          hidemouse();putimage(229,374,safe,COPY_PUT);showmouse();
   #if ASSERTION_USAGE
                                           assert(safe != NULL);
   #endif
                                         free(safe);                                          free(safe);
                                         x=y=0;                                          x = y = 0;
                                 }                                  }
                                 if (isinnormbutton(x,y,getmaxx()/2,getmaxy()-93)) {                                  if (isinnormbutton(x,y,getmaxx()/2,getmaxy()-93)) {
                                         x=y=0xffff;                                          x=y=0xffff;
Line 1231  void OpenSquare(WORD x, WORD y) /* {{{ *
Line 1259  void OpenSquare(WORD x, WORD y) /* {{{ *
         register int a,b;          register int a,b;
   
         settextstyle(0,0,1);          settextstyle(0,0,1);
         sqopen(x,y)=YES;          set_sqopen(x, y, YES);
         sqclosed--;          sqclosed--;
         if ((num[0]=value(x,y)) != 0) {          if ((num[0]=value(x,y)) != 0) {
                 setcolor(ColorConvert(num[0]));                  setcolor(ColorConvert(num[0]));
Line 1452  BYTE YesNo(int x,int y) /* {{{ */
Line 1480  BYTE YesNo(int x,int y) /* {{{ */
         showmouse();          showmouse();
         ret=menu(yesnostr,x+28,y+5,0,2,17,RED,LIGHTGREEN);          ret=menu(yesnostr,x+28,y+5,0,2,17,RED,LIGHTGREEN);
         hidemouse();putimage(x,y,safe,COPY_PUT);showmouse();          hidemouse();putimage(x,y,safe,COPY_PUT);showmouse();
   #if ASSERTION_USAGE
           assert(safe != NULL);
   #endif
         free(safe);          free(safe);
         return ret ? NO : YES;          return ret ? NO : YES;
 } /* }}} */  } /* }}} */

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top