void gameover(struct game *g) { SDL_Rect r; struct position *p = g->frontend; int pph; /* points per hour */ #if 0 if (g->running == false) return; #endif pph = g->points * 3600.f / (time(NULL) - g->game_time); r.x = p->x + 10; r.y = p->y + p->size * PREVIEW_H + 60; char endMsg[1024]; sprintf(endMsg,"GAME OVER\nYour Score: %i\nPress any key/button",g->points,g->lines_cleared,g->level); sf_puts(screen, &r, endMsg); SDL_UpdateRects(screen, 1, &r); r.y += r.h; SDL_Event e; while (SDL_WaitEvent(&e) && (e.type != SDL_KEYDOWN && e.type != SDL_MOUSEBUTTONDOWN)) { SDL_Delay(10); } #if 0 g->running = false; #endif restart_game(g); }
int snake_move(void) { int sx[100] = {250, 200, 150, 100, 50}; int sy[100] = {300, 300, 300, 300, 300}; int fx = 0; int fy = 0; int f_count = 100; int step = 50; int x_offset = step; int y_offset = 0; int s_len = 5; char dict = 'd'; char new_dict = 0; char flag = 0; char eat_state = 0; barriar(); system("stty raw -echo"); while(flag == 0) { show_food(&fx, &fy, sx, sy, s_len, &f_count); if(move_one_step(sx, sy, x_offset,y_offset, s_len, eat_state) == -1) { restart_game(sx, sy, s_len); dict = 'd'; new_dict = 0; x_offset = step; y_offset = 0; s_len = 5; } eat_state = eat_food(&fx, &fy, sx, sy, &s_len,&f_count); new_dict = get_key(); switch(new_dict) { case 'a' : if(dict != 'd') dict = new_dict;break; case 'd' : if(dict != 'a') dict = new_dict;break; case 'w' : if(dict != 's') dict = new_dict;break; case 's' : if(dict != 'w') dict = new_dict;break; case 'q' : dict = new_dict; default : break; } switch(dict) { case 'a' : x_offset=-step; y_offset=0;break; case 'd' : x_offset=step; y_offset=0;break; case 'w' : x_offset=0; y_offset=-step;break; case 's' : x_offset=0; y_offset=step;break; case 'q' : flag = 1;break; default : break; } usleep(1000); } system("stty cooked echo"); return 0; }
int main () { freeze (1); update_status = 0; sp_nodraw (1, 1); fill_screen (0); sp_noclip (create_sprite (76, 40, "none", "button-start", 1), 1); sp_noclip (create_sprite (524, 40, "none", "button-continue", 2), 1); sp_noclip (create_sprite (104, 440, "none", "button-ordering", 1), 1); sp_noclip (create_sprite (560, 440, "none", "button-quit", 1), 1); make_start.build (); say_stop ("I thought you won already?", g_daniel); say_stop ("I did!", g_dink); say_stop ("Am I dead already?", g_eggeric); say_stop ("I'm afraid so...", g_adelbrecht); say_stop ("That's not a bad thing at all!", g_machteld); say_stop ("Anyway, no point to continue, the story is over.", g_daniel); restart_game (); }
//State Machine Definitions int tickFct_Keypad(int state) { char key = GetKeypadKey(); switch(state) { case keypad_start: state = keypad_poll; break; case keypad_poll: state = keypad_poll; break; } switch(state) { case keypad_start: break; case keypad_poll: switch(key) { case '\0': break; case '1': if( gameover == OFF ) { toggle_pause(); } else if( gameover == ON ) { restart_game(); } break; case '4': if( gameover == OFF ) { move_player(PLAYER_TOP); } break; case '7': if( gameover == OFF ) { move_player(PLAYER_BOT); } break; default: break; } break; } return state; }
void die () { int r; freeze (1); sp_base_idle (1, ""); sp_brain (1, "none"); sp_seq (1, "die"); sp_frame (1, 1); sp_nohit (1, 1); wait (3000); while (1) { r = choice ("Load", "Restart", "Quit"); if (r == 1) escape.load (); else if (r == 2) restart_game (); else if (r == 3) kill_game (); } }
void die( void ) { freeze(1); &update_status = 0; int &mholdx = sp_x(1,-1); int &mholdy = sp_y(1,-1) //int &crap = create_sprite(&mholdx,&mholdy,5,436,1); sp_seq(1, 436); sp_base_idle(1, -1); wait(3000); sp_nohit(1, 1); sp_brain(1, 0); again: choice_start(); "Load a previously saved game" "Restart game" "Quit to system" choice_end(); if (&result == 1) { load(); kill_this_task(); } if (&result == 2) { sp_nohit(1, 0); restart_game(); } if (&result == 3) { kill_game(); } }
void post_script_cleanup() { // should do any post-script stuff here, like go to new room if (ccError) quit(ccErrorString); ExecutingScript copyof = scripts[num_scripts-1]; // write_log("Instance finished."); if (scripts[num_scripts-1].forked) delete scripts[num_scripts-1].inst; num_scripts--; inside_script--; if (num_scripts > 0) curscript = &scripts[num_scripts-1]; else { curscript = NULL; } // if (abort_executor) user_disabled_data2=aborted_ip; int old_room_number = displayed_room; // run the queued post-script actions for (int ii = 0; ii < copyof.numPostScriptActions; ii++) { int thisData = copyof.postScriptActionData[ii]; switch (copyof.postScriptActions[ii]) { case ePSANewRoom: // only change rooms when all scripts are done if (num_scripts == 0) { new_room(thisData, playerchar); // don't allow any pending room scripts from the old room // in run_another to be executed return; } else curscript->queue_action(ePSANewRoom, thisData, "NewRoom"); break; case ePSAInvScreen: invscreen(); break; case ePSARestoreGame: cancel_all_scripts(); try_restore_save(thisData); return; case ePSARestoreGameDialog: restore_game_dialog(); return; case ePSARunAGSGame: cancel_all_scripts(); load_new_game = thisData; return; case ePSARunDialog: do_conversation(thisData); break; case ePSARestartGame: cancel_all_scripts(); restart_game(); return; case ePSASaveGame: save_game(thisData, copyof.postScriptSaveSlotDescription[ii]); break; case ePSASaveGameDialog: save_game_dialog(); break; default: quitprintf("undefined post script action found: %d", copyof.postScriptActions[ii]); } // if the room changed in a conversation, for example, abort if (old_room_number != displayed_room) { return; } } int jj; for (jj = 0; jj < copyof.numanother; jj++) { old_room_number = displayed_room; QueuedScript &script = copyof.ScFnQueue[jj]; RunScriptFunction(script.Instance, script.FnName, script.ParamCount, script.Param1, script.Param2); if (script.Instance == kScInstRoom && script.ParamCount == 1) { // some bogus hack for "on_call" event handler play.roomscript_finished = 1; } // if they've changed rooms, cancel any further pending scripts if ((displayed_room != old_room_number) || (load_new_game)) break; } copyof.numanother = 0; }
int main(int argc, char *argv[]) { // define usage const char *usage = "Usage: sudoku n00b|l33t [#]\n"; // ensure that number of arguments is as expected if (argc != 2 && argc != 3) { fprintf(stderr, usage); return 1; } // ensure that level is valid if (strcmp(argv[1], "debug") == 0) g.level = "debug"; else if (strcmp(argv[1], "n00b") == 0) g.level = "n00b"; else if (strcmp(argv[1], "l33t") == 0) g.level = "l33t"; else { fprintf(stderr, usage); return 2; } // n00b and l33t levels have 1024 boards; debug level has 9 int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024; // ensure that #, if provided, is in [1, max] if (argc == 3) { // ensure n is integral char c; if (sscanf(argv[2], " %d %c", &g.number, &c) != 1) { fprintf(stderr, usage); return 3; } // ensure n is in [1, max] if (g.number < 1 || g.number > max) { fprintf(stderr, "That board # does not exist!\n"); return 4; } // seed PRNG with # so that we get same sequence of boards srand(g.number); } else { // seed PRNG with current time so that we get any sequence of boards srand(time(NULL)); // choose a random n in [1, max] g.number = rand() % max + 1; } // start up ncurses if (!startup()) { fprintf(stderr, "Error starting up ncurses!\n"); return 5; } // register handler for SIGWINCH (SIGnal WINdow CHanged) signal(SIGWINCH, (void (*)(int)) handle_signal); // start the first game if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } redraw_all(); // initialize legal variable g.legal = true; // initialize won variable g.won = false; // let the user play! int ch; do { // refresh the screen refresh(); // get user's input ch = getch(); // capitalize input to simplify cases ch = toupper(ch); // process user's input switch (ch) { // start a new game case 'N': g.number = rand() % max + 1; if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // restart current game case 'R': if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // let user manually redraw screen with ctrl-L case CTRL('l'): redraw_all(); break; // move cursor on the board case KEY_DOWN: case KEY_UP: case KEY_LEFT: case KEY_RIGHT: move_cursor(ch); break; case KEY_BACKSPACE: case KEY_DC: case 46: // . case 48: // 0 case 49: // 1 case 50: // 2 case 51: // 3 case 52: // 4 case 53: // 5 case 54: // 6 case 55: // 7 case 56: // 8 case 57: // 9 change_number(ch); if(!legal(ch)) { show_banner("Illegal Move..."); show_cursor(); g.legal = false; } else { hide_banner(); show_cursor(); g.legal = true; } if(won(ch)) { show_banner("You Won The Game!!!"); g.won = true; } break; } // log input (and board's state) if any was received this iteration if (ch != ERR) log_move(ch); } while (ch != 'Q'); // shut down ncurses shutdown(); // tidy up the screen (using ANSI escape sequences) printf("\033[2J"); printf("\033[%d;%dH", 0, 0); // that's all folks printf("\nkthxbai!\n\n"); return 0; }
/** * Start new game with exact same parameters as current. */ int on_select_restart(Control* btn) { restart_game(game); return show_arena(get_root(btn)); }
/* * Main driver for the game. */ int main(int argc, char **argv) { // define usage const char *usage = "Usage: sudoku n00b|l33t [#]\n"; // ensure that number of arguments is as expected if (argc != 2 && argc != 3) { fprintf(stderr, usage); return 1; } // ensure that level is valid if (!strcmp(argv[1], "debug")) g.level = "debug"; else if (!strcmp(argv[1], "n00b")) g.level = "n00b"; else if (!strcmp(argv[1], "l33t")) g.level = "l33t"; else { fprintf(stderr, usage); return 2; } // n00b and l33t levels have 1024 boards; debug level has 9 int max = (!strcmp(g.level, "debug")) ? 9 : 1024; // ensure that #, if provided, is in [1, max] if (argc == 3) { // ensure n is integral char c; if (!sscanf(argv[2], " %d %c", &g.number, &c) == 1) { fprintf(stderr, usage); return 3; } // ensure n is in [1, max] if (g.number < 1 || g.number > max) { fprintf(stderr, "That board # does not exist!\n"); return 4; } // seed PRNG with # so that we get same sequence of boards srand(g.number); } else { // seed PRNG with current time so that we get any sequence of boards srand(time(NULL)); // choose a random n in [1, max] g.number = rand() % max + 1; } // start up ncurses if (!startup()) { fprintf(stderr, "Error starting up ncurses!\n"); return 6; } // register handler for SIGWINCH (SIGnal WINdow CHanged) signal(SIGWINCH, (void (*)(int)) handle_signal); // start the first game if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 7; } redraw_all(); // let the user play! int ch; do { // refresh the screen refresh(); // get user's input ch = getch(); // capitalize input to simplify cases ch = toupper(ch); // process user's input switch (ch) { // left arrow key case KEY_LEFT: case 'H': if (--g.x < 0) g.x += DIM; hide_banner(); show_cursor(); break; // right arrow key case KEY_RIGHT: case 'L': if (++g.x >= DIM) g.x -= DIM; hide_banner(); show_cursor(); break; // up arrow key case KEY_UP: case 'K': if (--g.y < 0) g.y += DIM; hide_banner(); show_cursor(); break; // down arrow key case KEY_DOWN: case 'J': if (++g.y >= DIM) g.y -= DIM; hide_banner(); show_cursor(); break; // enable user to enter numbers case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (g.given[g.y][g.x] == false && validate(ch) == true) { enter_number(ch); draw_numbers(); show_cursor(); won(); } break; // delete a number case KEY_BACKSPACE: case KEY_DC: case '.': case '0': if (g.given[g.y][g.x] == false) { g.board[g.y][g.x] = 0; draw_numbers(); hide_banner(); show_cursor(); } break; // start a new game case 'N': g.number = rand() % max + 1; if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 7; } break; // restart current game case 'R': if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 7; } break; // let user manually redraw screen with ctrl-L case CTRL('l'): redraw_all(); break; } // end switch statement // log input (and board's state) if any was received this iteration if (ch != ERR) log_move(ch); } while (ch != 'Q'); // shut down ncurses shutdown(); // tidy up the screen (using ANSI escape sequences) printf("\033[2J"); printf("\033[%d;%dH", 0, 0); // kthxbai printf("\nkthxbai!\n\n"); return 0; }
int main(int argc, char *argv[]) { // define usage const char *usage = "Usage: sudoku n00b|l33t [#]\n"; // ensure that number of arguments is as expected if (argc != 2 && argc != 3) { fprintf(stderr, usage); return 1; } // ensure that level is valid if (strcmp(argv[1], "debug") == 0) g.level = "debug"; else if (strcmp(argv[1], "n00b") == 0) g.level = "n00b"; else if (strcmp(argv[1], "l33t") == 0) g.level = "l33t"; else { fprintf(stderr, usage); return 2; } // n00b and l33t levels have 1024 boards; debug level has 9 int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024; // ensure that #, if provided, is in [1, max] if (argc == 3) { // ensure n is integral char c; if (sscanf(argv[2], " %d %c", &g.number, &c) != 1) { fprintf(stderr, usage); return 3; } // ensure n is in [1, max] if (g.number < 1 || g.number > max) { fprintf(stderr, "That board # does not exist!\n"); return 4; } // seed PRNG with # so that we get same sequence of boards srand(g.number); } else { // seed PRNG with current time so that we get any sequence of boards srand(time(NULL)); // choose a random n in [1, max] g.number = rand() % max + 1; } ////////////// for (int m=0; m<9; m++) { for (int n=0; n<9; n++) { g.badMoves[m][n]=0; } } // start up ncurses if (!startup()) { fprintf(stderr, "Error starting up ncurses!\n"); return 5; } // register handler for SIGWINCH (SIGnal WINdow CHanged) signal(SIGWINCH, (void (*)(int)) handle_signal); // start the first game if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } redraw_all(); // let the user play! int ch; do { // refresh the screen refresh(); // get user's input ch = getch(); //check won // capitalize input to simplify cases ch = toupper(ch); // process user's input switch (ch) { // start a new game case 'N': g.number = rand() % max + 1; if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // restart current game case 'R': if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // let user manually redraw screen with ctrl-L case CTRL('l'): redraw_all(); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //getting input as a char and logging as the ascii value case '9': movenumber=9; if (tempBoard[g.y][g.x]!=0)/// break;/// if (check_valid(movenumber)) { g.board[g.y][g.x]=9; draw_numbers(); show_cursor();//// //printf ("%c" g.board[3][3]); //printf ("%c" tempBoard[3][3]); } break; case '8': movenumber=8; if (tempBoard[g.y][g.x]!=0)/// break;/// if (check_valid(movenumber)) { g.board[g.y][g.x]=8; draw_numbers(); show_cursor();//// } break; case '7': movenumber=7; if (tempBoard[g.y][g.x]!=0)/// break;/// if (check_valid(movenumber)) { g.board[g.y][g.x]=7; draw_numbers(); show_cursor();//// } break; case '6': movenumber=6; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=6; draw_numbers(); show_cursor();//// break; case '5': movenumber=5; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=5; draw_numbers(); show_cursor();//// break; case '4': movenumber=4; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=4; draw_numbers(); show_cursor();//// break; case '3': movenumber=3; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=3; draw_numbers(); show_cursor();//// break; case '2': movenumber=2; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=2; draw_numbers(); show_cursor();//// break; case '1': movenumber=1; if (tempBoard[g.y][g.x]!=0)/// break;/// check_valid(movenumber); g.board[g.y][g.x]=1; draw_numbers(); show_cursor();//// break; case '0': break; case KEY_UP: // move cursor to new place if (g.y<1) { g.y = 8; } else g.y = g.y-1; show_cursor(); break; case KEY_DOWN: // move cursor to new place if (g.y>7) { g.y = 0; } else g.y = g.y+1; show_cursor(); break; case KEY_RIGHT: // move cursor to new place if (g.x>7) { g.x = 0; } else g.x = g.x+1; show_cursor(); break; case KEY_LEFT: // move cursor to new place if (g.x<1) { g.x = 8; } else g.x = g.x-1; show_cursor(); break; } // log input (and board's state) if any was received this iteration if (ch != ERR) log_move(ch); if (!badBanner()) { hide_banner(); show_cursor(); } ////call badBanner } ///////////////////////////////goes with do way above//////// while (ch != 'Q'); // shut down ncurses shutdown(); // tidy up the screen (using ANSI escape sequences) printf("\033[2J"); printf("\033[%d;%dH", 0, 0); // that's all folks printf("\nkthxbai!\n\n"); return 0; }
int main(int argc, char *argv[]) { // define usage const char *usage = "Usage: sudoku n00b|l33t [#]\n"; // ensure that number of arguments is as expected if (argc != 2 && argc != 3) { fprintf(stderr, usage); return 1; } // ensure that level is valid if (strcmp(argv[1], "debug") == 0) g.level = "debug"; else if (strcmp(argv[1], "n00b") == 0) g.level = "n00b"; else if (strcmp(argv[1], "l33t") == 0) g.level = "l33t"; else { fprintf(stderr, usage); return 2; } // n00b and l33t levels have 1024 boards; debug level has 9 int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024; // ensure that #, if provided, is in [1, max] if (argc == 3) { // ensure n is integral char c; if (sscanf(argv[2], " %d %c", &g.number, &c) != 1) { fprintf(stderr, usage); return 3; } // ensure n is in [1, max] if (g.number < 1 || g.number > max) { fprintf(stderr, "That board # does not exist!\n"); return 4; } // seed PRNG with # so that we get same sequence of boards srand(g.number); } else { // seed PRNG with current time so that we get any sequence of boards srand(time(NULL)); // choose a random n in [1, max] g.number = rand() % max + 1; } // start up ncurses if (!startup()) { fprintf(stderr, "Error starting up ncurses!\n"); return 5; } // register handler for SIGWINCH (SIGnal WINdow CHanged) signal(SIGWINCH, (void (*)(int)) handle_signal); // start the first game if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } redraw_all(); // let the user play! int ch; int last[3] = {10}; do { // refresh the screen refresh(); // get user's input ch = getch(); // capitalize input to simplify cases ch = toupper(ch); // process user's input switch (ch) { // start a new game case 'N': g.number = rand() % max + 1; if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // restart current game case 'R': if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // let user manually redraw screen with ctrl-L case CTRL('l'): redraw_all(); break; case 'U': case CTRL('Z'): if (last[0] != 10 && !game_won()) { g.board[last[0]][last[1]] = last[2]; draw_numbers(); if (check_cols(1) || check_rows(1) || check_squares(1)) hide_banner(); show_cursor(); warn(); } break; // move cursor case KEY_UP: if (g.y > 0) { g.y -= 1; show_cursor(); } else { g.y = 8; show_cursor(); } break; case KEY_DOWN: if (g.y < 8) { g.y += 1; show_cursor(); } else { g.y = 0; show_cursor(); } break; case KEY_LEFT: if (g.x > 0) { g.x -= 1; show_cursor(); } else { g.x = 8; show_cursor(); } break; case KEY_RIGHT: if (g.x < 8) { g.x += 1; show_cursor(); } else { g.x = 0; show_cursor(); } break; //input number and check if game is won case '1' ... '9': if (g.init_board[g.y][g.x] == 0) { last[0] = g.y; last[1] = g.x; last[2] = g.board[g.y][g.x]; g.board[g.y][g.x] = ch - 48; draw_numbers(); if (check_cols(1) || check_rows(1) || check_squares(1)) hide_banner(); show_cursor(); } game_won(); warn(); break; //return to blank space case '0': case '.': case KEY_BACKSPACE: case KEY_DC: if (g.init_board[g.y][g.x] == 0) { last[0] = g.y; last[1] = g.x; last[2] = g.board[g.y][g.x]; g.board[g.y][g.x] = 0; draw_numbers(); if (check_cols(1) || check_rows(1) || check_squares(1)) hide_banner(); show_cursor(); } warn(); break; } // log input (and board's state) if any was received this iteration if (ch != ERR) log_move(ch); } while (ch != 'Q'); // shut down ncurses shutdown(); // tidy up the screen (using ANSI escape sequences) printf("\033[2J"); printf("\033[%d;%dH", 0, 0); // that's all folks printf("\nkthxbai!\n\n"); return 0; }