⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpegsol.c

📁 JavaScript 计数器的游戏。要运行这个游戏
💻 C
📖 第 1 页 / 共 3 页
字号:
	       (bx == sel_peg_x+2 && by == sel_peg_y && board[bx-1][by].peg) ||	       (bx == sel_peg_x-2 && by == sel_peg_y && board[bx+1][by].peg)))	    {	      gnome_canvas_item_move (item,				      bx*CELL_SIZE + CELL_SIZE/2 + board[bx][by].indent-x,				      by*CELL_SIZE + CELL_SIZE/2-y);	      x = bx*CELL_SIZE + CELL_SIZE/2 + board[bx][by].indent;	      y = by*CELL_SIZE + CELL_SIZE/2;	    }	  else	    {	      gnome_canvas_item_move(item, new_x - x, new_y - y);	      x = new_x;	      y = new_y;	    }        }      break;    case GDK_BUTTON_RELEASE:      if (dragging)	dragging = FALSE;      else	return FALSE;      gnome_canvas_item_ungrab (item, event->button.time);      scale_peg (item, x, y, (STILL_PEG_SIZE/MOVING_PEG_SIZE));      gnome_canvas_item_raise_to_top (item);      drop_peg ((x-get_indent(y/CELL_SIZE)*CELL_SIZE/2)/CELL_SIZE,		y/CELL_SIZE);      gnome_canvas_item_move (item,			      org_x - x + CELL_SIZE/2,			      org_y - y + CELL_SIZE/2);            break;          default:      return FALSE;      break;    }        return TRUE;}static intget_board_size (enum game_types new_type){  switch (new_type)    {    case 0:    case 1:    case 2:    case 3:    case 4:    case 5:    case 6:    case 7:    case 8:    case 9:      return 7;    case 10:      return 6;    case 11:      return 10;    case 12:    case 13:      return 8;    case 14:      return 6;    case 15:    case 16:      return 9;    default:      return 7;    }}/* set_cell: Sets the values for the hole and the peg in a single board cell.  */static voidset_cell (struct board_cell *board_cell, int value){  if (value == 2)    {      board_cell->peg = TRUE;      board_cell->hole = TRUE;    }  else if (value == 1)    {      board_cell->peg = FALSE;      board_cell->hole = TRUE;    }  else /* value == 0 */    {      board_cell->peg = FALSE;      board_cell->hole = FALSE;    }}static voidset_board (struct board_cell target_board[MAX_BOARD_SIZE][MAX_BOARD_SIZE],	   enum game_types new_type){  int x, y;  switch (new_type)    {    case CROSS:      {	int board_values [7][7] = {	  {0,0,1,1,1,0,0},	  {0,0,1,2,1,0,0},	  {1,1,2,2,2,1,1},	  {1,1,1,2,1,1,1},	  {1,1,1,2,1,1,1},	  {0,0,1,1,1,0,0},	  {0,0,1,1,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case PLUS:      {	int board_values [7][7] = {	  {0,0,1,1,1,0,0},	  {0,0,1,2,1,0,0},	  {1,1,1,2,1,1,1},	  {1,2,2,2,2,2,1},	  {1,1,1,2,1,1,1},	  {0,0,1,2,1,0,0},	  {0,0,1,1,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case FIREPLACE:      {	int board_values [7][7] = {	  {0,0,2,2,2,0,0},	  {0,0,2,2,2,0,0},	  {1,1,2,2,2,1,1},	  {1,1,2,1,2,1,1},	  {1,1,1,1,1,1,1},	  {0,0,1,1,1,0,0},	  {0,0,1,1,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case UP_ARROW:      {	int board_values [7][7] = {	  {0,0,1,2,1,0,0},	  {0,0,2,2,2,0,0},	  {1,2,2,2,2,2,1},	  {1,1,1,2,1,1,1},	  {1,1,1,2,1,1,1},	  {0,0,2,2,2,0,0},	  {0,0,2,2,2,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case PYRAMID:      {	int board_values [7][7] = {	  {0,0,1,1,1,0,0},	  {0,0,1,2,1,0,0},	  {1,1,2,2,2,1,1},	  {1,2,2,2,2,2,1},	  {2,2,2,2,2,2,2},	  {0,0,1,1,1,0,0},	  {0,0,1,1,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case DIAMOND:      {	int board_values [7][7] = {	  {0,0,1,2,1,0,0},	  {0,0,2,2,2,0,0},	  {1,2,2,2,2,2,1},	  {2,2,2,1,2,2,2},	  {1,2,2,2,2,2,1},	  {0,0,2,2,2,0,0},	  {0,0,1,2,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case LONGBOW:      {	int board_values [7][7] = {	  {0,0,1,1,1,0,0},	  {0,0,1,1,1,0,0},	  {2,1,1,1,1,1,2},	  {2,2,1,2,1,2,2},	  {1,2,1,2,1,2,1},	  {0,0,2,2,2,0,0},	  {0,0,1,2,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case CROSSBOW:      {	int board_values [7][7] = {	  {0,0,1,1,1,0,0},	  {0,0,1,1,1,0,0},	  {1,1,1,1,1,1,1},	  {1,2,2,1,2,2,1},	  {1,2,2,2,2,2,1},	  {0,0,1,2,1,0,0},	  {0,0,1,1,1,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case SOLITARE:      {	int board_values [7][7] = {	  {0,0,2,2,2,0,0},	  {0,0,2,2,2,0,0},	  {2,2,2,2,2,2,2},	  {2,2,2,1,2,2,2},	  {2,2,2,2,2,2,2},	  {0,0,2,2,2,0,0},	  {0,0,2,2,2,0,0}	};		board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case FRENSH:      {	int board_values [7][7] = {	  {0,0,2,2,2,0,0},	  {0,2,2,2,2,2,0},	  {2,2,2,2,2,2,2},	  {2,2,2,1,2,2,2},	  {2,2,2,2,2,2,2},	  {0,2,2,2,2,2,0},	  {0,0,2,2,2,0,0}	};	board_size = 7;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case SQUARE:      {	int board_values [6][6] = {	  {2,2,2,2,2,2},	  {2,2,2,2,2,2},	  {2,2,1,2,2,2},	  {2,2,2,2,2,2},	  {2,2,2,2,2,2},	  {2,2,2,2,2,2}	};	board_size = 6;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case DRAUGHTSBOARD:      {	int board_values [10][10] = {	  {0,0,0,0,2,2,0,0,0,0},	  {0,0,0,2,2,2,2,0,0,0},	  {0,0,2,2,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,2,2,0},	  {2,2,2,2,2,1,2,2,2,2},	  {2,2,2,2,2,2,2,2,2,2},	  {0,2,2,2,2,2,2,2,2,0},	  {0,0,2,2,2,2,2,2,0,0},	  {0,0,0,2,2,2,2,0,0,0},	  {0,0,0,0,2,2,0,0,0,0}	};		board_size = 10;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case THE_X:      {	int board_values [8][8] = {	  {2,2,2,0,0,2,2,2},	  {2,2,2,0,0,2,2,2},	  {2,2,2,2,2,2,2,2},	  {0,0,2,1,2,2,0,0},	  {0,0,2,2,1,2,0,0},	  {2,2,2,2,2,2,2,2},	  {2,2,2,0,0,2,2,2},	  {2,2,2,0,0,2,2,2}	};	board_size = 8;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case BIG_DIAMOND:      {	int board_values [8][8] = {	  {0,0,0,1,2,0,0,0},	  {0,0,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,0},	  {2,2,2,2,2,2,2,2},	  {2,2,2,2,2,2,2,2},	  {0,2,2,2,2,2,2,0},	  {0,0,2,2,2,2,0,0},	  {0,0,0,2,1,0,0,0}	};	board_size = 8;	hex_struct = FALSE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case TRIANGULAR:      {	int board_values [6][6] = {	  {0,0,2,0,0,0},	  {0,0,2,2,0,0},	  {0,2,1,2,0,0},	  {0,2,2,2,2,0},	  {2,2,2,2,2,0},	  {2,2,2,2,2,2}	};	board_size = 6;	hex_struct = TRUE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case HEXAGONAL:      {	int board_values [9][9] = {	  {0,0,2,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,2,0},	  {2,2,2,2,2,2,2,2,0},	  {2,2,2,2,1,2,2,2,2},	  {2,2,2,2,2,2,2,2,0},	  {0,2,2,2,2,2,2,2,0},	  {0,2,2,2,2,2,2,0,0},	  {0,0,2,2,2,2,2,0,0}	};	board_size = 9;	hex_struct = TRUE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    case STELLAR:      {	int board_values [9][9] = {	  {0,0,0,0,2,0,0,0,0},	  {0,0,0,2,2,0,0,0,0},	  {0,2,2,1,2,2,2,2,0},	  {0,2,2,2,2,2,2,0,0},	  {0,0,2,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,0,0},	  {0,2,2,2,2,2,2,2,0},	  {0,0,0,2,2,0,0,0,0},	  {0,0,0,0,2,0,0,0,0}	};	board_size = 9;	hex_struct = TRUE;	for (x = 0; x < board_size; x++)	  for (y = 0; y < board_size; y++)	    set_cell (&target_board[x][y], board_values[y][x]);	break;      }    }  for (x = 0; x < board_size; x++)    for (y = 0; y < board_size; y++)      {	if (get_indent(y))	  target_board[x][y].indent = CELL_SIZE/2;	else	  target_board[x][y].indent = 0;      }}static voiddraw_line (GnomeCanvasGroup *group,	    int x1, int y1, int x2, int y2, double thickness, char *color){  GnomeCanvasPoints *points;  points = gnome_canvas_points_new (2);  points->coords[0] = x1;  points->coords[1] = y1;  points->coords[2] = x2;  points->coords[3] = y2;  gnome_canvas_item_new (group,			 gnome_canvas_line_get_type (),			 "points", points,			 "fill_color", color,			 "width_units", thickness,			 NULL);  gnome_canvas_points_free (points);}static voiddraw_arc (GnomeCanvasGroup *group,	  double x, double y, double w, double h,	  int start, int lenght, double thickness, char *color){	GnomeCanvasPoints *points;	int i;	points = gnome_canvas_points_new ((20 * lenght / 360)+1);	for (i = 0; i <= 2*(20 * lenght / 360); i+=2)	  {	    points->coords[i] = x + w/2 - (w/2) * sin ((lenght * i/(2*(20 * lenght / 360))+start) * 2 * 3.14 / 360);	    points->coords[i+1] = y + h/2 + (h/2) * cos ((lenght * i/(2*(20 * lenght / 360))+start) * 2 * 3.14 / 360);	  }	gnome_canvas_item_new (group,			       gnome_canvas_line_get_type (),			       "points", points,			       "fill_color", color,			       "width_units", thickness,			       NULL);	gnome_canvas_points_free (points);}/* set_pegs: Creates the peg objects and destroys the old.  */static voidset_pegs (void){  int x, y;  for (x = 0; x < MAX_BOARD_SIZE; x++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -