Gnomine - first click...



Hi,

	A patch to make gnomine slightly easier to play, to give you a
chance at the first click.

	HTH,

		Michael Meeks.

-- 
 michael@imaginator.com  <><, Pseudo Engineer, itinerant idiot
diff -r -c5 gnomine/ChangeLog gnomine-hacked/ChangeLog
*** gnomine/ChangeLog	Sun May 17 22:24:00 1998
--- gnomine-hacked/ChangeLog	Mon May 18 13:52:24 1998
***************
*** 1,5 ****
--- 1,14 ----
+ 1998-05-18 Michael Meeks <michael@imaginator.com>
+ 
+ 	* minefield.c: Add 'first click is nice' ie. a hole or un-mined tile
+ 	               if possible.
+                        NB. as an offset is added to every ->mines[index], it
+ 	               is vital to use cell_idx for every index calculation.
+ 	               NB. cell_idx (f, x, y) returns what is seen on the
+ 	               screen in cell (x, y) as previously, as expected.
+ 
  1998-05-17 Timo Sirainen <a@sicom.fi>
  
  	* minefield.c: Marking two mines fast resulted as doubleclick and
  	               didn't work right
  	* minefield.c: Changed multi press behaviour so that it always
diff -r -c5 gnomine/minefield.c gnomine-hacked/minefield.c
*** gnomine/minefield.c	Sun May 17 22:24:01 1998
--- gnomine-hacked/minefield.c	Mon May 18 13:51:02 1998
***************
*** 51,65 ****
  
  static GtkWidgetClass *parent_class;
  
  static inline gint cell_idx(GtkMineField *mfield, guint x, guint y)
  {
! 	if (x>=0 && x<mfield->xsize && y>=0 && y<mfield->ysize)
! 		return x+y*mfield->xsize;
! 	return -1;
  }
  
  static void _setup_sign (sign *signp, char **data)
  {
  	GdkImlibImage *image;
  
          image = gdk_imlib_create_image_from_xpm_data(data);
--- 51,120 ----
  
  static GtkWidgetClass *parent_class;
  
  static inline gint cell_idx(GtkMineField *mfield, guint x, guint y)
  {
!   if (x>=0 && x<mfield->xsize && y>=0 && y<mfield->ysize)
!     {    
!       int c ;
!       c = x + y*mfield->xsize - mfield->offset ;
!       if (c<0) c+= mfield->xsize*mfield->ysize ;
!       return c ;
!     }
!   return -1;
! }
! 
! static guint gtk_minefield_centre_hole (GtkMineField *mfield)
! {
!   int nx, ny, i, n, cidx ;
! 
!   mfield->offset = 0 ;
!   for (nx=1;nx<mfield->xsize-1;nx++) /* First try and find a good place */
!     for (ny=1;ny<mfield->ysize-1;ny++) {
! 	if (mfield->mines[cell_idx(mfield, nx, ny)].mined)
! 	  continue ;
! 	n = 0 ;
! 	for (i=0;i<8;i++)
! 	  if ((cidx = cell_idx(mfield, nx+neighbour_map[i].x,
! 			       ny+neighbour_map[i].y)) != -1) {
! 	    if (mfield->mines[cidx].mined) n++;
! 	  }
! 	if (n==0)
! 	  return (nx + ny*mfield->xsize) ;
!     }
!   /* Then find an un-mined tile */
!   for (cidx=0;cidx<mfield->xsize*mfield->ysize;cidx++)
!     if (!mfield->mines[cidx].mined)
!       return cidx ;
!   return 0 ;
! }
! 
! static void gtk_minefield_centre_grid (GtkMineField *mfield, guint x, guint y)
! {
!   int nx, ny, n, i, cidx ;
! 
!   mfield->offset = x + y*mfield->xsize - gtk_minefield_centre_hole(mfield) ;
!   if (mfield->offset<0)
!     mfield->offset+= mfield->xsize*mfield->ysize ;
! 
!   for (nx=0; nx<mfield->xsize; nx++) {
!     for (ny=0; ny<mfield->ysize; ny++) {
!       n = 0;
!       for (i=0; i<8; i++) {
! 	if ((cidx = cell_idx(mfield, nx+neighbour_map[i].x,
! 			     ny+neighbour_map[i].y)) != -1) {
! 	    if (mfield->mines[cidx].mined) n++;
! 	  }
!       }
!       cidx = cell_idx(mfield, nx, ny) ;
!       mfield->mines[cidx].neighbours = n;
!     }
!   }
!   mfield->untouched = 0 ;
  }
  
+ 
  static void _setup_sign (sign *signp, char **data)
  {
  	GdkImlibImage *image;
  
          image = gdk_imlib_create_image_from_xpm_data(data);
***************
*** 436,446 ****
          guint x, y, c;
  
  	for (x = 0; x < mfield->xsize; x++)
  		for (y = 0; y < mfield->ysize; y++)
                  {
!                         c = x+y*mfield->xsize;
                          if (mfield->mines[c].shown == 0 && mfield->mines[c].marked == 0)
                          {
                                  mfield->mines[c].marked = 1;
                                  gtk_mine_draw(mfield, x, y);
                          }
--- 491,501 ----
          guint x, y, c;
  
  	for (x = 0; x < mfield->xsize; x++)
  		for (y = 0; y < mfield->ysize; y++)
                  {
! 		        c = cell_idx(mfield, x, y) ;
                          if (mfield->mines[c].shown == 0 && mfield->mines[c].marked == 0)
                          {
                                  mfield->mines[c].marked = 1;
                                  gtk_mine_draw(mfield, x, y);
                          }
***************
*** 451,461 ****
          mfield->win = 1;
  }
  
  static void gtk_minefield_show(GtkMineField *mfield, guint x, guint y)
  {
! 	int c = x+mfield->xsize*y;
  	
          if (mfield->mines[c].marked != 1 && mfield->mines[c].shown != 1) {
  		mfield->mines[c].shown = 1;
  		mfield->shown++;
                  gtk_mine_draw(mfield, mfield->cdownx, mfield->cdowny);
--- 506,516 ----
          mfield->win = 1;
  }
  
  static void gtk_minefield_show(GtkMineField *mfield, guint x, guint y)
  {
! 	int c = cell_idx (mfield, x, y) ;
  	
          if (mfield->mines[c].marked != 1 && mfield->mines[c].shown != 1) {
  		mfield->mines[c].shown = 1;
  		mfield->shown++;
                  gtk_mine_draw(mfield, mfield->cdownx, mfield->cdowny);
***************
*** 471,480 ****
--- 526,537 ----
  }
  
  static void gtk_minefield_toggle_mark(GtkMineField *mfield, guint x, guint y)
  {
          int c = cell_idx(mfield, x, y);
+ 	if (mfield->shown == 0)
+ 	  return ;
          if (mfield->mines[c].shown == 0) {
  		if ((mfield->mines[c].marked = 1-mfield->mines[c].marked) == 1) {
  			mfield->flags++;
  		} else {
  			mfield->flags--;
***************
*** 567,578 ****
          if (mfield->lose || mfield->win) return FALSE;
  
          if (mfield->bdown[0] || mfield->bdown[1]) {
                  x = event->x/minesize;
                  y = event->y/minesize;
!                 c = x+y*(mfield->xsize);
! 
                  if (c != mfield->cdown) {
                          mfield->mines[mfield->cdown].down = 0;
                          gtk_mine_draw(mfield, mfield->cdownx, mfield->cdowny);
  
                          multi = mfield->multi_mode;
--- 624,634 ----
          if (mfield->lose || mfield->win) return FALSE;
  
          if (mfield->bdown[0] || mfield->bdown[1]) {
                  x = event->x/minesize;
                  y = event->y/minesize;
! 		c = cell_idx (mfield, x, y) ;
                  if (c != mfield->cdown) {
                          mfield->mines[mfield->cdown].down = 0;
                          gtk_mine_draw(mfield, mfield->cdownx, mfield->cdowny);
  
                          multi = mfield->multi_mode;
***************
*** 604,614 ****
  	if (mfield->lose || mfield->win) return FALSE;
  	
          if (event->button <= 3 && !mfield->bdown[1]) {
                  x = event->x/minesize;
                  y = event->y/minesize;
!                 c = x+y*(mfield->xsize);
                  if (!mfield->bdown[0] && !mfield->bdown[1] && !mfield->bdown[2]) {
                          mfield->cdownx = x;
                          mfield->cdowny = y;
                          mfield->cdown = c;
                          mfield->mines[c].down = 1;
--- 660,670 ----
  	if (mfield->lose || mfield->win) return FALSE;
  	
          if (event->button <= 3 && !mfield->bdown[1]) {
                  x = event->x/minesize;
                  y = event->y/minesize;
! 		c = cell_idx (mfield, x, y) ;
                  if (!mfield->bdown[0] && !mfield->bdown[1] && !mfield->bdown[2]) {
                          mfield->cdownx = x;
                          mfield->cdowny = y;
                          mfield->cdown = c;
                          mfield->mines[c].down = 1;
***************
*** 650,661 ****
                      mfield->bdown[1] = 1;
                      mfield->bdown[2] = 0;
                      event->button = 2;
                  }
                  switch (event->button) {
!                 case 1: gtk_minefield_show(mfield, mfield->cdownx, mfield->cdowny);
!                         break;
                  case 2: if (mfield->multi_mode) gtk_minefield_multi_release(mfield, mfield->cdownx, mfield->cdowny, mfield->cdown, 1);
                          break;
                  }
  		if (!mfield->lose && !mfield->win) {
  			gtk_signal_emit(GTK_OBJECT(mfield),
--- 706,720 ----
                      mfield->bdown[1] = 1;
                      mfield->bdown[2] = 0;
                      event->button = 2;
                  }
                  switch (event->button) {
!                 case 1: 
! 		  if (mfield->untouched)
! 		    gtk_minefield_centre_grid(mfield, mfield->cdownx, mfield->cdowny) ;
! 		  gtk_minefield_show(mfield, mfield->cdownx, mfield->cdowny);
! 		  break;
                  case 2: if (mfield->multi_mode) gtk_minefield_multi_release(mfield, mfield->cdownx, mfield->cdowny, mfield->cdown, 1);
                          break;
                  }
  		if (!mfield->lose && !mfield->win) {
  			gtk_signal_emit(GTK_OBJECT(mfield),
***************
*** 857,875 ****
  		tmp = mfield->mines[i].mined;
  		mfield->mines[i].mined = mfield->mines[j].mined;
  		mfield->mines[j].mined = tmp;
  	}
  
! 	for (x=0; x<mfield->xsize; x++) {
! 		for (y=0; y<mfield->ysize; y++) {
! 			n = 0;
! 			for (i=0; i<8; i++) {
! 				if ((cidx = cell_idx(mfield, x+neighbour_map[i].x,
! 						     y+neighbour_map[i].y)) != -1) {
! 					if (mfield->mines[cidx].mined) n++;
! 				}
! 			}
!                         mfield->mines[x+mfield->xsize*y].neighbours = n;
! 		}
! 	}
  }
- 
--- 916,923 ----
  		tmp = mfield->mines[i].mined;
  		mfield->mines[i].mined = mfield->mines[j].mined;
  		mfield->mines[j].mined = tmp;
  	}
  
! 	mfield->untouched = 1 ;
! 	mfield->offset = 0 ;
  }
diff -r -c5 gnomine/minefield.h gnomine-hacked/minefield.h
*** gnomine/minefield.h	Sun May 17 22:24:01 1998
--- gnomine-hacked/minefield.h	Mon May 18 13:49:15 1998
***************
*** 40,56 ****
--- 40,58 ----
      };
    
  struct _GtkMineField {
          GtkWidget widget;
          guint xsize, ysize;
+         gint offset;
          guint mcount;
  	mine *mines;
  	guint flags;
  	guint shown;
  	gint cdown;
          guint cdownx;
          guint cdowny;
+         gint untouched ;
  	gint bdown[3];
          gint lose;
          gint win;
  	gint multi_mode;
          sign flag;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]