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.14 and 1.15

version 1.14, 2003/08/12 20:51:00 version 1.15, 2003/10/27 09:57:36
Line 8 
Line 8 
  * All rights reserved.   * All rights reserved.
  */   */
   
 /* $Platon: games/mines/mines.c,v 1.13 2003/08/03 21:34:19 nepto Exp $ */  /* $Platon: games/mines/mines.c,v 1.14 2003/08/12 20:51:00 nepto Exp $ */
   
 #define PSQUARE_DYNAMIC_ALLOCATION      (0)  #define PSQUARE_DYNAMIC_ALLOCATION      (0)
 #define ASSERTION_USAGE                         (1)  #define ASSERTION_USAGE                         (1)
Line 34 
Line 34 
 #define INFOYSIZE       (textheight(infostr3[0])*INFOLINES+(itabsize+1)*6)  #define INFOYSIZE       (textheight(infostr3[0])*INFOLINES+(itabsize+1)*6)
 #define INFOLINES       (14)  #define INFOLINES       (14)
 #define DEFITABSIZE     (0)  #define DEFITABSIZE     (0)
 #define FADESTEPS       (1)  #define FADESTEPS       (100)
   
 #if PSQUARE_DYNAMIC_ALLOCATION  #if PSQUARE_DYNAMIC_ALLOCATION
 #  define MAXNX         ((getmaxx()+1)/MINBARSIZE)      /* MAXIMUM x size */  #  define MAXNX         ((getmaxx()+1)/MINBARSIZE)      /* MAXIMUM x size */
Line 63 
Line 63 
                 ||isininfo(xoff+x*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 || PLATON_SYSTEM_X11
 #  define FadeIn()              (void)kbhit()  #  define FadeIn()              (void)kbhit()
 #  define FadeOut()             (void)kbhit()  #  define FadeOut()             (void)kbhit()
 #else  #else
Line 132  typedef struct stsquare
Line 132  typedef struct stsquare
         BYTE sqmark;        /* Square is marked */          BYTE sqmark;        /* Square is marked */
 } STSQUARE;  } STSQUARE;
   
   enum desktop_operation
   {
           DESKTOP_SAVE    = 0,
           DESKTOP_RESTORE = 1
   };
   
 /* /////////////////////////////////////////////////////////////////////// */  /* /////////////////////////////////////////////////////////////////////// */
 /* GLOBAL IDENTIFICATORS */  /* GLOBAL IDENTIFICATORS */
 #if PLATON_SYSTEM_MSDOS  #if PLATON_SYSTEM_MSDOS
