int Tetris::gameAbout(GtkAction *action, void *d) { Tetris *t = (Tetris*) d; const gchar * const authors[] = { "Gnome Games Team", NULL }; const gchar * const documenters[] = { "Angela Boyle", NULL }; gchar *license = games_get_license (_("Gnometris")); gtk_show_about_dialog (GTK_WINDOW (t->getWidget()), #if GTK_CHECK_VERSION (2, 11, 0) "program-name", _("Gnometris"), #else "name", _("Gnometris"), #endif "version", VERSION, "comments", _("A classic game of fitting falling blocks together.\n\nGnometris is a part of GNOME Games."), "copyright", "Copyright \xc2\xa9 1999 J. Marcin Gorycki, 2000-2008 Others", "license", license, "website-label", _("GNOME Games web site"), "authors", authors, "documenters", documenters, "translator-credits", _("translator-credits"), "logo-icon-name", "gnome-gnometris", "website", "http://www.gnome.org/projects/gnome-games/", "wrap-license", TRUE, NULL); g_free (license); return TRUE; }
int Tetris::gamePause(GtkAction *action, void *d) { Tetris *t = (Tetris*) d; t->togglePause(); return TRUE; }
int Tetris::timeoutHandler(void *d) { Tetris *t = (Tetris*) d; if (t->paused) return TRUE; if (t->onePause) { t->onePause = false; t->field->redraw(); } else { bool res = t->field->moveBlockDown(); t->field->redraw(); if (res) { t->manageFallen(); if (t->fastFall && t->inPlay) { t->fastFall = false; } } } return TRUE; }
///////////////////////////////////////////////// /// \brief Main function of the program. /// /// Create a Tetris instance and run the game. /// /// \param argc : Number of given command-line parameters. /// \param argv : Command-line parameters. /// \return Program ending status code. ///////////////////////////////////////////////// int main(int argc, char* argv[]) { Tetris tetris; tetris.run(); return EXIT_SUCCESS; }
bool MyApp::OnInit() { srand(time(NULL)); Tetris *tetris = new Tetris(wxT("Tetris")); tetris->Centre(); tetris->Show(true); return true; }
int main(int argc, char **argv) { try { Tetris game; game.run(); return 0; } catch(const std::exception &exc) { std::cerr << exc.what() << std::endl; } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator translator; translator.load("tetris_ru.qm", "."); a.installTranslator(&translator); Tetris w; w.show(); return a.exec(); }
void Tetris::confNotify (GamesConf *conf, const char *group, const char *key, gpointer data) { if (!group) return; Tetris *t = (Tetris *) data; t->initOptions (); t->setOptions (); }
int Tetris::gameEnd(GtkAction *action, void *d) { Tetris *t = (Tetris*) d; g_source_remove(t->timeoutId); t->timeoutId = 0; blocknr_next = -1; t->endOfGame(); return TRUE; }
int main(){ Tetris game; event_handle event_hdl; game.StartTetris(79, 52); // creates the enviroment unsigned long int Event; while(true){ Sleep(10); // sleep added, to increase performance Event = event_hdl.getEvent(); // gets any buttons pressed and the windows focus if(!game.RunTetris(Event)) break; // everything else } return 0; }
int Tetris::gameNew(GtkAction *action, void *d) { Tetris *t = (Tetris*) d; if (t->timeoutId) { g_source_remove(t->timeoutId); t->timeoutId = 0; /* Catch the case where we started a new game without * finishing the old one. */ if ((t->scoreFrame->getScore() > 0) && t->inPlay) t->high_scores->add (t->scoreFrame->getScore()); } t->inPlay = true; int level = t->cmdlineLevel ? t->cmdlineLevel : t->startingLevel; t->fastFall = false; t->scoreFrame->setLevel(level); t->scoreFrame->setStartingLevel(level); t->field->setUseTarget (t->useTarget); t->generateTimer (level); t->field->emptyField(t->line_fill_height,t->line_fill_prob); t->scoreFrame->resetScore(); t->paused = false; t->field->generateFallingBlock(); t->field->redraw(); t->preview->previewBlock(blocknr_next, rot_next, color_next); gtk_widget_queue_draw(t->preview->getWidget()); gtk_action_set_visible(t->pause_action, TRUE); gtk_action_set_visible(t->resume_action, FALSE); gtk_action_set_sensitive(t->pause_action, TRUE); gtk_action_set_sensitive(t->end_game_action, TRUE); gtk_action_set_sensitive(t->preferences_action, FALSE); t->field->hidePauseMessage(); t->field->hideGameOverMessage(); games_sound_play ("gnometris"); return TRUE; }
int Tetris::gameHelp(GtkAction *action, void *data) { Tetris *t = (Tetris*) data; GError *error = NULL; gtk_show_uri (gtk_widget_get_screen (t->getWidget ()), "help:gnometris", gtk_get_current_event_time (), &error); if (error) g_warning ("Failed to show help: %s", error->message); g_clear_error (&error); return TRUE; }
int main(int argc, char *argv[]) { ALLEGRO_DISPLAY *display; unsigned int ticks = 0; if (!al_init()) { std::cerr << "[ERROR] Error initializing Allegro" << std::endl; } display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT); if (!display) { std::cerr << "[ERROR] Error creating Allegro display" << std::endl; } al_install_audio(); al_install_keyboard(); al_init_primitives_addon(); al_init_acodec_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_image_addon(); al_reserve_samples(10); srand(time(NULL)); ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); ALLEGRO_EVENT_QUEUE *timerQueue = al_create_event_queue(); al_register_event_source(timerQueue, al_get_timer_event_source(timer)); al_start_timer(timer); Tetris *game = new Tetris(SCREEN_WIDTH, SCREEN_HEIGHT, timerQueue); while (game->update(ticks)) { game->render(); ++ticks; } delete game; al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(timerQueue); return 0; }
void Interface::rightMove() { Tetris copy = ArrayTe[rear]; copy.right_move(20); bool canMove = true; for (int i = 0; i < 4; i++) { if (sc[copy.trans_to_yindex(i)][copy.trans_to_xindex(i)]){ canMove = false; break; } } if (canMove) ArrayTe[rear].right_move(20); }
int main( int argc, char** argv ) { (void)argc; (void)argv; try{ Tetris tetris; tetris.run(); }catch( std::exception& ex ){ std::cerr << ex.what() << std::endl; return 1; } return 0; }
void getOutput( OutputPack* opack ) { if ( tetris_output == NULL ) { tetris_output = opack ; } // Clear screen if ( system("clear") ) { system("cls"); } // Print tetris printMatrix( opack->tetris , TT_NONE , ' ' ); // Print time printf("Time : %f\n" , trt.getGameplayTime() ); // Print erased lines if ( opack->didEraseLines ) { printf("Deleted Rows : %d\n" , opack->numOfErasedLines ); } }
int main(int argc, char* argv[]){ try { setWorkdir(); Tetris tetris; tetris.play(); } catch (TetrisException& e) { std::cerr << "Tetris exception occured:\n" << e.what(); } catch (std::exception& e){ std::cerr << "Standard exception occured: \n" << e.what(); } }
static void timerCallback (int value) { tetris.MoveDown(); /* call back again after elapsedUSecs have passed */ glutTimerFunc (tetris.msecs, timerCallback, value); display(); }
int main (void) { cout << "Genetic Algorithm Tetris version 0.1" << endl; // The pieces that will allow us to play some tetris Tetris tetris; Controller controller; Display_Manager output; // Connect the pieces //tetris.input = controller; //output.feed = tetris.state; // Let it rip! tetris.run (); return 0; }
InputPack* sendInput( void ) { trt.externCodeTimeFactor = 1000; int user_input; ipack.rotate = ipack.move = false; if ( kbhit() ) { user_input = getch(); if ( ! trt.gamePaused() ) { if ( user_input == KEYBOARD_SPECIAL_CHARS ) { switch ( getch() ) { case KEYBOARD_ARROW_RIGHT : { ipack.move = true; ipack.dir = TMD_RIGHT; break; } case KEYBOARD_ARROW_LEFT : { ipack.move = true; ipack.dir = TMD_LEFT; break; } case KEYBOARD_ARROW_DOWN : { ipack.move = true; ipack.dir = TMD_DOWN; break; } } } else if ( user_input == ' ' ) { ipack.rotate = true; ipack.trnd = TRT_LEFT; } } if ( user_input == 'p' || user_input == 'P' ) { if ( trt.gamePaused() ) { ipack.pause = false; } else { ipack.pause = true; } } } fflush( stdin ); return &ipack; }
int main() { const int FRAMES_PER_SECOND = 25; const int SKIP_TICKS = 1000 / FRAMES_PER_SECOND; const int MAX_FRAMESKIP = 10; unsigned long next_game_tick = GetTickCount(); int loops = 0; Tetris game; printf("Game initializing\n"); game.init(); printf("Game initialized\n"); View view; view.init(game); //int sleep_time = 0; int quit = 0; bool game_is_running = true; while( game_is_running ) { while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { quit = view.getInput(); next_game_tick += SKIP_TICKS; loops++; } if(quit == 1) { game.pause(); quit = 0; } else if(quit == 2) { game_is_running = false; quit = 0; } game.update(); view.update(); } return 0; }
void keyboard(unsigned char Key, int x, int y){ switch(Key){ case 'j': tetris.MoveDown(); break; case 'k': tetris.MoveRotate(); break; case 'h': tetris.MoveLeft(); break; case 'l': tetris.MoveRight(); break; default: break; }; display(); }
void display(void) { /* clear window */ glClear(GL_COLOR_BUFFER_BIT); /* draw unit square polygon */ tetris.displayTetris(); /* flush GL buffers */ glFlush(); }
int main( void ) { // Set IO functions trt.IO.setInputFunction( &sendInput ); trt.IO.setOutputFunction( &getOutput ); // Set tetris speed in milliseconds trt.speed = 400; // Start playing game trt.newGame( WIDTH , HEIGHT ); return 0; }
int main(int argc, char** argv) { std::string ipAddress(""); if (argc > 1) { if (stricmp(argv[1], "--server") == 0) { g_networkPtr = new TetrisServer(); } else { ipAddress = argv[1]; g_networkPtr = new TetrisClient(ipAddress); } } if (g_networkPtr != NULL) { if (!g_networkPtr->Init()) { delete g_networkPtr; g_networkPtr = NULL; } } sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "SFML TETRIS"); sf::View playerView; GameManager gameMgr; Tetris* localGame = new Tetris(); localGame->Init(); gameMgr.AddGame(localGame, sf::FloatRect(.5, 0, 0.4, .4)); Tetris* otherGame = new Tetris(); otherGame->Init(); gameMgr.AddGame(otherGame, sf::FloatRect(0.5, 0.5, .4, 0.4)); sf::Clock clock; while (window.isOpen() && gameMgr.IsRunning()) { if (g_networkPtr != NULL) { g_networkPtr->Loop(); } sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } sf::Time time = clock.restart(); gameMgr.Update(&window, time.asSeconds()); //window.setView(window.getDefaultView()); //window.clear(sf::Color(40, 40, 40)); //game.Draw(&window); window.display(); } if (g_networkPtr != NULL) { delete g_networkPtr; g_networkPtr = NULL; } return 0; }
int main() { twi_init(); srandom(0); //timer_init(); DDRB = 0xff; PORTB = 0x00; uint16_t buttons; uint16_t changed; uint8_t selected = 0; matrix.setFont(font_3x5, codepage_ascii_caps, 3, 5); while (1) { psx.poll(); buttons = psx.buttons(); changed = psx.changed(); if (buttons & PSB_SELECT && changed & PSB_SELECT) { selected++; selected %= 6; } else if (buttons & PSB_SQUARE && changed & PSB_SQUARE) { hsv.addHue(-30); } else if (buttons & PSB_CIRCLE && changed & PSB_CIRCLE) { hsv.addHue(30); } else if (buttons & PSB_PAD_DOWN && changed & PSB_PAD_DOWN) { uint8_t v = hsv.getValue(); switch (v) { case 0xff: hsv.setValue(0x7f); break; case 0x7f: hsv.setValue(0x3f); break; case 0x3f: hsv.setValue(0x1f); break; case 0x1f: hsv.setValue(0x0f); break; case 0x0f: hsv.setValue(0x07); break; case 0x07: hsv.setValue(0x03); break; case 0x03: hsv.setValue(0x01); break; default: hsv.setValue(0x00); } } else if (buttons & PSB_PAD_UP && changed & PSB_PAD_UP) { uint8_t v = hsv.getValue(); switch (v) { case 0x00: hsv.setValue(0x01); break; case 0x01: hsv.setValue(0x03); break; case 0x03: hsv.setValue(0x07); break; case 0x07: hsv.setValue(0x0f); break; case 0x0f: hsv.setValue(0x1f); break; case 0x1f: hsv.setValue(0x3f); break; case 0x3f: hsv.setValue(0x7f); break; default: hsv.setValue(0xff); } } else if (buttons & PSB_PAD_LEFT && changed & PSB_PAD_LEFT) { uint8_t s = hsv.getSaturation(); switch (s) { case 0xff: hsv.setSaturation(0xfe); break; case 0xfe: hsv.setSaturation(0xfc); break; case 0xfc: hsv.setSaturation(0xf8); break; case 0xf8: hsv.setSaturation(0xf0); break; case 0xf0: hsv.setSaturation(0xe0); break; case 0xe0: hsv.setSaturation(0xc0); break; case 0xc0: hsv.setSaturation(0x80); break; default: hsv.setSaturation(0x00); } } else if (buttons & PSB_PAD_RIGHT && changed & PSB_PAD_RIGHT) { uint8_t s = hsv.getSaturation(); switch (s) { case 0x00: hsv.setSaturation(0x80); break; case 0x80: hsv.setSaturation(0xc0); break; case 0xc0: hsv.setSaturation(0xe0); break; case 0xe0: hsv.setSaturation(0xf0); break; case 0xf0: hsv.setSaturation(0xf8); break; case 0xf8: hsv.setSaturation(0xfc); break; case 0xfc: hsv.setSaturation(0xfe); break; default: hsv.setSaturation(0xff); } } else if (buttons & PSB_START && changed & PSB_START) { switch (selected) { case 0: { Clock clk; clk.run(); break; } case 1: { AltClock alt; alt.run(); break; } case 2: { Life life; life.run(); break; } case 3: { Mood mood; mood.run(); break; } case 4: { Animated ani; ani.run(); break; } case 5: { Tictactoe ttt; ttt.run(); break; } case 6: { Tetris tet; tet.run(); break; } } } matrix.setColor(0,0,0); matrix.rectangle(0,0,11,11, DRAW_FILLED); matrix.setColor(Rgb(hsv)); switch (selected) { case 0: matrix.text(0, 3, "CLK", DRAW_ORIENTATION_0); break; case 1: matrix.text(0, 3, "ALT", DRAW_ORIENTATION_0); break; case 2: matrix.text(0, 3, "LIF", DRAW_ORIENTATION_0); break; case 3: matrix.text(0, 3, "MOO", DRAW_ORIENTATION_0); break; case 4: matrix.text(0, 3, "ANI", DRAW_ORIENTATION_0); break; case 5: matrix.text(0, 3, "TTT", DRAW_ORIENTATION_0); break; case 6: matrix.text(0, 3, "TET", DRAW_ORIENTATION_0); break; } matrix.flush(); _delay_ms(127); } }
GameObject::GameObject(Tetris& tetris) : m_tetris(tetris), m_window(tetris.getWindow()) {}
void Game::start(const int TICKS_PER_SECOND, const int MAX_FRAMESKIP) { bool quit = false; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; Uint32 next_tick = SDL_GetTicks(); Uint32 fps_ticks = SDL_GetTicks(); Uint32 fps = 0; SDL_Rect fpsRenderRect = { 10, 10, 50, 30 }; SDL_Color fpsColor = {255, 255, 255, 255}; int loops; float interpolation; Tetris tetris; tetris.init(); SDL_Event e; GLuint MatrixID = glGetUniformLocation(_programID, "mvp"); bool moveUp = false; bool moveDown = false; bool moveLeft = false; bool moveRight = false; float testValY = 0.0f; float testValX = 0.0f; bool projectionMod = false; float angle = 0.0f; float prevAngle = angle; glm::mat4 Projection = glm::perspective(glm::radians(90.0f), _screen.x / _screen.y, 0.1f, 100.0f); glm::mat4 View = glm::lookAt( glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0) ); glm::mat4 Translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f)); glm::mat4 Scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.0)); glm::mat4 Rotate = glm::rotate(glm::mat4(1.0f), 0.0f, glm::vec3(0.0f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; while(!quit) { loops = 0; while (SDL_GetTicks() > next_tick && loops < MAX_FRAMESKIP) { if (SDL_GetTicks() > fps_ticks) { float fps_delta = (SDL_GetTicks() - fps_ticks) / 1000.0f; fps = Uint32(1.0 / fps_delta); } while(SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { quit = true; } if (e.type == SDL_KEYDOWN) { switch( e.key.keysym.sym ) { case SDLK_UP: moveUp = true; break; case SDLK_DOWN: moveDown = true; break; case SDLK_LEFT: moveLeft = true; break; case SDLK_RIGHT: moveRight = true; break; case SDLK_RETURN: projectionMod = !projectionMod; default: break; } } if (e.type == SDL_KEYUP) { switch( e.key.keysym.sym ) { case SDLK_UP: moveUp = false; break; case SDLK_DOWN: moveDown = false; break; case SDLK_LEFT: moveLeft = false; break; case SDLK_RIGHT: moveRight = false; break; default: break; } } tetris.handleInput(e); } tetris.update(); if (moveRight) { testValX += 0.1f; } if (moveLeft) { testValX -= 0.1f; } if (moveUp) { testValY += 0.1f; } if (moveDown) { testValY -= 0.1f; } prevAngle = angle; angle += 0.1f; if (angle > 360.f) { angle = 0.f; } next_tick += SKIP_TICKS; loops++; } interpolation = float(SDL_GetTicks() + SKIP_TICKS - next_tick) / float(SKIP_TICKS); Projection = glm::perspective(glm::radians(45.0f), _screen.x / _screen.y, 0.1f, 100.0f); if (projectionMod) { Projection = glm::ortho(-10.0f * (_screen.x / _screen.y), 10.0f * (_screen.x / _screen.y), -10.0f, 10.0f, 0.0f, 100.0f); } View = glm::lookAt( glm::vec3(0, 0, 4), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0) ); Translate = glm::translate(glm::mat4(1.0f), glm::vec3(testValX, testValY, 0.0f)); Scale = glm::scale(glm::mat4(1.0f), glm::vec3(0.5)); Rotate = glm::rotate(glm::mat4(1.0f), glm::mix(prevAngle, angle, interpolation), glm::vec3(1.0f, 1.0f, 0.0f)); Model = Translate * Rotate * Scale; MVP = Projection * View * Model; //Clear the screen glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(_programID); glUniformMatrix4fv(MatrixID, 1, GL_FALSE, glm::value_ptr(MVP)); glBindBuffer(GL_ARRAY_BUFFER, _VBO); glEnableVertexAttribArray(_vertexPos2DLocation); glVertexAttribPointer(_vertexPos2DLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, _cVBO); glEnableVertexAttribArray(_vertexColor); glVertexAttribPointer(_vertexColor, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _IBO); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL); glDisableVertexAttribArray(_vertexPos2DLocation); glDisableVertexAttribArray(_vertexColor); glUseProgram(NULL); tetris.render(interpolation); //Render FPS fps_ticks = SDL_GetTicks(); SDL_GL_SwapWindow(_window); } }
void Interface::draw(Tetris next) { int j; next.set_offset(270, 110); setfillcolor(EGERGB(next.getR(), next.getG(), next.getB())); for (j = 0; j < 4; j++) { bar(next.getXCoord(j) - 10, next.getYCoord(j) - 10, next.getXCoord(j) + 10, next.getYCoord(j) + 10); setcolor(WHITE); rectangle(next.getXCoord(j) - 10, next.getYCoord(j) - 10, next.getXCoord(j) + 10, next.getYCoord(j) + 10); } }
void GameOnSelect( VariantList* pVList ) { Entity *pEntClicked = pVList->m_variant[1].GetEntity(); Tetris* tetris = Tetris::GetInstance(); Config* config = Config::GetInstance(); if( pEntClicked->GetName() == GUI_IMAGEBUTTON_GAMEPLAY_MENU_BUTTON ) { GetApp()->buttonClickSound(); if( tetris->isEndGame() ) { SlideScreen( pEntClicked->GetParent(), false ); GetMessageManager()->CallEntityFunction( pEntClicked->GetParent(), 500, "OnDelete", NULL ); GetApp()->setGame( false ); GetApp()->setContinueBtn( false ); if( tetris->getScoreInt() > config->getMinScore() ) { GameState::SetState( new GS_Menu() ); InputBestScoreCreate( pEntClicked->GetParent()->GetParent() ); } else { tetris->ResetEndGame(); GameState::SetState( new GS_Menu() ); MainMenuCreate( pEntClicked->GetParent()->GetParent() ); } tetris->FreeInstance(); config->FreeInstance(); return; } GameState::SetState( new GS_Menu() ); if( config->getMusic() ) { GetAudioManager()->StopMusic(); } GetApp()->setGame( false ); SlideScreen( pEntClicked->GetParent(), false ); GetMessageManager()->CallEntityFunction( pEntClicked->GetParent(), 500, "OnDelete", NULL ); MainMenuCreate( pEntClicked->GetParent()->GetParent() ); } if( pEntClicked->GetName() == GUI_IMAGEBUTTON_GAMEPLAY_DOWN && !tetris->isEndGame() ) { if( config->getSoundEffects() ) { GetAudioManager()->Play( GetApp()->getResourceInstance()->getItem(GetApp()->getResolutionType(), RES_TYPE_AUDIO, RES_ID_AUDIO_FIGURE_DOWN ) ); } tetris->ClickForceDown(); } if( pEntClicked->GetName() == GUI_IMAGEBUTTON_GAMEPLAY_LEFT && !tetris->isEndGame() ) { buttonMoveSound(); tetris->ClickLeft(); } if( pEntClicked->GetName() == GUI_IMAGEBUTTON_GAMEPLAY_RIGHT && !tetris->isEndGame() ) { buttonMoveSound(); tetris->ClickRight(); } if( pEntClicked->GetName() == GUI_IMAGEBUTTON_GAMEPLAY_ROTATE && !tetris->isEndGame() ) { buttonMoveSound(); tetris->ClickRotate(); } tetris->FreeInstance(); config->FreeInstance(); }