int main() { if(SetupWindow("Tic-Tac-Toe", 500, 500)) SetupGame(); return 0; }
void GameSpecificMenu (){ char c; BOOLEAN cont = TRUE; while(cont) { printf("\n\nCurrent %dx%d board: \n", width, length); PrintPosition(gInitialPosition, "Gamesman", 0); printf("\tGame Options:\n\n" "\tc)\t(C)hange the board size (nxn), currently: %dx%d\n" //"\ti)\tSet the (I)nitial position\n" "\tr)\t(R)eset to default settings\n" "\tb)\t(B)ack to the main menu\n" "\nSelect an option: ", width, length); c = GetMyChar(); switch(c) { case 'c': case 'C': ChangeBoardSize(); break; case 'i': case 'I': GetInitialPosition(); break; case 'r': case 'R': Reset(); SetupGame(); break; case 'b': case 'B': cont = FALSE; break; default: printf("Invalid option!\n"); } } //InitializeHelpStrings(); }
//----------------------------------------------------------------------------- Game::Game() { m_dice = new Dice(); SetupGame(); CardsManager::initialiseCards(); // CardsManager::printAllCards(); }
void InitializeGame (){ if(!set) { Reset(); set = TRUE; } //InitializeHelpStrings(); SetupGame(); gMoveToStringFunPtr = &MoveToString; }
// This is my primary Event Loop. This is where most of the fun stuff happens ;) void Megamaniac() { // WTF does this do? Something to do with my Data Structure I assume... Game game; while (true) { // Let's run our initial setup to get everything for the game ready. SetupGame(&game); // Do we need to change the level? Not really but we should probably start at Level 1. ChangeLevel(&game); // This is where the Event Loop actually starts. This will run repeatedly until our game is over. while (!game.game_over) { clear_screen(); GameStats(&game); int userInput = UserInput(&game); MovementPlayer(&game, userInput); MovementMissiles(&game, userInput); MovementAliens(&game); MovementBombs(&game); MovementBonuses(&game); CollisionMissiles(&game); CollisionAliens(&game); CollisionBombs(&game); CollisionBonuses(&game); UpdateScreen(&game); show_screen(); timer_pause(25); } GameOver(&game); int userInput = wait_char(); while (userInput != 'r' && userInput >= 0) { if (userInput == 'q') { exit(0); } if (userInput == 'r') { Megamaniac(); } userInput = wait_char(); } } }
//----------------------------------------Game Loop int main() { SetupGame(); //this is the game loop. this loops forever. while (1) { SHOW_SPRITES; //monster stuff MonsterUpdate(SpriteNum); //player stuff num = PlayerCheckControls(SpriteNum); if (num == 1) //then a bullet was instantiated { SpriteNum++; PlayerSlideBack(); PlayerSlideBack(); PlayerSlideBack(); PlayerSlideBack(); PlayerUpdate(SpriteNum); HIDE_SPRITES; //clear unused sprites } num = PlayerUpdate(SpriteNum); if (num == 1) //then a bullet died { set_sprite_tile(SpriteNum, 5); //hide the players current sprite SpriteNum--; move_sprite(SpriteNum, P_PosX, P_PosY); //and show the new } //woah there sparky delay(20); } }
void ChangeBoardSize (){ int newWidth, newLength; while (TRUE) { printf("\n\nCurrent board of size %dx%d:\n\n", width, length); PrintPosition(gInitialPosition, "Gamesman", 0); printf("\n\nEnter the new width (%d - %d): ", WIDTH_MIN, WIDTH_MAX); newWidth = GetMyChar()-48; if(newWidth > WIDTH_MAX || newWidth < WIDTH_MIN) { printf("\nInvalid width!\n"); continue; } printf("\n\nEnter the new length (%d - %d): ", LENGTH_MIN, LENGTH_MAX); newLength = GetMyChar()-48; if(newLength > LENGTH_MAX || newLength < LENGTH_MIN) { printf("\nInvalid length!\n"); continue; } width = newWidth; length = newLength; boardsize = width*length; SetupGame(); break; } }
void MainWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case B_ABOUT_REQUESTED: { AboutRequested(); break; } case M_SHOW_HELP: { HelpWindow *helpwin = new HelpWindow(); helpwin->Show(); break; } case M_SHOW_CUSTOM: { CustomWindow *cswin = new CustomWindow(); cswin->Show(); break; } case M_NEW_GAME: { SetFace(FACE_NORMAL); SetupGame(); break; } case M_SHOW_SCORES: { ScoreWindow *scorewin = new ScoreWindow(); scorewin->Show(); break; } case M_PAUSE_GAME: { BMenuItem *item = fMenuBar->FindItem(M_PAUSE_GAME); if (fTimerView->GetState() == TIMER_START) { fTimerView->SetState(TIMER_STOP); if (item) item->SetMarked(true); fFieldView->SetPauseMode(true); } else { if (item->IsMarked()) { fTimerView->SetState(TIMER_START); if (item) item->SetMarked(false); fFieldView->SetPauseMode(false); } } break; } case M_SET_DIFFICULTY: { int32 level; if (msg->FindInt32("level",&level) != B_OK) break; BMenuItem *item = fMenuBar->FindItem(M_SET_DIFFICULTY); BMenu *menu = item ? item->Menu() : NULL; item = menu->FindMarked(); if (item) item->SetMarked(false); menu->ItemAt(level)->SetMarked(true); gDifficulty = level; SetupGame(); fFieldView->SetPauseMode(false); break; } case M_UPDATE_COUNT: { fCounterView->SetCount(fFieldView->MineCount() - fFieldView->FlagCount()); break; } case M_START_TIMER: { fTimerView->SetState(TIMER_RESET); fTimerView->SetState(TIMER_START); gGameState = GAME_STARTED; break; } case M_SONAR_PENALTY: { fTimerView->SetState(TIMER_STOP); if (fTimerView->GetTime() < 979) fTimerView->SetTime(fTimerView->GetTime() + 20); else fTimerView->SetTime(999); fTimerView->SetState(TIMER_START); if (fFieldView->CheckWin()) fFieldView->DoWin(); break; } case M_SIZE_CHANGED: { ResizeTo(fFieldView->Frame().right + 10,fFieldView->Frame().bottom + 10); break; } case M_SET_THEME: { BString name; if (msg->FindString("name",&name) == B_OK) SetTheme(name.String()); break; } case M_TOGGLE_SOUNDS: { gPlaySounds = gPlaySounds ? false : true; BMenuItem *item = fMenuBar->FindItem(M_TOGGLE_SOUNDS); if (item) item->SetMarked(!item->IsMarked()); break; } default: { BWindow::MessageReceived(msg); break; } } }
BouncyBallMain::BouncyBallMain(unsigned id, sbe::MainLoop const& main_loop) : Entity(id) , main_loop_(main_loop) , background_(IMG_LoadTexture(main_loop_.Renderer(), BACKGROUND_PATH.c_str())) , title_screen_(main_loop_.Renderer(), main_loop_.world()) , losing_screen_(main_loop_.Renderer(), main_loop_.world()) , pause_menu_(main_loop_.Renderer(), main_loop_.world()) , game_layer_(std::make_shared<sbe::EntityLayer>()) , game_started_(false) , losing_(false) { key_up.connect(sigc::mem_fun(this, &BouncyBallMain::OnKeyUp)); main_loop_.world()->SetGameData((void*)&bouncy_data_); bouncy_data_.left_scored.connect([this] { left_->Increment(); CheckIfWinning(); }); bouncy_data_.right_scored.connect([this] { right_->Increment(); CheckIfWinning(); }); title_screen_.start_clicked.connect([this] { StartGame(); }); title_screen_.two_player_clicked.connect([this] { right_paddle_->EnablePlayer(); right_paddle_->EnableEvents(); }); title_screen_.easy_clicked.connect([this] { right_paddle_->SetEasy(); }); title_screen_.medium_clicked.connect([this] { right_paddle_->SetMedium(); }); title_screen_.hard_clicked.connect([this] { right_paddle_->SetHard(); }); title_screen_.exit_clicked.connect([this] { // FIXME exit better then this... exit(0); }); losing_screen_.play_again.connect([this] { losing_screen_.Hide(); StartGame(); losing_ = false; }); losing_screen_.main_menu.connect([this] { losing_screen_.Hide(); ResetGame(); losing_ = false; }); pause_menu_.resume_clicked.connect([this] { pause_menu_.Hide(); game_layer_->UnPause(); }); pause_menu_.main_menu_clicked.connect([this] { pause_menu_.Hide(); game_layer_->UnPause(); ResetGame(); }); pause_menu_.restart_clicked.connect([this] { pause_menu_.Hide(); game_layer_->UnPause(); StartGame(); }); pause_menu_.exit_clicked.connect([this] { // FIXME exit better then this... exit(0); }); sbe::Rect const& bound = main_loop_.world()->Boundary(); sbe::Rect new_bound = {0, 10, bound.width(), bound.height() - 10}; main_loop_.world()->SetBoundary(new_bound); SetupGame(); title_screen_.SetMedium(); game_layer_->Hide(); losing_screen_.Hide(); pause_menu_.Hide(); main_loop_.world()->AddEntityLayer(game_layer_); }