Line 224  void DrawWindow(WORD x1,WORD y1,WORD x2,
Line 230  void DrawWindow(WORD x1,WORD y1,WORD x2,
 void DrawNormButton(WORD x,WORD y,char*label,char*str,BYTE bckcolor,BYTE rctcolor,BYTE txtcolor);  void DrawNormButton(WORD x,WORD y,char*label,char*str,BYTE bckcolor,BYTE rctcolor,BYTE txtcolor);
 void DrawNumButton(WORD x,WORD y,char*label,WORD num,BYTE bckcolor,BYTE rctcolor,BYTE txtcolor);  void DrawNumButton(WORD x,WORD y,char*label,WORD num,BYTE bckcolor,BYTE rctcolor,BYTE txtcolor);
 void DrawNumPlus10(WORD x,WORD y,BYTE c);  void DrawNumPlus10(WORD x,WORD y,BYTE c);
 BYTE YesNo(int x,int y);  BYTE YesNo();
 BYTE ColorConvert(BYTE value);  BYTE ColorConvert(BYTE value);
 void fade_out(WORD steps);  void fade_out(WORD steps);
 void fade_in(WORD steps);  void fade_in(WORD steps);
   void desktop_save_or_restore(enum desktop_operation op);
   
 /* High scores handling */  /* High scores handling */
 void HscTable(void);  void HscTable(void);
Line 741  BYTE DoAll(void) /* {{{ */
Line 748  BYTE DoAll(void) /* {{{ */
         FadeIn();          FadeIn();
         while (1) {          while (1) {
                 if (kbhit()) {                  if (kbhit()) {
                         if ((but=getch())==ESC) {                          if ((but = getch()) == ESC) {
                                 (void)getmousepos(&x,&y);                                  (void)getmousepos(&x, &y);
                                 if (YesNo(x-27,y-22)==YES)                                  if (YesNo() == YES)
                                         break;                                          break;
                         }                          }
                         if (!but) {                          if (!but) {
                                 switch (but = getch()) {                                  switch (but = getch()) {
                                         case 59: /* F1 */ {                                          case 59: /* F1 */
                                                 register WORD k,l;  
                                                 FILE*tmp=tmpfile();  
                                                 if (tmp==NULL)  
                                                         WriteError();  
                                                 clktmp = clock();  
                                                 hidemouse();                                                  hidemouse();
                                                 for (l=0;l<=getmaxy();l++) {                                                  desktop_save_or_restore(DESKTOP_SAVE);
                                                         for (k=0;k<=getmaxx();k+=2) {  
                                                                 but=getpixel(k,l)+getpixel(k+1,l)*16;  
                                                                 if (fwrite(&but,sizeof(BYTE),1,tmp)!=1)  
                                                                         WriteError();  
                                                                 putpixel(k,l,BLACK);  
                                                                 putpixel(k+1,l,BLACK);  
                                                         }  
                                                 }  
                                                 FadeOut();                                                  FadeOut();
                                                 showmouse();                                                  showmouse();
                                                 Help();                                                  Help();
                                                 hidemouse();                                                  hidemouse();
                                                 rewind(tmp);                                                  desktop_save_or_restore(DESKTOP_RESTORE);
                                                 for (l=0;l<=getmaxy();l++) {  
                                                         for (k=0;k<=getmaxx();k+=2) {  
                                                                 if (fread(&but,sizeof(BYTE),1,tmp)!=1)  
                                                                         WriteError();  
                                                                 putpixel(k,l,but);  
                                                                 putpixel(k+1,l,but/16);  
                                                         }  
                                                 }  
                                                 fclose(tmp);  
                                                 showmouse();                                                  showmouse();
                                                 start+=clock()-clktmp;                                                  break;
                                         }break;                                          case 62: /* F4 */
                                         case 62:/* F4 */ {                                                  hidemouse();
                                                 void*pictmp;                                                  desktop_save_or_restore(DESKTOP_SAVE);
                                                 clktmp=clock();                                                  cleardevice();
                                                 FadeOut();                                                  DrawWindow(getmaxx() / 2 - 150, getmaxy() / 2 - 20,
                                                 HideInfo();                                                                  getmaxx() / 2 + 150, getmaxy() / 2 + 20, 15, 0);
                                                 setpalette(0,0x3f);                                                  settextstyle(0, 0, 2);
                                                 pictmp=malloc(imagesize(getmaxx()/2-150,getmaxy()/2-20,getmaxx()/2+150,getmaxy()/2+20));                                                  outtextxy(getmaxx() / 2, getmaxy() / 2 - 6, "P A U Z A");
                                                 if (pictmp != NULL) {                                                  settextstyle(0, 0, 1);
                                                         hidemouse();                                                  outtextxy(getmaxx() / 2, getmaxy() / 2 + 10, "Klikni sem pre pokracovanie...");
                                                         getimage(getmaxx()/2-150,getmaxy()/2-20,getmaxx()/2+150,getmaxy()/2+20,pictmp);                                                  showmouse();
                                                         DrawWindow(getmaxx()/2-150,getmaxy()/2-20,getmaxx()/2+150,getmaxy()/2+20,1,0);                                                  while ((! releasebutton(0, &x, &y) || ! isinbar(x, y,
                                                         settextstyle(0,0,2);                                                                                  getmaxx() / 2 - 150, getmaxy() / 2 - 20,
                                                         outtextxy(getmaxx()/2,getmaxy()/2-6,"P A U Z A");                                                                                  getmaxx() / 2 + 150, getmaxy() / 2 + 20)))
                                                         settextstyle(0,0,1);                                                  {
                                                         outtextxy(getmaxx()/2,getmaxy()/2+10,"Klikni sem pre pokracovanie...");                                                          while (kbhit())
                                                         showmouse();                                                                  getch();
                                                 }  
                                                 while ((!releasebutton(0,&x,&y)  
                                                         ||!isinbar(x,y,getmaxx()/2-150,getmaxy()/2-20,getmaxx()/2+150,getmaxy()/2+20)))  
                                                 if (kbhit())  
                                                         getch();  
                                                 if (pictmp!=NULL) {  
                                                         hidemouse();  
                                                         putimage(getmaxx()/2-150,getmaxy()/2-20,pictmp,COPY_PUT);  
                                                         showmouse();  
 #if ASSERTION_USAGE  
                                                         assert(pictmp != NULL);  
 #endif  
                                                         free(pictmp);  
                                                 }                                                  }
                                                 settextstyle(0,0,itabsize+1);                                                  hidemouse();
                                                 ShowInfo();                                                  desktop_save_or_restore(DESKTOP_RESTORE);
                                                 FadeIn();                                                  showmouse();
                                                 start+=clock()-clktmp;                                                  break;
                                         } break;  
                                 }                                  }
                         }                          }
                 }                  }
Line 861  BYTE DoAll(void) /* {{{ */
Line 832  BYTE DoAll(void) /* {{{ */
                                 showmouse();                                  showmouse();
                 }                  }
                 if (but && isininfo(x, y)) {                  if (but && isininfo(x, y)) {
                         int xx,yy;                          register int diff_x, diff_y;
                           WORD xx, yy;
                         while (! releasebutton(but - 1, (WORD *) &xx, (WORD *) &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();                          diff_x = xx - x;
                         if (xx!=x||yy!=y)                          diff_y = yy - y;
                                 WriteInfo(xx - (int) (x - infox), yy - (int) (y - infoy));                          if (diff_x != 0 || diff_y != 0)
                         showmouse();                                  WriteInfo((int) infox + diff_x, (int) infoy + diff_y);
                         but=0;                          but = 0;
                 }                  }
                 but &= 3;                  but &= 3;
                 x = (x-xoff) / barsize;                  x = (x-xoff) / barsize;
Line 1157  char ineprogtext[]="\
Line 1129  char ineprogtext[]="\
                                                         ||!isinnormbutton(x,y,(getmaxx()+229)/2,getmaxy()-38))                                                          ||!isinnormbutton(x,y,(getmaxx()+229)/2,getmaxy()-38))
                                                 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  #if ASSERTION_USAGE
                                         assert(safe != NULL);                                          assert(safe != NULL);
 #endif  #endif
Line 1427  void DrawDefWindow(WORD sizex,WORD y1,WO
Line 1401  void DrawDefWindow(WORD sizex,WORD y1,WO
         DrawWindow((getmaxx()-sizex)/2,y1,getmaxx()-(getmaxx()-sizex)/2,y2,BLUE,WHITE);          DrawWindow((getmaxx()-sizex)/2,y1,getmaxx()-(getmaxx()-sizex)/2,y2,BLUE,WHITE);
         if (text!=NULL) {          if (text!=NULL) {
                 line((getmaxx()-sizex)/2+10,y1+33,getmaxx()-10-(getmaxx()-sizex)/2,y1+33);                  line((getmaxx()-sizex)/2+10,y1+33,getmaxx()-10-(getmaxx()-sizex)/2,y1+33);
                 settextstyle(0,0,2);outtextxy(getmaxx()/2,y1+19,text);                  settextstyle(0, 0, 2);
                   outtextxy(getmaxx() / 2, y1 + 19,text);
         }          }
 } /* }}} */  } /* }}} */
   
Line 1477  void DrawNumPlus10(WORD x,WORD y,BYTE c)
Line 1452  void DrawNumPlus10(WORD x,WORD y,BYTE c)
         }          }
 } /* }}} */  } /* }}} */
   
 BYTE YesNo(int x,int y) /* {{{ */  BYTE YesNo() /* {{{ */
   {
           void*safe;
           register BYTE ret;
           hidemouse();
           HideInfo();
           if ((safe = malloc(imagesize(0, 195, getmaxx(), 325))) == NULL)
                   desktop_save_or_restore(DESKTOP_SAVE);
           getimage(0, 195, getmaxx(), 325, safe);
           DrawDefWindow(420, 195, 325, "Koniec hry?");
           showmouse();
           ret = menu(yesnostr, getmaxx() / 2, 256, 0, 2, 25, RED, LIGHTGREEN);
           settextstyle(0, 0, 1);
           hidemouse();
           if (safe == NULL) {
                   desktop_save_or_restore(DESKTOP_RESTORE);
           } else {
                   putimage(0, 195, safe, COPY_PUT);
                   free(safe);
           }
           ShowInfo();
           showmouse();
           return ret ? NO : YES;
   } /* }}} */
   
   BYTE YesNoOld(int x,int y) /* {{{ */
 {  {
         void*safe;          void*safe;
         register BYTE ret;          register BYTE ret;
Line 1489  BYTE YesNo(int x,int y) /* {{{ */
Line 1489  BYTE YesNo(int x,int y) /* {{{ */
         DrawWindow(x,y,x+56,y+40,BLUE,WHITE);          DrawWindow(x,y,x+56,y+40,BLUE,WHITE);
         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  #if ASSERTION_USAGE
         assert(safe != NULL);          assert(safe != NULL);
 #endif  #endif
Line 1511  BYTE ColorConvert(BYTE c) /* {{{ */
Line 1513  BYTE ColorConvert(BYTE c) /* {{{ */
 void fade_out(WORD steps) /* {{{ */  void fade_out(WORD steps) /* {{{ */
 {  {
         register WORD k,l;          register WORD k,l;
         struct palettetype start_pal,curr_pal;          int size;
           struct palettetype start_pal, curr_pal;
         getpalette(&start_pal);          getpalette(&start_pal);
         curr_pal.size=start_pal.size;          size = start_pal.size;
         for (l=0;l<steps;l++) {          curr_pal.size = size;
                 for (k=0;k<start_pal.size;k++) {          for (l = 0; l < steps; l++) {
                         curr_pal.colors[k]=start_pal.colors[k]*(steps-l-1)/steps;                  for (k = 0; k < size; k++) {
                           curr_pal.colors[k] = start_pal.colors[k] * (steps - l - 1) / steps;
                 }                  }
                 setallpalette(&curr_pal);                  setallpalette(&curr_pal);
         }          }
Line 1524  void fade_out(WORD steps) /* {{{ */
Line 1528  void fade_out(WORD steps) /* {{{ */
   
 void fade_in(WORD steps) /* {{{ */  void fade_in(WORD steps) /* {{{ */
 {  {
         register WORD k,l;          register WORD k, l;
           int size = getdefaultpalette()->size;
         struct palettetype curr_pal;          struct palettetype curr_pal;
         curr_pal.size=getdefaultpalette()->size;          curr_pal.size = size;
         for (l=0;l<steps;l++) {          for (l = 0; l < steps; l++) {
                 for (k=0;k<getdefaultpalette()->size;k++)                  for (k = 0; k < size; k++) {
                         curr_pal.colors[k]=getdefaultpalette()->colors[k]*(l+1)/steps;                          curr_pal.colors[k] = getdefaultpalette()->colors[k] * (l + 1) / steps;
                   }
                 setallpalette(&curr_pal);                  setallpalette(&curr_pal);
         }          }
 } /* }}} */  } /* }}} */
   
   void desktop_save_or_restore(enum desktop_operation op) /* {{{ */
   {
           static void *buffer  = NULL;
           static FILE *fhandle = NULL;
           static int   bufsize = 0;
           static int   y_size  = 0;
           register int i;
           if (op == DESKTOP_SAVE) {
                   if (buffer != NULL) {
                           free(buffer);
                           buffer = NULL;
                   }
                   if (fhandle != NULL) {
                           fclose(fhandle);
                           fhandle = NULL;
                   }
                   for (y_size = getmaxy() + 1; ; y_size = (y_size / 2) + 1) {
                           bufsize = imagesize(0, 0, getmaxx(), y_size - 1);
                           if ((buffer = malloc(bufsize)) != NULL)
                                   break;
   #if PLATON_SYSTEM_X11
                           /* Desktop save/restore disk swapping/storage mechanism does not
                              properly work with X11 pixmaps due to known issues (see notes
                              nead getimage()/putimage in x11-bgi.c file). Thus if we failed
                              to allocate 8 bytes size buffer, we exit immidiatelly. */
                           WriteError();
   #endif
                   }
                   if (y_size <= getmaxy()) {
                           if ((fhandle = tmpfile()) == NULL)
                                   WriteError();
                   }
                   for (i = 0; i <= getmaxy(); i += y_size) {
   #if 0
                           fprintf(stderr, "getimage(0, %d, %d, %d, %p);\n",
                                           i, getmaxx(), min(getmaxy(), i + y_size - 1), buffer);
   #endif
                           getimage(0, i, getmaxx(), min(getmaxy(), i + y_size - 1), buffer);
                           if (i + y_size < getmaxy()) {
                                   if (fwrite(buffer, bufsize, 1, fhandle) != 1)
                                           WriteError();
                           }
                   }
           } else if (op == DESKTOP_RESTORE) {
                   if (fhandle != NULL)
                           rewind(fhandle);
                   for (i = 0; i < getmaxy() + 1 - y_size; i += y_size)
                           ;
   #if 0
                   fprintf(stderr, "putimage(0, %d, %p, COPY_PUT);\n", i, buffer);
   #endif
                   putimage(0, i, buffer, COPY_PUT);
                   for (i -= y_size; i >= 0; i -= y_size) {
                           if (fread(buffer, bufsize, 1, fhandle) != 1)
                                   WriteError();
                           putimage(0, i, buffer, COPY_PUT);
                   }
                   if (buffer != NULL) {
                           free(buffer);
                           buffer = NULL;
                   }
                   if (fhandle != NULL) {
                           fclose(fhandle);
                           fhandle = NULL;
                   }
           }
   } /* }}} */
   
 /* /////////////////////////////////////////////// */  /* /////////////////////////////////////////////// */
 void HscTable(void) /* {{{ */  void HscTable(void) /* {{{ */
 {  {

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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