void set_store_hs(void) { const struct set *s = SET_GET(sets, curr); fs_file fp; if ((fp = fs_open(config_cheat() ? s->cheat_scores : s->user_scores, "w"))) { int i; fs_printf(fp, "version %d\nset %s\n", SCORE_VERSION, s->id); put_score(fp, &s->time_score); put_score(fp, &s->coin_score); for (i = 0; i < s->count; i++) { const struct level *l = &level_v[i]; int flags = 0; if (l->is_locked) flags |= LEVEL_LOCKED; if (l->is_completed) flags |= LEVEL_COMPLETED; fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file); put_score(fp, &l->scores[SCORE_TIME]); put_score(fp, &l->scores[SCORE_GOAL]); put_score(fp, &l->scores[SCORE_COIN]); } fs_close(fp); } }
int main(void) { t_game game; if (!(WIN_VALUE % 2) && initscr()) { glob = &game; init(&game); setwins(&game); score_init(&game); while ((game.size = menu(&game) + 3) > 5) put_score(&game); if (game.size > 3 && game.size < 6) { set_plateau(&game); if (start(&game)) put_msg(game.msgbar, " GAME BEGIN", 2); play(&game); refresh(); } ft_exit("ya", &game); } else ft_putendl("Game_2048: Initialisation failed."); return (0); }
void tab_score(t_program *tetris) { int i; werase(tetris->tet.over.game); wborder(tetris->tet.over.game, '|', '|', '-', '-', '/', '\\', '\\', '/'); mvwprintw(tetris->tet.over.game, 0, 1, "HIGHSCORE"); i = -1; while (++i < 10) { mvwprintw(tetris->tet.over.game, i + 1, 2, "%s", tetris->hscore[i].name); put_score(tetris, tetris->hscore[i].name, 2, i + 1); } }
game playfield::tick( movement& usrInput ) { ticker++; // // give a chance to all sprites to live // for (int i=0; i<numSprites; i++) Sprites[i]->live( usrInput ); for (i=0; i<numLoadedTiles; i++) backgroundTiles[i]->live(); // // take care of fruit display // // DISPLAY FRUIT // duration should be < 1/2 * frequency if ( ticker % fruit_frequency == fruit_duration) { // set field pos field [ fruitX + fruitY * maxX ] = fruit_icon; backBuffer[ fruitX + fruitY * maxX ] = new tile (*get_field_position(fruitX, fruitY)); } // REMOVE FRUIT if (field[ fruitX+fruitY*maxX ] == fruit_icon && ticker%fruit_frequency >= 2*fruit_duration) { // set field pos field [ fruitX + fruitY * maxX ] = spc; backBuffer[ fruitX + fruitY * maxX ] = new tile (*get_field_position(fruitX, fruitY)); } // ok, have there been any important 'events'? // Did the user win? if (numDots == 0) { crntGame = level_done; // some music and stuff... fancy displays e.t.c... Sprites[0]->set_status(dying); // just to delay a bit... Sprites[0]->set_status(eatable); } // we can assume that makman is the first sprite there is... #define makman Sprites[0] int makpos[2]; int makofs, makdir, dummy; makman->get_position( makpos[0], makpos[1], makofs, makdir, dummy, dummy, dummy, dummy, maxX, maxY); makpos[0] *= 32; makpos[1] *= 32; makpos[ makdir ] += abs(makofs); for (i=1;i<numSprites;i++) { int gh[2], ghofs, ghdir; status foe; Sprites[i]->get_position( gh[0], gh[1], ghofs, ghdir, dummy, dummy, dummy, dummy, maxX, maxY); gh[0] *= 32; gh[1] *= 32; gh[ ghdir ] += abs(ghofs); // DETECT colision, if any! int colision = FALSE; // X colision? int xm = (makpos[0]+5 <= gh[0] && gh[0] <= makpos[0]+26); int xg = (gh[0]+5 <= makpos[0] && makpos[0] <= gh[0] +26); int ym = (makpos[1]+5 <= gh[1 ] && gh[1 ] <= makpos[1]+26); int yg = (gh[1]+5 <= makpos[1] && makpos[1] <= gh[1] +26); int xx = ( makpos[1] == gh[1] && (xm || xg)); int yy = ( makpos[0] == gh[0] && (ym || yg)); if ( xx || yy || ((xm||xg) && (ym||yg)) ) colision = TRUE; foe = Sprites[i]->get_status(); if (colision) if (foe == eating) { makman->set_status(dying); lives--; if (lives) { // erase a makman, if there is one field[lives-1] = spc; backBuffer[lives-1] = new tile (*get_field_position(lives-1,0)); } usrInput = move_left; if (lives) { SndEng->play(snd_start); // remove fruit field [ fruitX + fruitY * maxX ] = spc; makman->set_status(eatable); makman->set_pos(10,11); for (int j=1; j<numSprites; j++) { Sprites[j]->set_pos(7+j,9); Sprites[j]->set_status(hatching); } update(FALSE); SndEng->wait(); } else crntGame = game_over; } else if (foe == eatable) if (Sprites[i]->get_status() == eatable) { Sprites[i]->set_status(dying); score += ghost_values [ ghost_value++ ]; } } put_score(); return crntGame; }
int main(int argc, char *argv[]) { int sprite_policy = 1; int cmap_policy = 1; int wait_msec = WAIT_MSEC; struct itimerval value, ovalue; struct sigaction sig_act; int i; scale_log2 = 0; cheat_mode = 0; for (i=1; i<argc; i++){ if (!strcmp("-speed", argv[i])) sprite_policy = 0; else if (!strcmp("-fast", argv[i])) sprite_policy = 0; else if (!strcmp("-doublesize", argv[i])) scale_log2 = 1; else if (!strcmp("-private", argv[i])) cmap_policy = 0; else if (!strcmp("-fit", argv[i])) cmap_policy = 0; else if (!strcmp("-cheat", argv[i])) cheat_mode = 1; else if (!strcmp("-display", argv[i])) win::set_disp_string(argv[++i]); else if (!strcmp("-wait", argv[i])) wait_msec = atoi(argv[++i]); else if (!strcmp("-hiscores", argv[i])) put_score(); else put_usage(); } wbase .event(ClientMessage, &client_message_callback); wscore.event(ClientMessage, &client_message_callback); wbase .event(FocusIn, &focus_in_callback ); wbase .event(FocusOut, &focus_out_callback ); wbase .event(KeyPress, &key_press_callback ); wbase .event(KeyRelease, &key_release_callback ); wchip .event(ButtonPress, &button_press_callback ); wchip .event(ButtonRelease, &button_release_callback); wchip .event(MotionNotify, &motion_callback ); wchip .event(LeaveNotify, &leave_callback ); wbase.make(NULL, 0, 0, MARGIN * 3 + ((WSIZE + MAP_SIZEX) << scale_log2), MARGIN * 2 + (WSIZE << scale_log2), cmap_policy); wchip.make(&wbase, MARGIN, MARGIN, WSIZE << scale_log2, WSIZE << scale_log2, (SCREEN_SIZEX + WSIZE) << scale_log2, (SCREEN_SIZEY + WSIZE) << scale_log2, 320 << scale_log2, 240 << scale_log2, sprite_policy); wradar.make(&wbase, MARGIN * 2 + (WSIZE << scale_log2), MARGIN + ((WSIZE - MAP_SIZEY) << scale_log2), MAP_SIZEX << scale_log2, MAP_SIZEY << scale_log2); wscore.make(NULL, 0, 0, WSCORE_SIZEX, WSCORE_SIZEY); if (link_tiff(spdata, wbase, wchip)) return 1; wbase.title("xkobo"); wbase.set_wm_close(); wbase.hold_size(); wbase.font(NORMAL_FONT); wbase.foreground(wbase.alloc_color(65535, 65535, 65535)); wbase.background(wbase.alloc_color(0, 0, 0)); wbase.map(); wbase.clear(); wchip.foreground(wbase.alloc_color(65535, 65535, 65535)); wchip.background(wbase.alloc_color(0, 0, 0)); wchip.setborder(wbase.alloc_color(0, 0, 0)); wchip.erase_cursor(); wchip.map(); wradar.foreground(wbase.alloc_color(65535, 65535, 65535)); wradar.background(wbase.alloc_color(0, 0, 0)); wradar.setborder(wbase.alloc_color(0, 0, 0)); wradar.map(); wscore.title("xkobo-score"); wscore.set_wm_close(); wscore.hold_size(); wscore.font(NORMAL_FONT); wscore.foreground(wbase.alloc_color(65535, 65535, 50000)); wscore.background(wbase.alloc_color(0, 0, 0)); wscore.map(); wscore.clear(); rand_num.init(); manage.init(); memset(&sig_act, 0, sizeof(sig_act)); sig_act.sa_handler = sig_handle; sigaction(SIGALRM, &sig_act, 0); value.it_interval.tv_sec = 0; value.it_interval.tv_usec = wait_msec * 1000; value.it_value.tv_sec = 0; value.it_value.tv_usec = wait_msec * 1000; setitimer(ITIMER_REAL, &value, &ovalue); for (;;){ if (wait_msec && (signal_delivered == 0)) pause(); signal_delivered = 0; if (manage.mainloop()) break; } return 0; }