//int main(int argc, char *argv[], char *env[]) void main(void) { int i, j; mvtype movemade; mousex=100; mousey=100; iconmenu=0; set_default_options(); options=doptions; read_options(); initialise(startbrd); initial_displays(current); no_more_openings=FALSE; quit=game_over=0; g_path.move[0].f=0; randomize(); FLAGnewstart=1; while(!quit) { while(game.movenum<maxmoves && !quit) { whites=0; blacks=0; if (FLAGnewstart) { starttime=time(NULL); FLAGnewstart=0; } newtime=0; if (!game_over && ((current.mvr=='w' && options.whiteplayer==PROGRAM) || (current.mvr=='b' && options.blackplayer==PROGRAM))) movemade=get_computer_move(current); else movemade=get_player_move(current, game_over); if (kbhit()) { if (getch()==27) { options.whiteplayer=USER; options.blackplayer=USER; } } if (current.mvr=='w') (whites=time(NULL)-starttime); else (blacks=time(NULL)-starttime); if (movemade.t!=0) if (movemade.t<100) makemv(movemade); else {menu_option(movemade.t); game_over=0;} regular_displays(current, movemade); if (!game_over) game_over=over(); assert(game.lastmove<maxmoves); } options.whiteplayer=USER; options.blackplayer=USER; } }
cui_menu menu_play(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); bool is_debug = false; char coords[5]; char calculated_coords[5]; strcpy(coords, "d2d20"); strcpy(calculated_coords, "d2d20"); while(!done){ WPAD_IR(0, &ir); WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); u32 released = WPAD_ButtonsUp(0); if(egg_check_s1_code(pressed, released)){ is_debug = true; p_game->board->tile_color1 = 0xc66300FF; p_game->board->tile_color2 = 0x632100FF; p_game->board->piece_color1 = 0x4242CCFF; p_game->board->piece_color2 = 0x444411FF; cui_board_init(p_game->board); if(voice) AESND_PlayVoice(voice, VOICE_STEREO8, warp, warp_size, VOICE_FREQ32KHZ, 1, false); } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } if ( pressed & WPAD_BUTTON_MINUS){ switch(menu_option(p_game)){ case CUI_MENU_OPTION_GFX:menu_option_gfx(p_game);break; case CUI_MENU_OPTION_SND:menu_option_snd(p_game);break; default:break; } } int index_offset_x = (p_game->cursor->hotspot_x - 40 / 2)/ 40 - 140 / 40; int index_offset_y = p_game->cursor->hotspot_y / 40 - 80 / 40; if (pressed & WPAD_BUTTON_B) { p_game->cursor->is_grabbing = true; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[0] = 'a' + index_offset_x; coords[1] = '8' - index_offset_y; } } else if(released & WPAD_BUTTON_B){ p_game->cursor->is_grabbing = false; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[2] = 'a' + index_offset_x; coords[3] = '8' - index_offset_y; coords[4] = 0; if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, move_pcm, move_pcm_size, VOICE_FREQ48KHZ, 1, false); if(calculate_coords(coords, calculated_coords, p_game->engine)){ cui_board_read_core(p_game->board, p_game->engine); } } } cui_cursor_update(p_game->cursor, ir.x, ir.y, ir.angle); if(p_game->tex_wallpaper)GRRLIB_DrawImg(0, -50, p_game->tex_wallpaper, 1, 1, 1, 0XFFFFFFFF); cui_board_display(p_game->board, tex_pieces, tex_tile, font, index_offset_x, index_offset_y); cui_cursor_display(p_game->cursor); if(is_debug){ GRRLIB_PrintfTTF (20, 00, font, coords, 16, 0x424242FF); GRRLIB_PrintfTTF2 (20, 20, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x, ir.y); GRRLIB_PrintfTTF2 (20, 40, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x/40, ir.y/40); GRRLIB_PrintfTTF2 (20, 60, font, 16, 0xFFFFFFFF, "x:%d y:%d", index_offset_x, index_offset_y); GRRLIB_PrintfTTF (20, 80, font, p_game->cursor->is_grabbing?"GRAB":"POINT", 16, 0xFFFFFFFF); GRRLIB_Rectangle(p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, 4, 4, 0xFF4242FF, 1); } GRRLIB_Render(); } GRRLIB_FreeTexture(tex_pieces); GRRLIB_FreeTexture(tex_tile); GRRLIB_FreeTTF(font); return next_state; }
int main(int argc, char **argv) { GRRLIB_Init(); // Initialise the attached controllers WPAD_Init(); WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); // Initialise the audio subsystem AESND_Init(NULL); MODPlay_Init(&play); MODPlay_SetMOD(&play,bg_music); MODPlay_SetVolume(&play,63,63); MODPlay_Start(&play); cui_cursor cursor; cursor.tex[0]=GRRLIB_LoadTexture(player1_point_png); cursor.tex[1]=GRRLIB_LoadTexture(player1_grab_png); cursor.is_grabbing=false; cui_board board; ENGINE engine = FIRSTCHESS; if(engine == TSCP){ int i; for (i=0; i < CUI_TILE_NB; i++) { board.piece[i]=init_piece[i]; if(init_color[i] == 1){ board.color[i]=CUI_BLACK; }else if (init_color[i] == 6){ board.color[i]=CUI_EMPTY; }else if (init_color[i] == 0){ board.color[i]=CUI_WHITE; } } init_hash(); init_board(); open_book(); gen(); } cui_board_read_core(&board, engine); GRRLIB_SetBackgroundColour(0x030, 0x30, 0x42, 0xFF); board.tile_color1 = 0xAAAAAAFF; board.tile_color2 = 0x444444FF; board.piece_color1 = 0xAAAAAAFF; board.piece_color2 = 0x444444FF; cui_board_init(&board); cui_game game; game.board = &board; game.engine = engine; game.cursor = &cursor; game.is_mute = false; GRRLIB_texImg *tex_wallpaper = GRRLIB_LoadTexture(wall_jpg); game.tex_wallpaper = tex_wallpaper; voice = AESND_AllocateVoice(aesnd_callback); AESND_SetVoiceVolume(voice, 0xFF, 0xFF); AESND_SetVoiceStream(voice, true); cui_menu current_state = CUI_MENU_MAIN; while(current_state != CUI_MENU_EXIT) { switch(current_state){ case CUI_MENU_MAIN: current_state=menu_main(&game);break; case CUI_MENU_PLAY: current_state=menu_play(&game);break; case CUI_MENU_OPTION:current_state=menu_option(&game);break; case CUI_MENU_OPTION_GENERAL:current_state=menu_option_general(&game);break; case CUI_MENU_OPTION_GFX:current_state=menu_option_gfx(&game);break; case CUI_MENU_OPTION_SND:current_state=menu_option_snd(&game);break; case CUI_MENU_CREDITS:current_state=menu_credits(&game);break; case CUI_MENU_PAUSE:current_state=menu_pause(&game);break; case CUI_MENU_HOME:current_state=menu_home(&game);break; case CUI_MENU_EXIT:current_state=menu_exit(&game);break; default:break; } } GRRLIB_FreeTexture(tex_wallpaper); GRRLIB_FreeTexture(cursor.tex[0]); GRRLIB_FreeTexture(cursor.tex[1]); GRRLIB_Exit(); return 0; }
GtkWidget * prefs_charset_page (void) { GtkWidget *main_vbox, *frame, *frame_vbox, *table, *hbox; GtkWidget *label, *combo, *option_menu; main_vbox = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 10); /* * common frame */ frame = gtk_frame_new (_(" Common ")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, TRUE, 0); frame_vbox = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (frame_vbox), 10); gtk_container_add (GTK_CONTAINER (frame), frame_vbox); hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (frame_vbox), hbox, TRUE, TRUE, 0); table = gtk_table_new (2, 2, FALSE); gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, TRUE, 5); /* * locale charset */ hbox = gtk_hbox_new (FALSE, 0); gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); label = gtk_label_new (_("Locale character set: ")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); combo = gtk_combo_new (); gtk_combo_set_popdown_strings (GTK_COMBO (combo), charset_get_known_list (NULL)); gtk_table_attach (GTK_TABLE (table), combo, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), conf.charset_locale); gtk_signal_connect (GTK_OBJECT (GTK_COMBO (combo)->entry), "changed", GTK_SIGNAL_FUNC (cb_locale_charset_changed), NULL); /* * internal charset */ hbox = gtk_hbox_new (FALSE, 0); gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); label = gtk_label_new (_("Internal character set: ")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); combo = gtk_combo_new (); gtk_combo_set_popdown_strings (GTK_COMBO (combo), charset_get_known_list (NULL)); gtk_table_attach (GTK_TABLE (table), combo, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), conf.charset_internal); gtk_signal_connect (GTK_OBJECT (GTK_COMBO (combo)->entry), "changed", GTK_SIGNAL_FUNC (cb_internal_charset_changed), NULL); /* * Language to detect */ hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (frame_vbox), hbox, FALSE, TRUE, 0); label = gtk_label_new (_("Language for auto detecting")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 5); option_menu = menu_option_simple (charset_auto_detect_labels, conf.charset_auto_detect_lang, &config_changed-> charset_auto_detect_lang); gtk_box_pack_start (GTK_BOX (hbox), option_menu, FALSE, TRUE, 5); gtk_widget_show_all (frame); /* * filename frame */ frame = gtk_frame_new (_(" File name ")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, TRUE, 10); frame_vbox = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (frame_vbox), 10); gtk_container_add (GTK_CONTAINER (frame), frame_vbox); /* * charset for filename */ hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (frame_vbox), hbox, FALSE, TRUE, 0); label = gtk_label_new (_("Character set of file name")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 5); /* * filename charset */ combo = gtk_combo_new (); gtk_widget_set_usize (combo, 120, -1); gtk_combo_set_popdown_strings (GTK_COMBO (combo), charset_get_known_list (NULL)); gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), conf.charset_filename); gtk_signal_connect (GTK_OBJECT (GTK_COMBO (combo)->entry), "changed", GTK_SIGNAL_FUNC (cb_filename_charset_changed), NULL); option_menu = menu_option (charset_to_internal_items, conf.charset_filename_mode, cb_filename_charset_conv, combo); gtk_box_pack_start (GTK_BOX (hbox), option_menu, FALSE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); gtk_widget_show_all (frame); set_sensitive_filename_charset_mode (conf.charset_filename_mode, combo); return main_vbox; }