int bootmgr_touch_tetris() { bootmgr_selected = 3; bootmgr_set_time_thread(0); bootmgr_phase = BOOTMGR_TETRIS; tetris_init(); return TCALL_DELETE; }
static void tetris_pre_open(void) { setup_game_panel(RS_GAME_TETRIS, RS_GAME_CLASS, RS_GAME_LINES, RS_GAME_SCORE); cyclic_tetris_def(); tetris_init(); Speed = 3; Erasered = 0; TotalMark = 0; update_status(Speed, Erasered, TotalMark); }
int main(int argc, char *argv[]) { g_debug("Initializing lua"); lua_state = luaL_newstate(); luaL_openlibs(lua_state); g_debug("Initializing libtetris"); tetris_init(); tetris_plugin_init(lua_state); tetris_lua_functions_setup(); g_debug("Initializing GLib and GTK"); gdk_threads_init(); gtk_init(&argc, &argv); g_debug("Creating main window"); mainwindow = mainwindow_new(); g_signal_connect(G_OBJECT(mainwindow->window), "delete-event", G_CALLBACK(quit_everything), NULL); g_signal_connect(G_OBJECT(mainwindow->window), "destroy-event", G_CALLBACK(quit_everything), NULL); g_debug("Initializing clients plugins"); plugins_init(lua_state, mainwindow); g_debug("Loading config.lua"); if (luaL_loadfile(lua_state, "config.lua") != 0 || lua_pcall(lua_state, 0, 0, 0) != 0) g_warning("Unable to load or run config.lua: %s", lua_tostring(lua_state, -1)); g_debug("Launching main loop"); gtk_main(); return 0; }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif /* ltris info */ printf( "LTris %s\nCopyright 2002-2005 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); #ifndef SOUND printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ /* game ids - not translated to be fixed independant of language */ strcpy(gametype_ids[0],"demo"); strcpy(gametype_ids[1],"classic"); strcpy(gametype_ids[2],"figures"); strcpy(gametype_ids[3],"vshuman"); strcpy(gametype_ids[4],"vscpu"); strcpy(gametype_ids[5],"vshumanhuman"); strcpy(gametype_ids[6],"vshumancpu"); strcpy(gametype_ids[7],"vscpucpu"); /* game names - translated for display */ strcpy(gametype_names[0],_("Demo")); strcpy(gametype_names[1],_("Classic")); strcpy(gametype_names[2],_("Figures")); strcpy(gametype_names[3],_("Vs Human")); strcpy(gametype_names[4],_("Vs CPU")); strcpy(gametype_names[5],_("Vs Human&Human")); strcpy(gametype_names[6],_("Vs Human&CPU")); strcpy(gametype_names[7],_("Vs CPU&CPU")); config_load(); init_sdl( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ); set_video_mode( std_video_mode( config.fullscreen ) ); SDL_WM_SetCaption( "LTris", 0 ); sdl.fade = config.fade; SDL_SetEventFilter( event_filter ); #ifdef SOUND audio_open(); sound_enable( config.sound ); sound_volume( config.volume * 16 ); #endif /* create */ hint_load_res(); manager_create(); tetris_create(); chart_load(); /* run game */ manager_fade( FADE_IN ); while( !leave && !term_game ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_MAKE_STAT: manager_fade( FADE_OUT ); tetris_make_stat(); manager_fade( FADE_IN ); break; case ACTION_PLAY: manager_fade( FADE_OUT ); if ( tetris_init() ) { tetris_run(); tetris_clear(); } manager_fade( FADE_IN ); break; default: break; } } manager_fade( FADE_OUT ); /* delete stuff */ tetris_delete(); manager_delete(); chart_save(); chart_delete(); hint_delete_res(); #ifdef SOUND audio_close(); #endif config_save(); return EXIT_SUCCESS; }
static PRESULT tetris_key_proc(UINT32 vkey, UINT8 key_repeat_cnt, UINT8 key_status) { UINT8 back_saved; PRESULT ret = PROC_LOOP; if (key_status == PAN_KEY_PRESSED) { switch (vkey) { case V_KEY_UP: ChangeShape(&x, &y, &CurrentShape, &Status); break; case V_KEY_DOWN: GoDown(&x, &y, &CurrentShape, &Status); if (key_repeat_cnt == 0) { /* speed up drop speed */ osal_timer_set(GAME_CYCLIC_ID, 100); speed_up = TRUE; } break; case V_KEY_LEFT: GoLeft(&x, &y, &CurrentShape, &Status); break; case V_KEY_RIGHT: GoRight(&x, &y, &CurrentShape, &Status); break; case V_KEY_ENTER: if (playing == TRUE) { osal_timer_activate(GAME_CYCLIC_ID, FALSE); win_compopup_init(WIN_POPUP_TYPE_OK); win_compopup_set_frame(GET_MID_L(170), GET_MID_T(130), 170, 130); win_compopup_set_msg(NULL, NULL, RS_PAUSE); win_compopup_open_ext(&back_saved); osal_timer_activate(GAME_CYCLIC_ID, TRUE); } break; case V_KEY_MENU: case V_KEY_EXIT: if (playing == TRUE) { osal_timer_activate(GAME_CYCLIC_ID, FALSE); win_compopup_init(WIN_POPUP_TYPE_OKNO); //win_compopup_set_frame(GET_MID_L(250), GET_MID_T(130), 250, 130); win_compopup_set_frame(GET_MID_L(250), GET_MID_T(130), 320, 130); win_compopup_set_msg(NULL, NULL, RS_GAME_MSG_DO_YOU_QUIT); if (win_compopup_open_ext(&back_saved) == WIN_POP_CHOICE_YES) { playing = FALSE; tetris_init(); update_status(Speed, Erasered, TotalMark); tetris_redraw_main(); tetris_redraw_preview(); OSD_SetAttr((POBJECT_HEAD)&txt_start, C_ATTR_ACTIVE); OSD_ChangeFocus((POBJECT_HEAD)&game_con, 1, \ C_UPDATE_FOCUS | C_DRAW_SIGN_EVN_FLG); } else { osal_timer_activate(GAME_CYCLIC_ID, TRUE); } } break; default: ret = PROC_PASS; } } else if (key_status == PAN_KEY_RELEASE) { normal_speed(); } return ret; }
static BOOL GoDown(INT16 *x, INT16 *y, INT8 *CurrentShape, INT8 *Status) { INT8 AllAreOne = 1, removed_lines = 0; INT8 i, j, r, l, rr, ll; UINT8 back_saved; if (Possible(*x, (*y) + 1, *CurrentShape, *Status)) { hide(*x, *y, *CurrentShape, *Status); (*y)++; show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); return TRUE; } normal_speed(); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { back[i + *y][j + *x] += shape[*CurrentShape][*Status][i][j]; } } for (r = 1; r < MAXY; r++)//20 { for (l = 2; l < 2 + MAXX; l++)//13 { if (back[r][l] == 0) { AllAreOne = 0; } } if (AllAreOne == 1) { for (rr = r; rr > 0; rr--) { for (ll = 2; ll < 2 + MAXX; ll++) { back[rr][ll] = back[rr - 1][ll]; } } for (ll = 2; ll < 2 + MAXX; ll++) { back[0][ll] = 0; }//the upper line will be all zero which represented the line is blank Erasered++; if((!(Erasered % 30)) && (Speed < 10)) { Speed++; osal_timer_set(GAME_CYCLIC_ID, TimeDelay[Speed - 1]); } removed_lines++; } AllAreOne = 1; } show(*x, *y, *CurrentShape, *Status, BLOCK_INACTIVE); //sunk the button CreateNewShape(x, y, CurrentShape, Status); if (!Possible(*x, *y, *CurrentShape, *Status)) { playing = FALSE; osal_timer_activate(GAME_CYCLIC_ID, FALSE); win_compopup_init(WIN_POPUP_TYPE_OK); win_compopup_set_frame(GET_MID_L(250), GET_MID_T(130), 250, 130); win_compopup_set_msg(NULL, NULL, RS_GAME_SORRY_YOU_LOST); win_compopup_open_ext(&back_saved); tetris_init(); update_status(Speed, Erasered, TotalMark); tetris_redraw_main(); tetris_redraw_preview(); OSD_SetAttr((POBJECT_HEAD)&txt_start, C_ATTR_ACTIVE); OSD_ChangeFocus((POBJECT_HEAD)&game_con, 1, \ C_UPDATE_FOCUS | C_DRAW_SIGN_EVN_FLG); } TotalMark += (Speed + 1) * (10 + removed_lines - 1) * removed_lines; update_status(Speed, Erasered, TotalMark); if (removed_lines > 0) { tetris_redraw_main(); } if (playing == TRUE) { show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); } return FALSE; }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { struct port_config pin; unsigned char c; system_init(); //Configure UART console. configure_console(); configure_usart_callbacks(); usart_enable_rx_interrupt(&cdc_uart_module,&c); usart_enable(&cdc_uart_module); //Configures TC driver configure_tc(); //Configures TC callback configure_tc_callbacks(); //Initialize the delay driver delay_init(); //Enable system interrupt system_interrupt_enable_global(); //Configures PORT for LED0 port_get_config_defaults(&pin); pin.direction = PORT_PIN_DIR_OUTPUT; port_pin_set_config(LED0_PIN, &pin); port_pin_set_output_level(LED0_PIN, LED0_INACTIVE); port_pin_set_output_level(LED0_PIN, LED0_INACTIVE); /*main loop*/ while(1) { if (is_running) { //Handle user's input // if (uart_getc(&c)) // { switch (c) { case 'w': case ' ': //ROTATE tetris_rotate(); break; case 's': //DOWN tetris_gravity(); break; case 'd': //RIGHT tetris_move_right(); break; case 'a': //LEFT tetris_move_left(); break; default: break; } c=0; // } // was here if(!iterate_game) if(iterate_game) { //Update game iterate_game = false; tetris_gravity(); tetris_check_lines(); terminal_cursor_home(); tetris_print(); if (tetris_is_game_over()) { is_running = false; } } } else { // if (uart_getc(&c)) // { if (c == 'n') { c=0; //Seed random function so we do not get same start condition //for each new game. In essence we will not start a new game //exactly at the same time. srand(tick); //New Game is_running = true; terminal_cursor_off(); terminal_clear(); tetris_init(); tetris_new_block(); terminal_cursor_home(); tetris_print(); } // } } } }
int main(int argc, char *argv[]) { int mode = 0; initscr(); /* Start curses mode */ start_color(); /* Start color functionality */ init_pair(10,COLOR_WHITE,COLOR_WHITE); init_pair(11,COLOR_YELLOW,COLOR_YELLOW); init_pair(12,COLOR_MAGENTA,COLOR_MAGENTA); init_pair(13,COLOR_CYAN,COLOR_CYAN); init_pair(14,COLOR_GREEN,COLOR_GREEN); init_pair(15,COLOR_RED,COLOR_RED); init_pair(16,COLOR_BLUE,COLOR_BLUE); init_pair(17,COLOR_WHITE,COLOR_WHITE); init_pair(18,COLOR_YELLOW,COLOR_YELLOW); init_pair(19,COLOR_MAGENTA,COLOR_MAGENTA); init_pair(20,COLOR_BLACK,COLOR_WHITE); init_pair(21,COLOR_BLACK,COLOR_YELLOW); init_pair(22,COLOR_WHITE,COLOR_MAGENTA); init_pair(23,COLOR_WHITE,COLOR_CYAN); init_pair(24,COLOR_WHITE,COLOR_GREEN); init_pair(25,COLOR_WHITE,COLOR_RED); init_pair(26,COLOR_WHITE,COLOR_BLUE); curs_set(0); noecho(); keypad(stdscr,TRUE); refresh(); WINDOW **logo; WINDOW **menu; int i = 0; int score = 0; while (i == 0) { logo = draw_logo(); menu = draw_menu(); if (score > 0 ) { mode = 1; } else { mode = scroll_menu(menu); } switch (mode) { case 0: delete_menu(menu,5); delete_menu(logo,169); score = tetris_init(); break; case 1: delete_menu(menu,5); if (score > 0) { draw_hiscores(1,score); } else { draw_hiscores(0,score); } score = 0; break; case 2: delete_menu(menu,5); draw_help(); break; case 3: delete_menu(menu,5); delete_menu(logo,169); i = 1; break; } } /*getch();*/ endwin(); /* End curses mode */ }