void GroupGame::switchToMode() { GroupingMode::switchToMode(); m_ui->helpBar->setText(tr("<font color=\"green\">Type the groups of characters you hear ASAP.</font>")); m_ui->changeSequence->hide(); // Create the high scores button QAction *action = m_morse->menuBar()->addAction("HighScores"); connect(action, SIGNAL(triggered()), &m_scores, SLOT(showScores())); }
int main(int argc, const char * argv[]) { srand((unsigned int)time(NULL)); Player player1; Player *player1Pointer; player1Pointer = &player1; player1.index = 1; player1.numberOfLives = 3; player1.score = 0; player1.answer = 0; player1.loseLives = 'N'; Player player2; Player *player2Pointer; player2Pointer = &player2; player2.index = 2; player2.numberOfLives = 3; player2.score = 0; player2.answer = 0; player2.loseLives = 'N'; while (player1.numberOfLives > 0 && player2.numberOfLives > 0) { play(&player1); showScores(&player1, &player2); play(&player2); showScores(&player1, &player2); } if (player1.numberOfLives == 0 && player2.numberOfLives == 0) { printf("Tie!\n"); } else if (player2.numberOfLives == 0) { printf("Player 1 won!\n"); } else if (player1.numberOfLives == 0) { printf("Player 2 won!\n"); } return 0; }
void GroupGame::modeMenus() { // Create the high scores button QAction *action = menu()->addAction("HighScores"); connect(action, SIGNAL(triggered()), &m_scores, SLOT(showScores())); }
Window::Window(const QString& file) : m_pause_action(0), m_previous_state(0) { setAcceptDrops(true); // Create states m_states.insert("NewGame", new NewGameState(this)); m_states.insert("OpenGame", new OpenGameState(this)); m_states.insert("Optimizing", new OptimizingState(this)); m_states.insert("Play", new PlayState(this)); m_states.insert("AutoPause", new AutoPauseState(this)); m_states.insert("Pause", new PauseState(this)); m_states.insert("Finish", new FinishState(this)); m_state = m_states.value("NewGame"); // Create widgets m_contents = new QStackedWidget(this); setCentralWidget(m_contents); m_board = new Board(this); m_contents->addWidget(m_board); connect(m_board, &Board::started, this, &Window::gameStarted); connect(m_board, &Board::finished, this, &Window::gameFinished); connect(m_board, &Board::optimizingStarted, this, &Window::optimizingStarted); connect(m_board, &Board::optimizingFinished, this, &Window::optimizingFinished); // Create pause screen m_pause_screen = new QLabel(tr("<p><b><big>Paused</big></b><br>Click to resume playing.</p>"), this); m_pause_screen->setAlignment(Qt::AlignCenter); m_pause_screen->installEventFilter(this); m_contents->addWidget(m_pause_screen); // Create open game screen QLabel* open_game_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Loading game...</p>"), this); open_game_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(open_game_screen); // Create start screen QLabel* start_screen = new QLabel(tr("Click to start a new game."), this); start_screen->setAlignment(Qt::AlignCenter); start_screen->installEventFilter(this); m_contents->addWidget(start_screen); // Create new game screen QLabel* new_game_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Generating a new board...</p>"), this); new_game_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(new_game_screen); // Create optimizing screen QLabel* optimizing_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Optimizing word list...</p>"), this); optimizing_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(optimizing_screen); // Create game menu QMenu* menu = menuBar()->addMenu(tr("&Game")); menu->addAction(tr("New &Game..."), this, SLOT(newGame()), tr("Ctrl+Shift+N")); menu->addAction(tr("&New Roll"), this, SLOT(newRoll()), QKeySequence::New); menu->addAction(tr("&Choose..."), this, SLOT(chooseGame())); menu->addAction(tr("&Share..."), this, SLOT(shareGame())); menu->addSeparator(); QAction* end_action = menu->addAction(tr("&End"), this, SLOT(endGame())); end_action->setEnabled(false); connect(m_board, &Board::pauseAvailable, end_action, &QAction::setEnabled); m_pause_action = menu->addAction(tr("&Pause")); m_pause_action->setCheckable(true); m_pause_action->setShortcut(tr("Ctrl+P")); m_pause_action->setEnabled(false); connect(m_pause_action, &QAction::triggered, this, &Window::setPaused); connect(m_board, &Board::pauseAvailable, m_pause_action, &QAction::setEnabled); menu->addSeparator(); m_details_action = menu->addAction(tr("&Details"), this, SLOT(showDetails())); m_details_action->setEnabled(false); menu->addAction(tr("&High Scores"), this, SLOT(showScores())); menu->addSeparator(); QAction* action = menu->addAction(tr("&Quit"), this, SLOT(close()), tr("Ctrl+Q")); action->setMenuRole(QAction::QuitRole); monitorVisibility(menu); // Create settings menu menu = menuBar()->addMenu(tr("&Settings")); QMenu* submenu = menu->addMenu(tr("Show &Maximum Score")); QAction* score_actions[3]; score_actions[0] = submenu->addAction(tr("&Never")); score_actions[1] = submenu->addAction(tr("&End Of Game")); score_actions[2] = submenu->addAction(tr("&Always")); QActionGroup* group = new QActionGroup(this); for (int i = 0; i < 3; ++i) { score_actions[i]->setData(i); score_actions[i]->setCheckable(true); group->addAction(score_actions[i]); } connect(group, &QActionGroup::triggered, m_board, &Board::setShowMaximumScore); QAction* missed_action = menu->addAction(tr("Show Missed &Words")); missed_action->setCheckable(true); connect(missed_action, &QAction::toggled, m_board, &Board::setShowMissedWords); QAction* counts_action = menu->addAction(tr("Show Word &Counts")); counts_action->setCheckable(true); counts_action->setChecked(true); connect(counts_action, &QAction::toggled, m_board, &Board::setShowWordCounts); menu->addAction(tr("&Board Language..."), this, SLOT(showLanguage())); menu->addSeparator(); menu->addAction(tr("Application &Language..."), this, SLOT(showLocale())); monitorVisibility(menu); // Create help menu menu = menuBar()->addMenu(tr("&Help")); menu->addAction(tr("&Controls"), this, SLOT(showControls())); menu->addSeparator(); action = menu->addAction(tr("&About"), this, SLOT(about())); action->setMenuRole(QAction::AboutRole); action = menu->addAction(tr("About &Hspell"), this, SLOT(aboutHspell())); action->setMenuRole(QAction::ApplicationSpecificRole); action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); action->setMenuRole(QAction::AboutQtRole); action = menu->addAction(tr("About &SCOWL"), this, SLOT(aboutScowl())); action->setMenuRole(QAction::ApplicationSpecificRole); monitorVisibility(menu); // Load settings QSettings settings; QAction* score_action = score_actions[qBound(0, settings.value("ShowMaximumScore", 1).toInt(), 2)]; score_action->setChecked(true); m_board->setShowMaximumScore(score_action); missed_action->setChecked(settings.value("ShowMissed", true).toBool()); counts_action->setChecked(settings.value("ShowWordCounts", true).toBool()); restoreGeometry(settings.value("Geometry").toByteArray()); // Start game QString current = file; if (settings.contains("Current/Version")) { if (current.isEmpty() || QMessageBox::question(this, tr("Question"), tr("End the current game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { current = ":saved:"; } } m_state->finish(); m_contents->setCurrentIndex(3); if (current.isEmpty()) { newGame(); } else { startGame(current); } }