int board_accept_new_tile(PLAYER *player, short tile_code, const short tile_pos[], const short tile_size[]) { char *board; if (player->status & PLST_FINISHED) return 0; player->status &= ~PLST_DROPPED; player->status |= PLST_NEWTILE; player->released_details = 0; player->bonus = (player->options & PLOP_SHOWNEXT) ? 15 : 20; board = player->board; if (!check_tile_insert(board, tile_pos, tile_size)) { player->status |= PLST_FINISHED; draw_board(PT_FOREGROUND, player, 0); return 0; } memcpy(player->tile_pos, tile_pos, sizeof(short)*Dimension); memcpy(player->tile_size, tile_size, sizeof(short)*Dimension); player->tile_code = tile_code; tile_insert(board, tile_pos, tile_size, tile_code); player->status |= PLST_CHANGED; if (player->options & PLOP_SHOWNEXT) show_next(PT_FOREGROUND, player); update_bonus(PT_FOREGROUND, player->bonus); draw_board(PT_FOREGROUND, player, 0); return 1; }
void board_action(int player_no, ACTION action) { PLAYER *player = players[player_no]; player->status &= ~PLST_NEWTILE; switch(action) { case ACT_BACKRIGHT: if (!board_shift_wd(player, 1, -1) && !board_shift_wd(player, 1, 0)) board_shift_wd(player, 0, -1); break; case ACT_BACK: board_shift_wd (player, 0, -1); break; case ACT_BACKLEFT: if (!board_shift_wd (player, -1, -1) && !board_shift_wd(player, -1, 0)) board_shift_wd(player, 0, -1); break; case ACT_LEFT: board_shift_wd (player, -1, 0); break; case ACT_RIGHT: board_shift_wd(player, 1, 0); break; case ACT_FRONTLEFT: if (!board_shift_wd (player, -1, 1) && !board_shift_wd(player, -1, 0)) board_shift_wd(player, 0, 1); break; case ACT_FRONT: board_shift_wd (player, 0, 1); break; case ACT_FRONTRIGHT: if(!board_shift_wd (player, 1, 1) && !board_shift_wd(player, 1, 0)) board_shift_wd(player, 0, 1); break; case ACT_DOWN: board_shift_h (player); break; case ACT_TURNFWD: board_turn (player, 1); break; case ACT_TURNBACK: board_turn (player, -1); break; case ACT_ROTATEFWD: board_rotate (player, 1); break; case ACT_ROTATEBACK: board_rotate (player, -1); break; case ACT_DROP: case ACT_BACKTAB: board_drop (player); break; case ACT_QUIT: player->status |= PLST_FINISHED; player->status |= PLST_QUITTED; break; case ACT_SHOWNEXT: player->options ^= PLOP_SHOWNEXT; show_next(PT_FOREGROUND, player); break; case ACT_REDRAW: player->status |= PLST_DELAY; LastSaveLayer = -1; draw_board(PT_FOREGROUND, player, 0); player->status &= ~PLST_DELAY; if (player->type == 0) { long score = player->score; if (score < 50) score = 0; else score-= 50; draw_score_line(PT_FOREGROUND, SL_SCORE, score); player->score = score; } break; case ACT_LEVEL: if (player_no==0) player->status |= PLST_SKIPLEVEL; break; /* case ACT_TAB: boss_routine(); break; case ACT_PAUSE: pause_game(); break; */ default: ; } }
void *key_controll_pthread_fun() { int keyboard_fd; char *keyboard_str = "/dev/input/by-path/platform-i8042-serio-0-event-kbd"; //int open(const char *pathname, int flags); //int open(const char *pathname, int flags, mode_t mode); //int creat(const char *pathname, mode_t mode); if((keyboard_fd = open(keyboard_str , O_RDONLY )) < 0) { fprintf( stderr , "open %s failed:%s\n" , keyboard_str , strerror(errno)); exit(1); } // fprintf( stdout , "open %s success\n" , keyboard_str ); #if 0 struct input_event { struct timeval time; __u16 type; __u16 code; __s32 value; }; #endif struct input_event i_event; int read_bytes; int auto_display = 0; int keep_reading = 1; clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); while(keep_reading) { // fprintf(stdout , "1\n"); if((read_bytes = read(keyboard_fd , &i_event , sizeof(struct input_event))) < 0) { fprintf(stdout , "read from keyboard error:%s\n" , strerror(errno)); exit(1); } else { // press key if(EV_KEY == i_event.type) { // value == 1 means key DOWN however 2 means key UP if(i_event.value == 1) { //fprintf(stdout , "key DOWN value=%d\n" , i_event.value); switch(i_event.code) { case KEY_LEFT : change_global_keycode(&global_keycode , i_event.code); // clear_frame_buffer( fb ); // pthread_cancel(auto_display_pthread); show_privious(); // show_weather(fb , weather_info); break; case KEY_RIGHT: change_global_keycode(&global_keycode , i_event.code); // clear_frame_buffer( fb ); // pthread_cancel(auto_display_pthread); show_next(); // show_weather(fb , weather_info); break; case KEY_N: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(music_pthread); system("killall -9 madplay"); // pthread_mutex_lock(&music_mutex); next_music(); if(auto_display == 0) { // pthread_mutex_lock(&music_mutex); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); // pthread_mutex_lock(&music_mutex); } break; case KEY_P: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(music_pthread); system("killall -9 madplay"); //int pthread_mutex_lock(pthread_mutex_t *mutex); // pthread_mutex_lock(&music_mutex); privious_music(); if(auto_display == 0) { // pthread_mutex_lock(&music_mutex); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); // pthread_mutex_lock(&music_mutex); } break; case KEY_SPACE: if(auto_display == 0) { auto_display = 1; auto_display_pthread = start_auto_display_pthread(); } else { auto_display = 0; pthread_cancel(auto_display_pthread); clear_frame_buffer( fb ); first_show(); show_weather(fb , weather_info); } break; case KEY_Q: change_global_keycode(&global_keycode , i_event.code); pthread_cancel(auto_display_pthread); pthread_cancel(music_pthread); system("killall -9 madplay"); goto END; } } #if 0 else if(i_event.value == 0) { fprintf(stdout , "key UP value=%d\n" , i_event.value); } else { fprintf(stdout , "do not know value=%d\n" , i_event.value); } #endif } } } END: fprintf(stdout ,"key_controll_pthread exit : %s\n" , __func__); //int close(int fd); close(keyboard_fd); //void pthread_exit(void *value_ptr); pthread_exit(NULL); }