void check_fight (object me, object who) { int my_kee, whos_kee; int my_max_kee, whos_max_kee; if(!who) return; my_kee = me->query("kee"); whos_kee = who->query("kee"); my_max_kee = me->query("max_kee"); whos_max_kee = who->query("max_kee"); if (me->is_fighting()){ remove_call_out("check_fight"); call_out ("check_fight",1,me,who); return; } if (!present(who, environment(me))) return; // changed by snowcat on 6/24/1997 // bug abuse: player can exert recover when fight stops, //if ((my_kee*100/my_max_kee) <=(whos_kee*100/whos_max_kee) ) // player_win (me, who); //else player_lose (me, who); if ((my_kee*100/my_max_kee) <= 50) player_win (me, who); else if ((whos_kee*100/whos_max_kee) <= 50) player_lose (me, who); }
gint is_falling_letter(gunichar unichar) { GooCanvasItem *item; if ((item = g_hash_table_find(letters_table, unichar_comp, &unichar))) { player_win(item); return TRUE; } return FALSE; }
void end_game(char **_tab, t_cursor *cursor, char *name) { if (player_win(_tab)) { my_clear(); free_tab(_tab); free(cursor); my_putstr("Game just ended, "); my_putstr(name); my_putstr(" won this game.\n"); exit(0); } }
/* * Used to hide card after a timer * */ static gint hide_card (GtkWidget *widget, gpointer data) { if (currentMode == MODE_TUX){ GList *list = NULL; GList *to_remove = NULL; for (list = winning_pairs; list != NULL; list=list->next) if ((((WINNING *) list->data)->first == firstCard) || (((WINNING *) list->data)->first == secondCard) || (((WINNING *) list->data)->second == firstCard) || (((WINNING *) list->data)->second == secondCard) ){ to_remove = g_list_append( to_remove, list->data); } for (list = to_remove; list != NULL; list=list->next){ void *data = list->data; winning_pairs = g_list_remove (winning_pairs, list->data); g_free (data); g_warning("Again %d winning pairs in tux list! ", g_list_length(winning_pairs)); } g_list_free(to_remove); if (to_tux) tux_pairs++; else player_pairs++; update_scores(); } if(firstCard!=NULL) { display_card(firstCard, HIDDEN); if (currentMode == MODE_TUX) remove_card_from_tux_memory(firstCard); firstCard = NULL; } if(secondCard!=NULL) { display_card(secondCard, HIDDEN); if (currentMode == MODE_TUX) remove_card_from_tux_memory(secondCard); secondCard = NULL; } win_id = 0; remainingCards -= 2; if(remainingCards<=0){ if (currentMode == MODE_TUX){ if (tux_id){ g_source_remove(tux_id); tux_id = 0; to_tux = FALSE; } } player_win(); } return (FALSE); }
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { gchar *letter; gint i; LettersItem *item; gchar *str; gunichar unichar_letter; gint retval = TRUE; if(!gcomprisBoard) return FALSE; if (keyval){ g_warning("keyval %d", keyval); return TRUE; } if (preedit_str){ g_warning("preedit_str %s", preedit_str); /* show the preedit string on bottom of the window */ GcomprisProperties *properties = gc_prop_get (); gchar *text; PangoAttrList *attrs; gint cursor_pos; gtk_im_context_get_preedit_string (properties->context, &text, &attrs, &cursor_pos); if (!preedit_text) preedit_text = \ goo_canvas_text_new (goo_canvas_get_root_item(gcomprisBoard->canvas), "", BOARDWIDTH/2, BOARDHEIGHT - 100, -1, GTK_ANCHOR_N, "font", gc_skin_font_board_huge_bold, //"fill_color_rgba", 0xba00ffff, NULL); g_object_set (preedit_text, "text", text, "attributes", attrs, NULL); return TRUE; } /* commit str */ g_warning("commit_str %s", commit_str); str = commit_str; #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_lock (&items_lock); #else g_static_mutex_lock (&items_lock); #endif for (i=0; i < g_utf8_strlen(commit_str,-1); i++){ unichar_letter = g_utf8_get_char(str); str = g_utf8_next_char(str); if(!g_unichar_isalnum (unichar_letter)){ player_loose(); retval = FALSE; break; } letter = g_new0(gchar,6); g_unichar_to_utf8 (unichar_letter, letter); /* Force entered letter to the casing we expect * Children is to small to manage the caps lock key for now */ if (uppercase_only) { gchar *old = letter; letter = g_utf8_strup(old, -1); g_free(old); } else { gchar *old = letter; letter = g_utf8_strdown(old, -1); g_free(old); } if(item_on_focus==NULL) { for (i=0;i<items->len;i++) { item=g_ptr_array_index(items,i); g_assert (item!=NULL); if (strcmp(item->letter,letter)==0) { item_on_focus=item; break; } } } if(item_on_focus!=NULL) { if(strcmp(item_on_focus->letter, letter)==0) { gchar *tmpstr; item_on_focus->count++; g_free(item_on_focus->overword); tmpstr = g_utf8_strndup(item_on_focus->word, item_on_focus->count); /* Add the ZERO WIDTH JOINER to force joined char in Arabic and Hangul * http://en.wikipedia.org/wiki/Zero-width_joiner */ item_on_focus->overword = g_strdup_printf("%s%lc", tmpstr, 0x200D); g_free(tmpstr); g_object_set (item_on_focus->overwriteItem, "text", item_on_focus->overword, NULL); if (item_on_focus->count<g_utf8_strlen(item_on_focus->word,-1)) { g_free(item_on_focus->letter); item_on_focus->letter=g_utf8_strndup(item_on_focus->pos,1); item_on_focus->pos=g_utf8_find_next_char(item_on_focus->pos,NULL); } else { player_win(item_on_focus); item_on_focus=NULL; } } else { /* It is a loose : unselect the word and defocus */ g_free(item_on_focus->overword); item_on_focus->overword=g_strdup(" "); item_on_focus->count=0; g_free(item_on_focus->letter); item_on_focus->letter=g_utf8_strndup(item_on_focus->word,1); item_on_focus->pos=g_utf8_find_next_char(item_on_focus->word,NULL); g_object_set (item_on_focus->overwriteItem, "text", item_on_focus->overword, NULL); item_on_focus=NULL; g_free(letter); player_loose(); break; } } else { /* Anyway kid you clicked on the wrong key */ player_loose(); g_free(letter); break; } g_free(letter); } #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_unlock (&items_lock); #else g_static_mutex_unlock (&items_lock); #endif return retval; }