📄 llk_main.c
字号:
void ui_game_giveup(GtkWidget *w,gpointer data){ /*关闭定时器*/ if(timer_handle != 0)gtk_timeout_remove(timer_handle); /*不记录成绩,所以就不用ui_game_over函数了*/ if(algorithm_game.status != ALGORITHM_GAME_STOP) { ui_game_init(); } else {}}/* 下一关 如果当前关卡不是最后一关(第10关),那么,进入下一关 否则,弹出窗口,提示可以玩下一个难度,然后结束游戏. 等待玩家选择下一个难度*/void ui_game_next_level(void){ if(timer_handle != 0)gtk_timeout_remove(timer_handle); if( algorithm_game_net_level() ) {/*切换到下一关了*/ ui_redraw_images(); ui_point1.x=-1; ui_point1.y=-1; progress_timeout(GINT_TO_POINTER(9999)); ui_refresh_top(); timer_handle = gtk_timeout_add(1000,progress_timeout,NULL); } else {/*已经过完所有关卡*/ ui_game_over(TRUE); }}/* 洗牌*/void ui_game_wash(GtkWidget *w,gpointer data){ if(algorithm_game.status != ALGORITHM_GAME_RUN) {return;} if(timer_handle != 0)gtk_timeout_remove(timer_handle); /*关闭定时器*/ if(algorithm_game.life == 0) { ui_game_over(FALSE); return; } else { gchar *message = (gchar *)g_malloc(sizeof(gchar)*20); algorithm_game.life--; sprintf(message,"生命:%d",algorithm_game.life); gtk_label_set_text(GTK_LABEL(ui_top.label_life),message); g_free(message); } algorithm_game_wash(); ui_redraw_images(); ui_point1.x=-1; ui_point1.y=-1; timer_handle = gtk_timeout_add(1000,progress_timeout,NULL);/*打开定时器*/}/* 游戏结束*/void ui_game_over(gboolean success){ GtkWidget *dialog; GtkMessageType type; gchar *message = (gchar *)g_malloc(sizeof(gchar)*100); if(success) { /*弹出对话窗,*/ switch(algorithm_game.difficulty) { case 0: sprintf(message,"恭喜!!您已经玩过了Easy难度,挑战Normal难度吧!"); break; case 1: sprintf(message,"恭喜!!您已经玩过了Normal难度,挑战Hard难度吧!"); break; case 2: sprintf(message,"恭喜通关!!你好厉害哦^_^,可以把分数上传到网络,看看您的排名!"); break; } type = GTK_MESSAGE_INFO; } else { /*弹出对话窗,*/ sprintf(message,"胜败乃兵家常事,大侠重新来过吧..."); type = GTK_MESSAGE_WARNING; } dialog = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,type,GTK_BUTTONS_OK,message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_free(message); /*记录当前成绩*/ ui_game_init();}/* 根据当前的关卡,进行相应的变形操作. 消牌操作已经完成,这里只需要对局面今天调整即可.*/void ui_game_change(struct AlgorithmPoint p1, struct AlgorithmPoint p2){ algorithm_game_change(p1,p2); ui_redraw_images(); ui_point1.x=-1; ui_point1.y=-1;}/* 暂停,消除显示的图案,对于data数据不能做任何修改 恢复游戏,显示图案即可*/void ui_game_pause(void){ GdkPixbuf *pixbuf; GdkRectangle update_rect; gint width,height; if(algorithm_game.status == ALGORITHM_GAME_RUN) { if(timer_handle != 0) { gtk_timeout_remove(timer_handle); timer_handle = 0; } algorithm_game.status = ALGORITHM_GAME_PAUSE; /*销毁fixed上的所有图片,然后放上一个提示暂停状态的图片*/ gdk_draw_rectangle (ui_double_pixmap, ui_drawingarea->style->black_gc, TRUE, 0, 0, ui_drawingarea->allocation.width, ui_drawingarea->allocation.height); pixbuf = gdk_pixbuf_new_from_inline(-1,pause_inline,FALSE,NULL); //pixbuf = gdk_pixbuf_new_from_file("/mnt/hdc8/Personal/GameDesign/pause.png",NULL); if(pixbuf) { width = gdk_pixbuf_get_width(pixbuf); height = gdk_pixbuf_get_height(pixbuf); gdk_pixbuf_render_to_drawable_alpha(pixbuf,ui_double_pixmap, 0,0,(ui_drawingarea->allocation.width - width)/2,(ui_drawingarea->allocation.height - height)/2,width,height, GDK_PIXBUF_ALPHA_BILEVEL,128, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_pixbuf_unref(pixbuf); } update_rect.x = 0; update_rect.y = 0; update_rect.width = ui_drawingarea->allocation.width; update_rect.height = ui_drawingarea->allocation.height; gtk_widget_draw (ui_drawingarea, &update_rect); } else if(algorithm_game.status == ALGORITHM_GAME_PAUSE) { /*继续游戏,先销毁暂停状态的图片,然后画背景,然后redraw所有牌面*/ gdk_draw_rectangle (ui_double_pixmap, ui_drawingarea->style->black_gc, TRUE, 0, 0, ui_drawingarea->allocation.width, ui_drawingarea->allocation.height); /*消除以前可能有的选定*/ ui_point1.x = -1; ui_point1.y = -1; ui_drawingarea_draw_bg(0); ui_redraw_images(); /*重绘窗口*/ update_rect.x = 0; update_rect.y = 0; update_rect.width = ui_drawingarea->allocation.width; update_rect.height = ui_drawingarea->allocation.height; gtk_widget_draw (ui_drawingarea, &update_rect); timer_handle = gtk_timeout_add(1000,progress_timeout,NULL); /*打开定时器*/ algorithm_game.status = ALGORITHM_GAME_RUN; }}/* 刷新top的显示*/void ui_refresh_top(void){ gchar *message = (gchar *)g_malloc(sizeof(gchar)*20); if(algorithm_game.status != ALGORITHM_GAME_STOP) { switch(algorithm_game.difficulty) { case 0: sprintf(message,"难度:Easy"); break; case 1: sprintf(message,"难度:Normal"); break; case 2: sprintf(message,"难度:Hard"); break; } gtk_label_set_text(GTK_LABEL(ui_top.label_difficulty),message); sprintf(message,"等级:%d",algorithm_game.level); gtk_label_set_text(GTK_LABEL(ui_top.label_level),message); switch(algorithm_game.level) { case 0:/*不变化*/ sprintf(message,"不变化"); break; case 1:/*向下*/ sprintf(message,"向下"); break; case 2:/*向左*/ sprintf(message,"向左"); break; case 3:/*上下分离*/ sprintf(message,"上下分离"); break; case 4:/*左右分离*/ sprintf(message,"左右分离"); break; case 5:/*上下集中*/ sprintf(message,"上下集中"); break; case 6:/*左右集中*/ sprintf(message,"左右集中"); break; case 7:/*上左下右*/ sprintf(message,"上左下右"); break; case 8:/*左下右上*/ sprintf(message,"左下右上"); break; case 9:/*向外扩散*/ sprintf(message,"向外扩散"); break; case 10:/*向内集中*/ sprintf(message,"向内集中"); break; default: /*assert not reach*/ break; } gtk_label_set_text(GTK_LABEL(ui_top.label_change_type),message); sprintf(message,"%d",algorithm_game.score); gtk_label_set_text(GTK_LABEL(ui_top.label_score),message); sprintf(message,"生命:%d",algorithm_game.life); gtk_label_set_text(GTK_LABEL(ui_top.label_life),message); sprintf(message,"提示:%d",algorithm_game.hint); gtk_label_set_text(GTK_LABEL(ui_top.label_hint),message); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui_top.progress_bar),((double)time_remain/(double)ui_get_time_limited())); } else { gtk_label_set_text(GTK_LABEL(ui_top.label_difficulty),"难度:"); gtk_label_set_text(GTK_LABEL(ui_top.label_level),"等级:"); gtk_label_set_text(GTK_LABEL(ui_top.label_change_type),"变化类型:"); gtk_label_set_text(GTK_LABEL(ui_top.label_score),"0"); gtk_label_set_text(GTK_LABEL(ui_top.label_life),"生命:"); gtk_label_set_text(GTK_LABEL(ui_top.label_hint),"提示:"); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui_top.progress_bar),0); } g_free(message);}/* 得到当前难度对应的时间限制*/gint ui_get_time_limited(void){ if(algorithm_game.difficulty == 2)return 240; else return 200; }/* 提示*/void ui_game_hint( GtkWidget *w,gpointer data ){ gint i,j; gint k,l; gchar *message=(gchar *)g_malloc(sizeof(gchar)*20); if(algorithm_game.status != ALGORITHM_GAME_RUN)return; if(algorithm_game.hint == 0)return; algorithm_game.hint--; sprintf(message,"提示:%d",algorithm_game.hint); gtk_label_set_text(GTK_LABEL(ui_top.label_hint),message); g_free(message); //g_assert(!algorithm_game_no_solution()); /*拷贝自algorithm_game_no_solution函数,做适当修改*/ for(i=0; i<algorithm_game.row ;i++) { for(j=0; j<algorithm_game.col ;j++) { if(algorithm_game.data[i][j] > 0) { for(k=i;k<algorithm_game.row;k++) { for(l=0;l<algorithm_game.col;l++) { if(k == i && l == j)continue; /*排除自己和自己相连的情况*/ if(algorithm_game.data[k][l] > 0) { struct AlgorithmPoint p1,p2; p1.x = i; p1.y = j; p2.x = k; p2.y = l; if(algorithm_can_link(p1,p2,NULL,NULL)) { ui_replace_image(p1,p2); /*窗口重绘在ui_replace_image函数中完成*/ /*给p1,p2处换图象*/ return; /*找到一对就返回*/ } } } } } } }}/* 处理消牌时候的连线效果*/void ui_draw_line(struct AlgorithmPoint p1,struct AlgorithmPoint p2){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -