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

📄 gpegsol.c

📁 JavaScript 计数器的游戏。要运行这个游戏
💻 C
📖 第 1 页 / 共 3 页
字号:
    for (y = 0; y < MAX_BOARD_SIZE; y++)      {	if (peg_group[x][y])	  gtk_object_destroy (GTK_OBJECT(peg_group[x][y]));	peg_group[x][y] =	  GNOME_CANVAS_GROUP(gnome_canvas_item_new			     (gnome_canvas_root (canvas),			      gnome_canvas_group_get_type (),			      "x",0.0,			      "y",0.0,			      NULL));	if (x < board_size && y < board_size && board[x][y].hole)	  {	    gnome_canvas_item_new (peg_group[x][y],			   gnome_canvas_ellipse_get_type (),			   "x1", x * CELL_SIZE + (CELL_SIZE - STILL_PEG_SIZE)/2 + board[x][y].indent,			   "y1", y * CELL_SIZE + (CELL_SIZE - STILL_PEG_SIZE)/2,			   "x2", (x + 1) * CELL_SIZE - (CELL_SIZE - STILL_PEG_SIZE)/2 + board[x][y].indent,			   "y2", (y + 1) * CELL_SIZE - (CELL_SIZE - STILL_PEG_SIZE)/2,			   "fill_color", "blue",			   "outline_color", "black",			   "width_units", 0.8,			   NULL);	    draw_arc (peg_group[x][y],		      x*CELL_SIZE+CELL_SIZE/3 + board[x][y].indent,		      y*CELL_SIZE+CELL_SIZE/3,		      CELL_SIZE/3, CELL_SIZE/3, 92, 86, 2.0, "white");	    gtk_signal_connect (GTK_OBJECT (peg_group[x][y]), "event",				(GtkSignalFunc) item_event,				NULL);	    if (!board[x][y].peg)	      gnome_canvas_item_hide (GNOME_CANVAS_ITEM(peg_group[x][y]));	  }      }}/* draw_border_line: Draws the line around the board.  */static voiddraw_border_line (int x, int y){  if (x-1 < 0 || !board[x-1][y].hole)    draw_line (board_group,	       x*CELL_SIZE+board[x][y].indent, y*CELL_SIZE,	       x*CELL_SIZE+board[x][y].indent, (y+1)*CELL_SIZE,	       1.0, "white");  if (x+1 >= board_size || !board[x+1][y].hole)    draw_line (board_group,	       (x+1)*CELL_SIZE+board[x][y].indent, y*CELL_SIZE,	       (x+1)*CELL_SIZE+board[x][y].indent, (y+1)*CELL_SIZE,	       1.0, "black");  if (!hex_struct)    {      if (y-1 < 0 || !board[x][y-1].hole)	draw_line (board_group,		   x*CELL_SIZE, y*CELL_SIZE,		   (x+1)*CELL_SIZE, y*CELL_SIZE,		   1.0, "white");      if (y+1 >= board_size || !board[x][y+1].hole)	draw_line (board_group,		   x*CELL_SIZE, (y+1)*CELL_SIZE,		   (x+1)*CELL_SIZE, (y+1)*CELL_SIZE,		   1.0, "black");    }  else    {      if (!get_indent (y))	{	  if (y-1 < 0 || !board[x][y-1].hole)	    draw_line (board_group,		       x*CELL_SIZE+CELL_SIZE/2, y*CELL_SIZE,		       (x+1)*CELL_SIZE, y*CELL_SIZE,		       1.0, "white");	  if (y-1 < 0 || x-1 < 0 || !board[x-1][y-1].hole)	    draw_line (board_group,		       x*CELL_SIZE, y*CELL_SIZE,		       x*CELL_SIZE+CELL_SIZE/2, y*CELL_SIZE,		       1.0, "white");	  if (y+1 >= board_size || !board[x][y+1].hole)	    draw_line (board_group,		       x*CELL_SIZE+CELL_SIZE/2, (y+1)*CELL_SIZE,		       (x+1)*CELL_SIZE, (y+1)*CELL_SIZE,		       1.0, "black");	  if (y+1 >= board_size || x-1 < 0 || !board[x-1][y+1].hole)	    draw_line (board_group,		       x*CELL_SIZE, (y+1)*CELL_SIZE,		       x*CELL_SIZE+CELL_SIZE/2, (y+1)*CELL_SIZE,		       1.0, "black");	}      else	{	  if (y-1 < 0 || !board[x][y-1].hole)	    draw_line (board_group,		       x*CELL_SIZE+CELL_SIZE/2, y*CELL_SIZE,		       (x+1)*CELL_SIZE, y*CELL_SIZE,		       1.0, "white");	  if (y-1 < 0 || x+1 >= board_size || !board[x+1][y-1].hole)	    draw_line (board_group,		       (x+1)*CELL_SIZE, y*CELL_SIZE,		       (x+1)*CELL_SIZE+CELL_SIZE/2, y*CELL_SIZE,		       1.0, "white");	  if (y+1 >= board_size < 0 || !board[x][y+1].hole)	    draw_line (board_group,		       x*CELL_SIZE+CELL_SIZE/2, (y+1)*CELL_SIZE,		       (x+1)*CELL_SIZE, (y+1)*CELL_SIZE,		       1.0, "black");	  if (y+1 >= board_size < 0 || x+1 >= board_size	      || !board[x+1][y+1].hole)	    draw_line (board_group,		       (x+1)*CELL_SIZE, (y+1)*CELL_SIZE,		       (x+1)*CELL_SIZE+CELL_SIZE/2, (y+1)*CELL_SIZE,		       1.0, "black");	}    }}/* set_board_visual: Draws the board and the holes.  */static voidset_board_visual (void){  int x, y;  if (board_group)    gtk_object_destroy (GTK_OBJECT(board_group));  board_group = GNOME_CANVAS_GROUP(gnome_canvas_item_new (					   gnome_canvas_root (canvas),				           gnome_canvas_group_get_type (),					   "x",0.0,					   "y",0.0,					    NULL));  for (x = 0; x < board_size; x++)    for (y = 0; y < board_size; y++)      {	if (board[x][y].hole)	  {	    gnome_canvas_item_new (board_group,			  gnome_canvas_rect_get_type (),			  "x1", (double)x * CELL_SIZE + board[x][y].indent,			  "y1", (double)y * CELL_SIZE,			  "x2", (double)(x+1) * CELL_SIZE + board[x][y].indent,			  "y2", (double)(y+1) * CELL_SIZE,			  "fill_color_rgba", 0x0000001f,			  NULL);	    draw_border_line (x, y);	    /* Draw a two-coloured circle by drawing two arcs.  */	    draw_arc (board_group,		      x*CELL_SIZE+0.325*CELL_SIZE + board[x][y].indent,		      y*CELL_SIZE+0.325*CELL_SIZE,		      0.35*CELL_SIZE, 0.35*CELL_SIZE, 45, 180, 0.75, "black");	    draw_arc (board_group,		      x*CELL_SIZE+0.325*CELL_SIZE + board[x][y].indent,		      y*CELL_SIZE+0.325*CELL_SIZE,		      0.35*CELL_SIZE, 0.35*CELL_SIZE, 225, 180, 0.75, "white");	  }      }  gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas), 0.0, 0.0,				  board_size*CELL_SIZE,				  board_size*CELL_SIZE);  gtk_widget_set_usize (GTK_WIDGET(canvas), win_size, win_size);}static voidnew_game (enum game_types new_game_type){  if (game_type != new_game_type)    {      game_type = new_game_type;      board_size = get_board_size (game_type);      set_board (board, game_type);      set_board_visual ();    }  else    {      set_board (board, game_type);    }  set_pegs ();  moves = 0;  sel_peg_x = -1;}static voidundo (void){  if (!check_game_over () && moves > 0)    {      int x_dir;      int y_dir;      moves--;      undo_count++;      restore_peg (undo_vars[moves][0], undo_vars[moves][1]);      remove_peg (undo_vars[moves][2], undo_vars[moves][3]);      y_dir = (undo_vars[moves][3]-undo_vars[moves][1])/2;      if (!y_dir || !hex_struct)	x_dir = (undo_vars[moves][2]-undo_vars[moves][0])/2;      else if (get_indent (undo_vars[moves][1]) &&	  undo_vars[moves][2] > undo_vars[moves][0])	x_dir = 1;      else if (!get_indent (undo_vars[moves][1]) &&	       undo_vars[moves][2] < undo_vars[moves][0])	x_dir = -1;      else	x_dir = 0;      restore_peg (undo_vars[moves][0]+x_dir, undo_vars[moves][1]+y_dir);    }}static voidredo (void){  if (undo_count > 0)    {      int x_dir;      int y_dir;      remove_peg (undo_vars[moves][0], undo_vars[moves][1]);      restore_peg (undo_vars[moves][2], undo_vars[moves][3]);      y_dir = (undo_vars[moves][3]-undo_vars[moves][1])/2;      if (!y_dir || !hex_struct)	x_dir = (undo_vars[moves][2]-undo_vars[moves][0])/2;      else if (get_indent (undo_vars[moves][1]) &&	  undo_vars[moves][2] > undo_vars[moves][0])	x_dir = 1;      else if (!get_indent (undo_vars[moves][1]) &&	       undo_vars[moves][2] < undo_vars[moves][0])	x_dir = -1;      else	x_dir = 0;      remove_peg (undo_vars[moves][0]+x_dir, undo_vars[moves][1]+y_dir);      moves++;      undo_count--;    }  }static voidgame_new_cb (GtkWidget *widget, void *data){  new_game (game_type);}/* expose_preview_event: Refreshes the preview.  */static gintexpose_preview_event (GtkWidget *widget, GdkEventButton *event){  int x, y;  int xy_add;  gdk_window_clear_area (preview->window, 0, 0,			 MAX_BOARD_SIZE * PREVIEW_CELL_SIZE,			 MAX_BOARD_SIZE * PREVIEW_CELL_SIZE);  set_board (pref_board, pref_game_type);  pref_board_size = get_board_size (pref_game_type);  xy_add = (MAX_BOARD_SIZE-pref_board_size)*PREVIEW_CELL_SIZE/2;  for (x = 0; x < pref_board_size; x++)    for (y = 0; y < pref_board_size; y++)      if (pref_board[x][y].hole)	gdk_draw_arc (preview->window,		      preview->style->black_gc,		      pref_board[x][y].peg ? TRUE : FALSE,		      x*PREVIEW_CELL_SIZE+2+pref_board[x][y].indent/2+xy_add,		      y*PREVIEW_CELL_SIZE+2+xy_add,		      PREVIEW_CELL_SIZE-4, PREVIEW_CELL_SIZE-4,		      0*64, 360*64);  return FALSE;}static voidpref_gametype_cb (GtkWidget *widget, gint new_gametype, gint row,		  GdkEventButton *event, gpointer data){  if (new_gametype == pref_game_type)    return;  if (!pref_dialog)    return;  pref_game_type = new_gametype;  gtk_widget_draw (preview, NULL);  gnome_property_box_changed (GNOME_PROPERTY_BOX(pref_dialog));}static voidpref_sound_cb (GtkWidget *widget, void *data){  if (!pref_dialog)    return;  pref_sound = GTK_TOGGLE_BUTTON(widget)->active;  gnome_property_box_changed (GNOME_PROPERTY_BOX(pref_dialog));}static voidpref_apply (GtkWidget *widget, gint pagenum, const void *data){  if (pagenum != -1)    return;  if (pref_game_type != game_type)    {      gnome_config_set_int ("/gpegsol/Preferences/Gametype", pref_game_type);      gnome_config_sync ();      new_game (pref_game_type);    }  if (pref_sound != sound)    {      sound = pref_sound;      gnome_config_set_bool ("/gpegsol/Preferences/Sound", sound);      gnome_config_sync ();    }}static voidgame_preferences_cb (GtkWidget *widget, void *data){  GtkWidget *notebook;  GtkWidget *table;  GtkWidget *label;  GtkWidget *vbox;  GtkWidget *hbox, *frame;  GtkWidget *scrolled_window, *clist, *align, *cb;  int i;  gchar *names[N_GAMETYPES][1] = {{"Cross"}, {"Plus"}, {"Fireplace"},				  {"Up Arrow"}, {"Pyramid"}, {"Diamond"},				  {"Crossbow"}, {"Longbow"},				  {"Solitaire"}, {"Classic Frensh"},				  {"Square"}, {"Draughtsboard"},				  {"The X"}, {"Big Diamond"},				  {"Triangular"}, {"Hexagonal"},				  {"Stellar"}};  pref_game_type = game_type;  pref_sound = sound;  set_board (pref_board, pref_game_type);  if (pref_dialog)    return;  pref_dialog = gnome_property_box_new ();    gnome_dialog_set_parent (GNOME_DIALOG(pref_dialog), GTK_WINDOW(app));  gtk_window_set_title (GTK_WINDOW(pref_dialog),			_("Peg Solitaire Preferences"));  gtk_signal_connect (GTK_OBJECT(pref_dialog), "destroy",		      GTK_SIGNAL_FUNC(gtk_widget_destroyed), &pref_dialog);  notebook = GNOME_PROPERTY_BOX(pref_dialog)->notebook;  gtk_object_set_data (GTK_OBJECT(pref_dialog), "notebook", notebook);  gtk_widget_show (notebook);  gtk_notebook_set_tab_hborder (GTK_NOTEBOOK(notebook), 6);  gtk_notebook_set_tab_vborder (GTK_NOTEBOOK(notebook), 3);  label = gtk_label_new (_("Preferences"));  gtk_widget_show (label);  table = gtk_table_new (2, 2, FALSE);  gtk_widget_show (table);  frame = gtk_frame_new (_("Board"));  gtk_container_set_border_width (GTK_CONTAINER(frame), 5);  gtk_widget_show (frame);  hbox = gtk_hbox_new (TRUE, 5);  gtk_container_set_border_width (GTK_CONTAINER(hbox), 5);  gtk_widget_show (hbox);  clist = gtk_clist_new (1);  gtk_signal_connect (GTK_OBJECT(clist), "select_row",		      GTK_SIGNAL_FUNC(pref_gametype_cb), NULL);  gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_OUT);  scrolled_window = gtk_scrolled_window_new (NULL, NULL);  gtk_container_set_border_width (GTK_CONTAINER(scrolled_window), 10);  gtk_widget_set_usize (scrolled_window, 150, 150);   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_window),				  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);  gtk_box_pack_start (GTK_BOX(hbox), scrolled_window, TRUE, TRUE, 0);  gtk_widget_show (scrolled_window);  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_window),					 clist);  gtk_widget_show (clist);  for (i = 0; i < N_GAMETYPES; i++)    gtk_clist_append ((GtkCList *)clist, names[i]);  preview =  gtk_drawing_area_new ();  gtk_widget_set_events (preview, GDK_EXPOSURE_MASK);  gtk_signal_connect (GTK_OBJECT(preview), "expose_event", 		      GTK_SIGNAL_FUNC(expose_preview_event), NULL);  set_board (pref_board, pref_game_type);  gtk_drawing_area_size (GTK_DRAWING_AREA(preview),			 MAX_BOARD_SIZE * PREVIEW_CELL_SIZE,			 MAX_BOARD_SIZE * PREVIEW_CELL_SIZE);  gtk_widget_show (preview);  align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);  gtk_container_add (GTK_CONTAINER(align), preview);  gtk_widget_show (align);  gtk_box_pack_end (GTK_BOX(hbox), align, TRUE, TRUE, 0);  gtk_container_add (GTK_CONTAINER(frame), hbox);  gtk_table_attach (GTK_TABLE(table), frame, 0, 2, 0, 1, GTK_EXPAND |		    GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);  frame = gtk_frame_new (_("Sound"));  gtk_container_set_border_width (GTK_CONTAINER(frame), 5);  gtk_widget_show (frame);  vbox = gtk_vbox_new (TRUE, 0);  gtk_container_set_border_width (GTK_CONTAINER(vbox), 5);  gtk_widget_show (vbox);  cb = gtk_check_button_new_with_label (_("Sound"));  gtk_signal_connect (GTK_OBJECT(cb), "clicked", (GtkSignalFunc)pref_sound_cb, NULL);  gtk_widget_show (cb);  gtk_box_pack_start (GTK_BOX(vbox), cb, FALSE, FALSE, 0);  gtk_container_add (GTK_CONTAINER(frame), vbox);  gtk_table_attach (GTK_TABLE(table), frame, 0, 2, 1, 2, GTK_EXPAND |		    GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);  gtk_container_add (GTK_CONTAINER(notebook), table);  gtk_notebook_set_tab_label (GTK_NOTEBOOK(notebook),			      gtk_notebook_get_nth_page (GTK_NOTEBOOK(notebook),							 0), label);  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(cb), sound);  gtk_signal_connect (GTK_OBJECT(pref_dialog), "apply",		      GTK_SIGNAL_FUNC(pref_apply), NULL);  gtk_widget_show (pref_dialog);  pref_game_type = game_type;  pref_sound = sound;}/* game_exit_cb: Saves the win size and exits.  */static intgame_exit_cb (GtkWidget *widget, void *data){  if (win_size > MAX_WIN_SIZE)    win_size = MAX_WIN_SIZE;  else if (win_size < MIN_WIN_SIZE)    win_size = MIN_WIN_SIZE;  gnome_config_set_int ("/gpegsol/Preferences/Winsize", win_size);  gnome_config_sync ();  gtk_main_quit ();  return FALSE;}static voidgame_about_cb (GtkWidget *widget, void *data){  GtkWidget *about;  const gchar *authors[] = {    "Andreas T鴕

⌨️ 快捷键说明

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