void f_move_down(t_env *e) { int tmp; e->mod_tab[e->cursor] /= 2; tmp = e->cursor; move_down(e); while (e->mod_tab[e->cursor] == 0) { if (tmp == e->cursor) { f_escape(e); } move_down(e); } e->mod_tab[e->cursor] *= 2; }
int LOOK() { char FileName[40]; sprintf(FileName, "%d LOOK.txt", App.direction); FILE *fp = fopen(FileName, "w"); fprintf(fp, "Start POS: %d\n", App.CurrentApp); fprintf(fp, "\nCurrent rndLoop sum\n\n"); while (Power) { while (App.QueueSize) { switch (App.direction) { case UP: while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_up() == FALSE) { App.direction = DOWN; fprintf(fp, "direction changed \n"); break; // Κάνουμε Break από το for γιατί θέλουμε να αλλάξουμε κατεύθυνση. } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } pthread_mutex_unlock(&crit_m); break; //case break default: while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_down() == FALSE) { App.direction = UP; fprintf(fp, "direction changed \n"); break; // Κάνουμε Break από το for γιατί θέλουμε να αλλάξουμε κατεύθυνση. } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } pthread_mutex_unlock(&crit_m); break; //case break } } } fclose(fp); return TRUE; }
void process_key(void) //키 프로세스 { key = 0; //키값 초기화 if (kbhit()) { key = getch(); //키값을 받음 if (key == 224) //방향키인경우 { do { key = getch(); } while (key == 224); //방향키지시값을 버림 switch (key) { case LEFT: //왼쪽키 눌렀을때 if (check_crush(bx - 1, by, b_rotation) == true) //왼쪽으로 갈 수 있는지 체크 후 가능하면 이동 move_block(LEFT); break; case RIGHT: if (check_crush(bx + 1, by, b_rotation) == true) move_block(RIGHT); break; case DOWN: if (check_crush(bx, by + 1, b_rotation) == true) move_block(DOWN); break; case UP: //위쪽키 눌렀을때 회전 if (check_crush(bx, by, (b_rotation + 1) % 4) == true) move_block(UP); else if (crush_on == 1 && check_crush(bx, by - 1, (b_rotation + 1) % 4) == true) move_block(100); } //바닥에 닿은 경우 위쪽으로 한칸띄워서 회전이 가능하면 그렇게 함 } else //방향키가 아닌경우 { switch (key) //스페이스키 눌렀을때 { case SPACE: space_key_on = 1; //스페이스키 flag를 띄움 while (crush_on == 0) //바닥에 닿을때까지 이동시킴 { move_down(); score = score + level; //보너스점수 } break; case z: //테스트용 맛살 b_type_next = 1; break; case ESC: system("cls"); exit(0); } } } while (kbhit()) getch(); //키버퍼를 비우기 }
int main() { init_curses(); const char *exit_msg = ""; srandom(time(NULL)); struct game_t game = {0}; int last_turn = game.turns; get_highscore_filepath(&game); load_highscore(&game); place_tile(&game); place_tile(&game); while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (getch()) { case 'h': case KEY_LEFT: case 'a': move_left(&game); break; case 'j': case KEY_DOWN: case 's': move_down(&game); break; case 'k': case KEY_UP: case 'w': move_up(&game); break; case 'l': case KEY_RIGHT: case 'd': move_right(&game);break; case 'q': exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: move(7, 0); printw("You lose! Press q to quit."); while (getch() != 'q'); end: endwin(); if(game.score > game.highscore) { game.highscore = game.score; save_highscore(&game); } printf("You %s after scoring %d points in %d turns, " "with largest tile %d. The local highscore is %d points.\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board), game.highscore); free(game.highscorefile); return 0; }
int lose_game(struct game_t test_game) { int start_turns = test_game.turns; move_left(&test_game); move_up(&test_game); move_down(&test_game); move_right(&test_game); return test_game.turns == start_turns; }
int main(int argc, const char *argv[]) { char game[3][3]={0}; char key; show_game(game,3); printf("\n"); while(scanf(" %c",&key)){ switch(key){ case 'w': { // printf("%s\033[k"); system("clear"); sort_up(game,3); move_up(game,3); randfunc(game,3); show_game(game,3); } break; case 'a': { // printf("%s\033[1J"); system("clear"); sort_left(game,3); move_left(game,3); randfunc(game,3); show_game(game,3); } break; case 'd': { // printf("%s\033[1k"); system("clear"); sort_right(game,3); move_right(game,3); randfunc(game,3); show_game(game,3); } break; case 's': { // printf("%s\033[1J"); system("clear"); sort_down(game,3); move_down(game,3); randfunc(game,3); show_game(game,3); } break; } } return 0; }
void SantaMap::move(const char movement) { switch(movement) { case '<': move_left(); break; case '^': move_up(); break; case '>': move_right(); break; case 'v': move_down(); break; } increment_counter_if_new_visited_house(); }
int check_scale_boss(t_struct *st) { if (st->boss.y - st->heros.y < 0) return (move_down(st)); else if (st->boss.y - st->heros.y > 0) return (move_up(st)); else return (0); }
extern ITEM* heap_extractMin(HEAP* h){ ITEM* aux; aux = heap_queryMin(h); swap(h, 0, h->index); // printHeap(h); h->index -= 1; move_down(h, 0); return aux; }
int game_loop() { if(!game_over) { timer = gtk_timeout_add(level_speeds[current_level], (GtkFunction)game_loop,NULL); move_down(); } return FALSE; }
static void mouse_down_arrow_down(void *d, Evas *e, Evas_Object *obj, void *event_info) { app_t *app = d; if (app->mouse_down_anim) ecore_animator_del(app->mouse_down_anim); app->mouse_down_anim = ecore_animator_add(do_move_down, app); move_down(app); }
static void* trd_timer(void* p) { timer_init(); for(;;) { timer_update(); if(timer_interval() >= speeds[GAME->level]) { move_down(); timer_reset(); } usleep(50); } }
void check_move(char *buf, int *y, int *x, t_win *win) { if (buf[0] == 27) { move_up(buf[2], y, x, win); move_down(buf[2], y, x, win); move_left(buf[2], y, x, win); move_right(buf[2], y, x, win); if (!buf[1] && !buf[2]) leave_term(); } }
static void scroll_page_down(){ menu_list_data *data; data = (menu_list_data *) ssd_dialog_get_current_data(); if( (data->CurrentIndex + data->num_rows) >= data->num_items) return; data->CurrentIndex += data->num_rows-1; move_down(); }
int C_SCAN() { char FileName[40]; sprintf(FileName, "%d C-SCAN.txt", App.direction); FILE *fp = fopen(FileName, "w"); fprintf(fp, "Start POS: %d\n", App.CurrentApp); fprintf(fp, "\nCurrent rndLoop sum\n\n"); switch (App.direction) { case UP: while (Power) { while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_up() == FALSE) { App.sum += abs(App.CurrentApp - MaxBlockRange); App.CurrentApp = 0; fprintf(fp, "Cycle\n"); } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } } break; //case break default: while (Power) { while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_down() == FALSE) { App.sum += abs(App.CurrentApp + 1); App.CurrentApp = MaxBlockRange - 1; fprintf(fp, "Cycle\n"); } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } } break; //case break } fclose(fp); return TRUE; }
// move() // ... 기존의 머리는 몸통으로 바꾸어 출력하고 // ... 진행방향에 따라 알맞는 move함수를 호출한다. // void Snake::move() { putchar_at_xy(head().X, head().Y, 'o'); switch (direction_) { case UP: move_up(); break; case DOWN: move_down(); break; case LEFT: move_left(); break; case RIGHT: move_right(); break; } }
int key_event_update() { int ret; char buf[100]; while(1){ //Auto Driving Loop switch(c){ case 65://up sprintf(buf, "UP "); gotoxy(22, 43, buf, strlen(buf)); ret = move_up(); break; case 66://down sprintf(buf, "DOWN "); gotoxy(22, 43, buf, strlen(buf)); ret = move_down(); break; case 67://right sprintf(buf, "RIGHT "); gotoxy(22, 43, buf, strlen(buf)); ret = move_right(); break; case 68://left sprintf(buf, "LEFT "); gotoxy(22, 43, buf, strlen(buf)); ret = move_left(); break; default: ret = 1; break; } gotoxy_none(24,5); if(ret == 1){ //Artificial Intillegence Contorlling Object if(direction_guider() == -1){ blink_grid_hit(); return -1; // Computer Can't Proceed Further, Grid Lock } c = new_direction; }else if(ret == 0){ // AI Will Not allow us to hit any frid unless, Object stands on the GRID //Human Intillegence Contorlling Object c = fgetc(stdin); //Key Board Input fflush(stdin); if(c =='x'){ return -1; } }else{ // Invalid Input } continue; } }
extern void build_heap_lin(HEAP* h, ITEM* nodes,int n){ int i; h->size = n; h->index = n-1; for(i=0;i<n;i++){ h->data[i]= nodes+i; } for(i = floor((n-1)/2); i>=0; i--){ move_down(h,i); } }
int main(int argc, char** argv) { srand(time(NULL)); initialize_state(); initialize_timer(); print_state(stdout, 1.0f); printf("Score: %d\n", game_state.score); char input; double dTime = 0; while (1) { dTime += get_elapsed_time(); if (dTime > 1) { printf("Tick.\n"); dTime -= 1; } } while (input = getchar()) { switch (input) { case 'D': if (move_down()) return 0; break; case 'G': if (gravity_tick()) return 0; break; case 'L': move_left(); break; case 'R': move_right(); break; case 'U': rotate(); break; } print_state(stdout, 1.0f); printf("Score: %d\n", game_state.score); } return 0; }
fitness_t Strand::set_gene(int x, int y, mutation_t sj) { int i; int match; fitness_t wi, wj; mutation_t si; if (v == NULL) { v = new Locus[lseg]; // cerr << "new " << (void *)v << " [set_gene]" << endl; } for (i = 0, match = 0; i < nl; i++) { if (v[i].x == x) { match = 1; break; } if (x < v[i].x) break; } // If there is already a mutation at this locus (match == 1), // see if the new mutation overwrites an existing one or if it is // for the other strand, then save the mutation. If there is not // a mutation here yet, move the others down to make room for a // new locus in this strand and update the mutation count. if (match) { wi = locus_fitness(v[i].s[0],v[i].s[1]); if ((si = v[i].s[y]) != 0.0) v[i].s[y] = sj + si - sj*si; else v[i].s[y] = sj; } else { wi = 1.0; // cerr << "set: ml = " << ml << ", nl = " << nl << ", i = " << i << endl; move_down(i); v[i].s[0] = v[i].s[1] = 0.0; v[i].x = x; v[i].s[y] = sj; nl += 1; } // compute new fitness and return relative decrease in fitness // from the new mutation at this location wj = locus_fitness(v[i].s[0],v[i].s[1]); // cout << "set: w = " << wj/wi << endl; return wj/wi; }
void pacman::handle_events(SDL_Event &event){ if(event.type == SDL_KEYDOWN){ SDL_PumpEvents(); Uint8 *keystates = SDL_GetKeyState( NULL ); if(keystates[SDLK_UP]) move_up(40); if(keystates[SDLK_DOWN]) move_down(40); if(keystates[SDLK_RIGHT]) move_right(40); if(keystates[SDLK_LEFT]) move_left(40); } }
bool speech_dialog::process() { if(is_skipping_game()) { return true; } ++cycle_; if(text_char_ < num_chars()) { ++text_char_; } const int ScrollSpeed = 20; if(left_side_speaking_) { if(horizontal_position_ > 0) { horizontal_position_ -= ScrollSpeed; if(horizontal_position_ < 0) { horizontal_position_ = 0; } } } else { const int width = gui_section::get("speech_portrait_pane")->width(); if(horizontal_position_ < width) { horizontal_position_ += ScrollSpeed; if(horizontal_position_ > width) { horizontal_position_ = width; } } } #if !defined(__ANDROID__) if(expiration_ <= 0) { joystick::update(); if(!joystick_up_pressed_ && joystick::up()) { move_up(); } if(!joystick_down_pressed_ && joystick::down()) { move_down(); } } joystick_up_pressed_ = joystick::up(); joystick_down_pressed_ = joystick::down(); #endif return cycle_ == expiration_; }
/* Move the cursor around */ GUI_status SpellView::KeyDown(SDL_keysym key) { KeyBinder *keybinder = Game::get_game()->get_keybinder(); ActionType a = keybinder->get_ActionType(key); switch(keybinder->GetActionKeyType(a)) { case NORTH_KEY: return move_up(); case SOUTH_KEY: return move_down(); case WEST_KEY: case PREVIOUS_PARTY_MEMBER_KEY: move_left(); break; case EAST_KEY: case NEXT_PARTY_MEMBER_KEY: move_right(); break; case HOME_KEY: // TODO - add going to first viable page break; case END_KEY: // TODO - add going to last viable page break; case DO_ACTION_KEY: if(Game::get_game()->get_event()->is_looking_at_spellbook()) { show_spell_description(); return GUI_YUM; } if(event_mode) { event_mode_select_spell(); return GUI_YUM; } return GUI_PASS; case CANCEL_ACTION_KEY: return cancel_spell(); case TOGGLE_CURSOR_KEY : break; default: return GUI_PASS; } return(GUI_YUM); }
int main() { init_curses(); const char *exit_msg = ""; srand(time(NULL)); struct game_t game = {0}; int last_turn = game.turns; place_tile(&game); place_tile(&game); while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (getch()) { case 'h': case KEY_LEFT: move_left(&game); break; case 'j': case KEY_DOWN: move_down(&game); break; case 'k': case KEY_UP: move_up(&game); break; case 'l': case KEY_RIGHT: move_right(&game); break; case 'q': exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: move(7, 0); printw("You lose! Press q to quit."); while (getch() != 'q'); end: endwin(); printf("You %s after scoring %d points in %d turns, " "with largest tile %d\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board)); return 0; }
int C_LOOK() { char FileName[40]; sprintf(FileName, "%d C-LOOK.txt", App.direction); FILE *fp = fopen(FileName, "w"); fprintf(fp, "Start POS: %d\n", App.CurrentApp); fprintf(fp, "\nCurrent rndLoop sum\n\n"); switch (App.direction) { case UP: while (Power) { while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_up() == FALSE) { /* Μετακινήσου στην μικρότερη */ min_app(); fprintf(fp, "cycle\n"); } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } } break; //case break default: while (Power) { while (App.QueueSize) { pthread_mutex_lock(&crit_m); if (move_down() == FALSE) { /* Μετακινήσου στην μεγαλύτερη */ max_app(); fprintf(fp, "cycle\n"); } fprintf(fp, "%d %d %d\n", App.CurrentApp, App.CurrentRND, App.sum); pthread_mutex_unlock(&crit_m); if (Power) { sleep(1); } } } break; //case break } return TRUE; }
void try_move_down(struct block *blk) { int global_x = blk->pos_x; int global_y = blk->pos_y; char (*tmp)[4][4] = blk->dim; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if ((*tmp)[j][i] && global_y + i + 1 > 15) return; if ((*tmp)[j][i] && board[global_x + j][global_y + i + 1]) return; } } move_down(blk); }
/** * \brief Process a special key code. * \param key The code of the key. * \return True if the code has been processed. */ bool bear::gui::horizontal_flow::special_code( const input::key_info& key ) { bool result = false; if ( key.is_left() ) result = move_left(); else if ( key.is_right() ) result = move_right(); else if ( key.is_up() ) result = move_up(); else if ( key.is_down() ) result = move_down(); return result; } // horizontal_flow::special_code()
void paddle::move(directions direction) { if(direction!=up&&direction!=down){ return; } else{ if(direction==up){ move_down(); return; } if(direction==down){ move_up(); return; } } }
void _opque_print_stack(Stack_t *stack) { op_generic_t *gop; int i=0; if (log_level() <= 15) return; move_to_top(stack); while ((gop = (op_generic_t *)get_ele_data(stack)) != NULL) { log_printf(15, " i=%d gid=%d type=%d\n", i, gop_id(gop), gop_get_type(gop)); i++; move_down(stack); } if (stack_size(stack) != i) log_printf(0, "Stack size mismatch! stack_size=%d i=%d\n", stack_size(stack), i); }
static int get_input(t_context *gamestate, int key) { int condition; if (key == KEY_LEFT) condition = move_left(gamestate); else if (key == KEY_UP) condition = move_up(gamestate); else if (key == KEY_RIGHT) condition = move_right(gamestate); else if (key == KEY_DOWN) condition = move_down(gamestate); else return (-1); return (condition); }