void MenuDialog::quitClicked()
{
    if(this->quitButton)
    {
        emit closeGame();
    }
}
示例#2
0
/**
 * create the action events create the gui.
 */
void KJezzball::initXMLUI()
{
    m_newAction = KStdGameAction::gameNew( this, SLOT(newGame()), actionCollection() );
    // AB: originally KBounce/KJezzball used Space for new game - but Ctrl+N is
    // default. We solve this by providing space as an alternative key
    KShortcut s = m_newAction->shortcut();
    s.append(KKeySequence(QKeySequence(Key_Space)));
    m_newAction->setShortcut(s);

    KStdGameAction::quit(this, SLOT(close()), actionCollection() );
    KStdGameAction::highscores(this, SLOT(showHighscore()), actionCollection() );
    m_pauseButton = KStdGameAction::pause(this, SLOT(pauseGame()), actionCollection());
    KStdGameAction::end(this, SLOT(closeGame()), actionCollection());
    KStdGameAction::configureHighscores(this, SLOT(configureHighscores()),actionCollection());

    new KAction( i18n("&Select Background Folder..."), 0, this, SLOT(selectBackground()),
                       actionCollection(), "background_select" );
    m_backgroundShowAction =
        new KToggleAction( i18n("Show &Backgrounds"), 0, this, SLOT(showBackground()),
                           actionCollection(), "background_show" );
    m_backgroundShowAction->setCheckedState(i18n("Hide &Backgrounds"));
    m_backgroundShowAction->setEnabled( !m_backgroundDir.isEmpty() );
    m_backgroundShowAction->setChecked( m_showBackground );

    m_soundAction = new KToggleAction( i18n("&Play Sounds"), 0, 0, 0, actionCollection(), "toggle_sound");
}
示例#3
0
void KJezzball::newGame()
{
    // Check for running game
    closeGame();
    if ( m_state==Idle )
    {
        // untoggles the pause button in case it was toggled
        m_pauseButton->setChecked(false);

        // update displays
        m_game.level = 1;
        m_game.score = 0;

        m_levelLCD->display( m_game.level );
        m_scoreLCD->display( m_game.score );

        statusBar()->clear();

        // start new game
        m_state = Running;

        createLevel( m_game.level );
        startLevel();
    }
}
示例#4
0
void Console::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_1)
    {
        createGame(GameSnake);
        return;
    }
    else if (event->key() == Qt::Key_2)
    {
        createGame(GameRaycasting);
        return;
    }
    else if (event->key() == Qt::Key_Escape)
    {
        closeGame();
        return;
    }
    else if (event->key() == Qt::Key_Space)
    {
        m_isRunnig = !m_isRunnig;
        return;
    }

    if (m_game && m_isRunnig)
        m_game->keyPressEvent(convertQtKeyToGameKey(event->key()));
}
示例#5
0
文件: widget.cpp 项目: jikal/mystudy
void Widget::on_btnCancel_clicked()
{
    if(isGame == 1)
    {
        emit closeGame();
    }
    this->close();
}
示例#6
0
文件: widget.cpp 项目: jikal/mystudy
//玩游戏
void Widget::on_btnGame_clicked()
{
    mainform *m = new mainform();
    isGame = 1;
    ui->btnGame->setEnabled(false);//设置游戏按钮不可用
    connect(this, SIGNAL(closeGame()), m, SLOT(close()));
    connect(m, SIGNAL(game_able()), this, SLOT(btnGame_able()));
    m->show();
}
示例#7
0
void KBounceGameWidget::onWallDied()
{
    if ( m_lives <= 1 )
    {
        closeGame();
    }
    else
    {
        m_lives--;
        emit livesChanged( m_lives );
    }
}
示例#8
0
void KBounceGameWidget::newGame()
{
    closeGame();
    setCursor( m_vertical ? Qt::SizeVerCursor : Qt::SizeHorCursor );
    m_level = 1;
    m_score = 0;

    emit levelChanged( m_level );
    emit scoreChanged( m_score );
    
    newLevel();
}
示例#9
0
void Console::createGame(int gameId)
{
    switch (gameId)
    {
    case GameSnake:
        closeGame();
        m_game = new Snake(20, 15);
        break;
    case GameRaycasting:
        closeGame();
        m_game = new Raycasting;
        break;
    default:
        return;
    }

    m_game->setDisplay(m_display);
    m_game->initialize();

    m_isRunnig = true;
    m_loopTimer = startTimer(100);
}
示例#10
0
// called by main for commmand line files
void Kolf::openURL(KURL url)
{
	QString target;
	if (KIO::NetAccess::download(url, target, this))
	{
		isTutorial = false;
		QString mimeType = KMimeType::findByPath(target)->name();
		if (mimeType == "application/x-kourse")
			filename = target;
		else if (mimeType == "application/x-kolf")
			loadedGame = target;
		else
		{
			closeGame();
			return;
		}

		QTimer::singleShot(10, this, SLOT(startNewGame()));
	}
	else
		closeGame();
}
示例#11
0
void GameWindow::startNewGame(){

    popUpWindow = new QWidget;
    QPushButton *newGameButton = new QPushButton("NEW GAME");
    QPushButton *quitButton = new QPushButton("QUIT");
    QObject::connect(quitButton, SIGNAL(pressed()), this, SLOT(closeGame()));
    QObject::connect(newGameButton, SIGNAL(pressed()), this, SLOT(restartGame()));
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(newGameButton);
    layout->addWidget(quitButton);
    popUpWindow->setFixedSize(100,100);


}void GameWindow::startGame(int level, int difficulty){
示例#12
0
文件: widget.cpp 项目: jikal/mystudy
//窗体关闭事件//主窗口关闭引发所有子窗口关闭
void Widget::closeEvent(QCloseEvent *)
{
    QMap<QString, ChatWidgit *>::Iterator it;//迭代器
    while(list.size() > 0)
    {
        it = list.begin();
        list[it.key()]->close();
    }
    if(isGame == 1)
    {
        emit closeGame();
    }
    sendMessage(ParticipantLeft);
}
示例#13
0
void KBounceGameWidget::tick()
{
    static int ticks = TICKS_PER_SECOND;
    ticks--;
    if ( ticks <= 0 )
    {
        if ( m_time == 1 )
            closeGame();
        else
        {
            m_time--;
            emit timeChanged( m_time );
        }
        ticks = TICKS_PER_SECOND;
    }
}
示例#14
0
MenuDialog::MenuDialog(QWidget *parent) : QDialog(parent)
{
    continueButton = new QPushButton("Continue");
    newButton = new QPushButton("New Game");
    loadButton = new QPushButton("Load Game");
    quitButton = new QPushButton("Quit");
    optionsButton = new QPushButton("Options");

    newButton->setStyleSheet("QPushButton {background-color:white}");
    continueButton->setStyleSheet("QPushButton {background-color:white}");
    loadButton->setStyleSheet("QPushButton {background-color:white}");
    quitButton->setStyleSheet("QPushButton {background-color:white}");
    optionsButton->setStyleSheet("QPushButton {background-color:white}");

    connect(this, SIGNAL(finished(int)), parent, SLOT(show()));
    connect(this, SIGNAL(closeGame()), parent, SLOT(close()));

    connect(newButton, SIGNAL(clicked(bool)), parent, SLOT(resetB()));
    connect(newButton, SIGNAL(clicked(bool)), this, SLOT(close()));

    connect(continueButton, SIGNAL(clicked(bool)), parent, SLOT(open()));
    connect(continueButton, SIGNAL(clicked(bool)), this, SLOT(close()));

    connect(loadButton, SIGNAL(clicked(bool)), parent, SLOT(open()));
    connect(loadButton, SIGNAL(clicked(bool)), this, SLOT(close()));

    connect(quitButton, SIGNAL(clicked(bool)), this, SLOT(quitClicked()));

    QVBoxLayout *layout = new QVBoxLayout;

    layout->addWidget(newButton);
    layout->addWidget(continueButton);
    layout->addWidget(loadButton);
    layout->addWidget(optionsButton);
    layout->addWidget(quitButton);
    layout->setContentsMargins(250, 330, 250, 330);
    setLayout(layout);
    //this->layout()->setSizeConstraint(QLayout::SetFixedSize);

    setWindowTitle("Checkers");

    QPalette backGround;

    backGround.setBrush(this->backgroundRole(),
                  QBrush(QImage(":/images/background.jpg")));
    this->setPalette(backGround);
}
示例#15
0
void GameWindow::userWon(){
    timer->stop();
    popUpWindow = new QWidget();
    QLabel *label = new QLabel("Congratulations!! YOU WON!! ");
    QVBoxLayout *layout = new QVBoxLayout;
    QVBoxLayout *buttonlayout = new QVBoxLayout;
    QPushButton *closebutton = new QPushButton("Exit");
    QPushButton *againbutton = new QPushButton("Play Again");
    QObject::connect(closebutton, SIGNAL(pressed()), this, SLOT(closeGame()));
    QObject::connect(againbutton, SIGNAL(pressed()), this, SLOT(restartGame()));
    layout->addWidget(label);
    buttonlayout->addWidget(closebutton);
    buttonlayout->addWidget(againbutton);
    layout->addLayout(buttonlayout);
    popUpWindow->setLayout(layout);
    popUpWindow->setFixedSize(300,300);
    popUpWindow->show();
}
示例#16
0
// stops game loop
void GameWindow::messageUser(){
    if(userLost&&countloss==0){
        countloss =1;
        popUpWindow = new QWidget();
        QLabel *label = new QLabel("You ran out of Lives!!");
        QVBoxLayout *layout = new QVBoxLayout;
        QVBoxLayout *buttonlayout = new QVBoxLayout;
        QPushButton *closebutton = new QPushButton("Exit");
        QPushButton *againbutton = new QPushButton("Play Again");
        QObject::connect(closebutton, SIGNAL(pressed()), this, SLOT(closeGame()));
        QObject::connect(againbutton, SIGNAL(pressed()), this, SLOT(restartGame()));
        layout->addWidget(label);
        buttonlayout->addWidget(closebutton);
        buttonlayout->addWidget(againbutton);
        layout->addLayout(buttonlayout);
        popUpWindow->setLayout(layout);
        popUpWindow->setFixedSize(200,200);
        popUpWindow->show();

    }
}
示例#17
0
void CGameApplication::mainLoop()
{
/*
    // Définition de la langue de l'application
    if (isArg("--lang"))
    {
        CString lang = getArg(getArgPosition("--lang") + 1);
        setLanguage(TLang::French); ...
    }
*/

    // Chargement d'une map au démarrage
    if (isArg("--map"))
    {
        CString map_name = getArg(getArgPosition("--map") + 1);
        loadMap(map_name);
    }

/*
    // Lancement en mode serveur
    if (isArg ("--server"))
    {
        //...
    }
*/

#ifdef T_ACTIVE_DEBUG_MODE
    m_activityDebug = new CActivity("debug");
    CWindowDebug * windowDebug = new CWindowDebug();
    m_activityDebug->addWindow(windowDebug);
    windowDebug->open();
    windowDebug->setFocus();
#endif // T_ACTIVE_DEBUG_MODE

    // Boucle de l'application
    while (eventLoop());

    closeGame();
}
示例#18
0
// used to handle message from a ClientConnection
// those message can be 
//     'SYSTEM_REGISTER <CONSUMER | PROVIDER> #Game [Game]' --> no answer
//     'SYSTEM_REQUEST_GAME GameKind'
//             'SYSTEM_REQUEST_GAME_REFUSED ErrorMessage'
//             'SYSTEM_REQUEST_GAME_ACCEPTED GameId #Consumer [Consumer]'
//     'SYSTEM_JOIN_GAME GameId'
//     'SYSTEM_LEAVE_GAME GameId'
//     '<gameId> MESSAGE'
void ConnectionManager::handleMessage( ClientConnectionPtr connection,
                                       const std::string& message )
{
   // log the message
   AsyncLogger::getInstance()->log( "RECEIVE FROM (" + connection->getLogin() + ") : " + message );

   // explode the message to be able to check the kind 
   std::vector< std::string > messageParts;
   if ( StringUtils::explode( message,
                              ' ',
                              messageParts,
                              2 ) == 2 )
   {
      if ( messageParts[ 0 ] == SYSTEM_REGISTER )
      {
         registerConnection( connection,
                              messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME )
      {
         requestGame( connection,
                        messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME_LIST )
      {
         requestGameList( connection,
                           messageParts[ 1 ] );
      }
      else if ( messageParts[ 0 ] == SYSTEM_JOIN_OR_REQUEST_GAME )
      {
         joinOrRequestGame( connection,
                              messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_JOIN_GAME )
      {
         joinGame( connection,
                     messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_LEAVE_GAME )
      {
         leaveGame( connection,
                     messageParts[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == SYSTEM_GAME_CREATION_REFUSED )
      {
         // get the relevant information
         std::vector< std::string > messageInformation;
         StringUtils::explode( messageParts[ 1 ],
                                 ' ',
                                 messageInformation,
                                 2 );

         // and close the game
         closeGame( connection,
                     messageInformation[ 0 ],
                     messageInformation[ 1 ] );
         dumpCurrentState();
      }
      else if ( messageParts[ 0 ] == GAME_MESSAGE )
      {
         // get the relevant information
         std::vector< std::string > messageInformation;
         StringUtils::explode( messageParts[ 1 ],
                                 ' ',
                                 messageInformation,
                                 2 );

         // and forward the message (gameId, message)
         handleGameMessage( connection,
                              messageInformation[ 0 ],
                              message );
      }
   }
}
示例#19
0
void Kolf::initGUI()
{
	newAction = KStdGameAction::gameNew(this, SLOT(newGame()), actionCollection());
	newAction->setText(newAction->text() + QString("..."));

	endAction = KStdGameAction::end(this, SLOT(closeGame()), actionCollection());
	printAction = KStdGameAction::print(this, SLOT(print()), actionCollection());

	(void) KStdGameAction::quit(this, SLOT(close()), actionCollection());
	saveAction = KStdAction::save(this, SLOT(save()), actionCollection(), "game_save");
	saveAction->setText(i18n("Save &Course"));
	saveAsAction = KStdAction::saveAs(this, SLOT(saveAs()), actionCollection(), "game_save_as");
	saveAsAction->setText(i18n("Save &Course As..."));

	saveGameAction = new KAction(i18n("&Save Game"), 0, this, SLOT(saveGame()), actionCollection(), "savegame");
	saveGameAsAction = new KAction(i18n("&Save Game As..."), 0, this, SLOT(saveGameAs()), actionCollection(), "savegameas");

	loadGameAction = KStdGameAction::load(this, SLOT(loadGame()), actionCollection());
	loadGameAction->setText(i18n("Load Saved Game..."));

	highScoreAction = KStdGameAction::highscores(this, SLOT(showHighScores()), actionCollection());

	editingAction = new KToggleAction(i18n("&Edit"), "pencil", CTRL+Key_E, this, SLOT(emptySlot()), actionCollection(), "editing");
	newHoleAction = new KAction(i18n("&New"), "filenew", CTRL+SHIFT+Key_N, this, SLOT(emptySlot()), actionCollection(), "newhole");
	clearHoleAction = new KAction(KStdGuiItem::clear().text(), "locationbar_erase", CTRL+Key_Delete, this, SLOT(emptySlot()), actionCollection(), "clearhole");
	resetHoleAction = new KAction(i18n("&Reset"), CTRL+Key_R, this, SLOT(emptySlot()), actionCollection(), "resethole");
	undoShotAction = KStdAction::undo(this, SLOT(emptySlot()), actionCollection(), "undoshot");
	undoShotAction->setText(i18n("&Undo Shot"));
	//replayShotAction = new KAction(i18n("&Replay Shot"), 0, this, SLOT(emptySlot()), actionCollection(), "replay");

	holeAction = new KListAction(i18n("Switch to Hole"), 0, this, SLOT(emptySlot()), actionCollection(), "switchhole");
	nextAction = new KAction(i18n("&Next Hole"), "forward", KStdAccel::shortcut(KStdAccel::Forward), this, SLOT(emptySlot()), actionCollection(), "nexthole");
	prevAction = new KAction(i18n("&Previous Hole"), "back", KStdAccel::shortcut(KStdAccel::Back), this, SLOT(emptySlot()), actionCollection(), "prevhole");
	firstAction = new KAction(i18n("&First Hole"), "gohome", KStdAccel::shortcut(KStdAccel::Home), this, SLOT(emptySlot()), actionCollection(), "firsthole");
	lastAction = new KAction(i18n("&Last Hole"), CTRL+SHIFT+Key_End, this, SLOT(emptySlot()), actionCollection(), "lasthole");
	randAction = new KAction(i18n("&Random Hole"), "goto", 0, this, SLOT(emptySlot()), actionCollection(), "randhole");

	useMouseAction = new KToggleAction(i18n("Enable &Mouse for Moving Putter"), 0, this, SLOT(emptySlot()), actionCollection(), "usemouse");
	useMouseAction->setCheckedState(i18n("Disable &Mouse for Moving Putter"));
	connect(useMouseAction, SIGNAL(toggled(bool)), this, SLOT(useMouseChanged(bool)));
	KConfig *config = kapp->config();
	config->setGroup("Settings");
	useMouseAction->setChecked(config->readBoolEntry("useMouse", true));

	useAdvancedPuttingAction = new KToggleAction(i18n("Enable &Advanced Putting"), 0, this, SLOT(emptySlot()), actionCollection(), "useadvancedputting");
	useAdvancedPuttingAction->setCheckedState(i18n("Disable &Advanced Putting"));
	connect(useAdvancedPuttingAction, SIGNAL(toggled(bool)), this, SLOT(useAdvancedPuttingChanged(bool)));
	useAdvancedPuttingAction->setChecked(config->readBoolEntry("useAdvancedPutting", false));

	showInfoAction = new KToggleAction(i18n("Show &Info"), "info", CTRL+Key_I, this, SLOT(emptySlot()), actionCollection(), "showinfo");
	showInfoAction->setCheckedState(i18n("Hide &Info"));
	connect(showInfoAction, SIGNAL(toggled(bool)), this, SLOT(showInfoChanged(bool)));
	showInfoAction->setChecked(config->readBoolEntry("showInfo", false));

	showGuideLineAction = new KToggleAction(i18n("Show Putter &Guideline"), 0, this, SLOT(emptySlot()), actionCollection(), "showguideline");
	showGuideLineAction->setCheckedState(i18n("Hide Putter &Guideline"));
	connect(showGuideLineAction, SIGNAL(toggled(bool)), this, SLOT(showGuideLineChanged(bool)));
	showGuideLineAction->setChecked(config->readBoolEntry("showGuideLine", true));

	KToggleAction *act=new KToggleAction(i18n("Enable All Dialog Boxes"), 0, this, SLOT(enableAllMessages()), actionCollection(), "enableAll");
	act->setCheckedState(i18n("Disable All Dialog Boxes"));

	soundAction = new KToggleAction(i18n("Play &Sounds"), 0, this, SLOT(emptySlot()), actionCollection(), "sound");
	connect(soundAction, SIGNAL(toggled(bool)), this, SLOT(soundChanged(bool)));
	soundAction->setChecked(config->readBoolEntry("sound", true));

	(void) new KAction(i18n("&Reload Plugins"), 0, this, SLOT(initPlugins()), actionCollection(), "reloadplugins");
	(void) new KAction(i18n("Show &Plugins"), 0, this, SLOT(showPlugins()), actionCollection(), "showplugins");

	aboutAction = new KAction(i18n("&About Course"), 0, this, SLOT(emptySlot()), actionCollection(), "aboutcourse");
	tutorialAction = new KAction(i18n("&Tutorial"), 0, this, SLOT(tutorial()), actionCollection(), "tutorial");

	statusBar();
	setupGUI();
}
示例#20
0
void StartUi::slotStartServer()
{
    /* todo GameFrame
    if(!settings->getShowIpStats())
        ip_stats->hide();
*/
    menuTabFrame->setSettings();

    if(settings->isServer())
    {
        qsrand(QDateTime::currentDateTime().toTime_t());
        adminPassword.setNum(qrand ());
        if(server)
        {
            server->kill();
            delete server;
        }
        server = new QProcess(this);
        connect(server, SIGNAL(started()), this, SLOT(slotServerLaunched()));
        connect(server, SIGNAL(error(QProcess::ProcessError)), this, SLOT(slotServerLaunchedError(QProcess::ProcessError)));
        //read debug ouputs
        connect(server,SIGNAL(readyReadStandardOutput()),this,SLOT(slotReadServerDebug()));
        server->setReadChannelMode(QProcess::MergedChannels);

		QString serverCmdLine("./Serverd");
		serverCmdLine += " --port ";
		serverCmdLine += QString::number(settings->getServerPort());
		serverCmdLine += " --admin-password " + adminPassword;
        if(settings->isDebugMode())
            serverCmdLine += " --debug-mode";
        serverCmdLine += " --started-from-gui";

        server->start(serverCmdLine);
    }
    else
    {
        adminPassword = menuTabFrame->getAdminPassword();
    }
    gamePlay = new GamePlay(settings, menuTabFrame->getGraphicPreview(), menuTabFrame->getPlayerName());
    NetClient *netclient = gamePlay->getNetClient();

    connect( gamePlay, SIGNAL(quitGame()), this, SLOT(closeGame()), Qt::QueuedConnection );
    connect( gamePlay, SIGNAL(sigLoadInterGame()), this, SLOT(slotLoadInterGame()) );

    /* Connect some signals to the ourselves */
    connect( netclient, SIGNAL(sigConnectionError()), this, SLOT(slotConnectionError()), Qt::QueuedConnection);
    connect( netclient, SIGNAL(sigGameStarted()), this, SLOT(slotGameStarted()));
    connect( netclient, SIGNAL(sigNetClientEnd()), this, SLOT(closeGame()));

    /* Connect some signals to the IP stats widget */
    connect( netclient, SIGNAL(sigStatPing(int)), &ipStats, SLOT(slotStatPing(int)));
    connect( netclient, SIGNAL(sigStatPacketLoss(double)), &ipStats, SLOT(slotStatPacketLoss(double)));

    /* Connect some signals to the frame menu */
    connect( netclient, SIGNAL(sigConnected()), menuTabFrame, SLOT(slotConnectedToServer()));
    connect( netclient, SIGNAL(sigIsServerAdmin()), menuTabFrame, SLOT(slotIsServerAdmin()));
    connect( netclient, SIGNAL(sigUpdatePlayerData(qint8,QString)), menuTabFrame, SLOT(slotUpdatePlayerData(qint8,QString)));
    connect( netclient, SIGNAL(sigMaxPlayersChanged(int)), menuTabFrame, SLOT(slotMaxPlayersValueChanged(int)));
    connect( netclient, SIGNAL(sigMaxWinsChanged(int)), menuTabFrame, SLOT(slotMaxWinsValueChanged(int)));
    connect( netclient, SIGNAL(sigMapRandom(bool)), menuTabFrame, SLOT(slotMapRandom(bool)));
    connect( netclient, SIGNAL(mapPreviewReceived(MapClient*)), menuTabFrame,SLOT(slotMapPreviewReceived(MapClient*)));
    connect( netclient, SIGNAL(sigPlayerLeft(qint8)), menuTabFrame, SLOT(slotPlayerLeft(qint8)));

    /* Connect some signals to the player list */
    connect( netclient, SIGNAL(sigUpdatePlayerData(qint8, QString)), &playerListWidget, SLOT(slotAddPlayer(qint8, QString)));
    connect( gamePlay, SIGNAL(sigNewPlayerGraphic(qint8,const QPixmap &)), &playerListWidget, SLOT(slotNewPlayerGraphic(qint8,const QPixmap &)));
    connect( netclient, SIGNAL(sigPlayerLeft(qint8)), &playerListWidget, SLOT(slotRemovePlayer(qint8)));
    connect( netclient, SIGNAL(sigScoreUpdate(qint8, qint16)), &playerListWidget, SLOT(slotUpdatePlayerScore(qint8, qint16)));
    // must be queued otherwise NetClient instance is deleted before finishing its processing
    connect( netclient, SIGNAL(sigServerStopped()), this, SLOT(slotServerStopped()), Qt::QueuedConnection);

    // if the server is remote, try to connect immediately (otherwise server's output must be checked)
    if(!settings->isServer())
        gamePlay->cliConnect(adminPassword);
}
示例#21
0
void StartUi::slotConnectionError()
{
    //qDebug("StartUi::slotConnectionError");
    closeGame();
}
示例#22
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    qsrand(QTime::currentTime().second());

    this->bufferPixmap = new QPixmap(288,512);
    // Set size.
    this->resize(540,960);

    /* Init 3 buttons. */
    this->startButton = new QPushButton(this);
    this->startButton->setGeometry(QRect((20.0/288)*this->width(),
                                         (341.0/512)*this->height(),
                                         (117.0/288)*this->width(),
                                         (71.0/512)*this->height()));
    this->startButton->setStyleSheet("QPushButton{border-image:url(:/image/image/button_play.png);}"
                                     "QPushButton:pressed{margin: 2px 2px 2px 2px;}");
    connect(this->startButton,SIGNAL(clicked()),this,SLOT(startGame()));

    this->closeButton = new QPushButton(this);
    this->closeButton->setGeometry(QRect((151.0/288)*this->width(),
                                         (341.0/512)*this->height(),
                                         (117.0/288)*this->width(),
                                         (71.0/512)*this->height()));
    this->closeButton->setStyleSheet("QPushButton{border-image:url(:/image/image/button_close.png);}"
                                     "QPushButton:pressed{margin: 2px 2px 2px 2px;}");
    connect(this->closeButton,SIGNAL(clicked()),this,SLOT(closeGame()));

    this->infoButton = new QPushButton(this);
    this->infoButton->setGeometry(QRect((106.5/288)*this->width(),
                                        (300.0/512)*this->height(),
                                        (75.0/288)*this->width(),
                                        (48.0/512)*this->height()));
    this->infoButton->setStyleSheet("QPushButton{border-image:url(:/image/image/button_rate.png);}"
                                    "QPushButton:pressed{margin: 2px 2px 2px 2px;}");
    connect(this->infoButton,SIGNAL(clicked()),this,SLOT(displayInfo()));

    /* Init all the game elements. */
    this->background = new EleBackground();
    this->ground = new EleGround();
    this->bird = new EleBird();
    this->scoreboard = new EleScoreBoard();
    this->readyboard = new EleReadyBoard();
    this->overboard = new EleOverBoard();
    this->titleboard = new EleTitleBoard();
    this->pipe[0] = new ElePipe(0);
    this->pipe[1] = new ElePipe(1);
    this->pipe[2] = new ElePipe(2);

    this->impactBirdRect.setRect(0,0,0.4*this->bird->getBindRect().width(),
                                 0.4*this->bird->getBindRect().height());

    /* Sound */
    this->soundDie = new QSound(":/sounds/sounds/sfx_die.wav");
    this->soundHit = new QSound(":/sounds/sounds/sfx_hit.wav");
    this->soundPoint = new QSound(":/sounds/sounds/sfx_point.wav");
    this->soundSwooshing = new QSound(":/sounds/sounds/sfx_swooshing.wav");
    this->soundWing = new QSound(":/sounds/sounds/sfx_wing.wav");

    /* The refresh rate : 50Hz */
    connect(&timer,SIGNAL(timeout()),this,SLOT(update()));
    timer.start(20);

    /* Connect signals and slots */
    connect(this->pipe[0],SIGNAL(pipePass()),this,SLOT(getScore()));
    connect(this->pipe[1],SIGNAL(pipePass()),this,SLOT(getScore()));
    connect(this->pipe[2],SIGNAL(pipePass()),this,SLOT(getScore()));

    connect(this->overboard,SIGNAL(buttonVisible(bool,bool,bool)),this,SLOT(setButtonVisible(bool,bool,bool)));

    // Game Start.
    this->gameTitle();
}
示例#23
0
void Kolf::gameOver()
{
	int curPar = 0;
	int lowScore = INT_MAX; // let's hope it doesn't stay this way!
	int curScore = 1;

	// names of people who had the lowest score
	QStringList names;

	HighScoreList highScores;
	int scoreBoardIndex = 1;

	while (curScore != 0)
	{
		QString curName;

		// name taken as a reference and filled out
		curScore = scoreboard->total(scoreBoardIndex, curName);

		scoreBoardIndex++;

		if (curName == i18n("Par"))
		{
			curPar = curScore;
			continue;
		}

		if (curScore == 0)
			continue;

		// attempt to add everybody to the highscore list
		// (ignored if we aren't competing down below)
		highScores.append(HighScore(curName, curScore));

		if (curScore < lowScore)
		{
			names.clear();
			lowScore = curScore;
			names.append(curName);
		}
		else if (curScore == lowScore)
			names.append(curName);
	}

	// only announce a winner if more than two entries
	// (player and par) are on the scoreboard + one to go past end
	// + 1 for koodoo
	if (scoreBoardIndex > 4)
	{
		if (names.count() > 1)
		{
			QString winners = names.join(i18n(" and "));
			KMessageBox::information(this, i18n("%1 tied").arg(winners));
		}
		else
			KMessageBox::information(this, i18n("%1 won!").arg(names.first()));
	}

	if (competition)
	{
		// deal with highscores
		// KScoreDialog makes it very easy :-))

		KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Custom1 | KScoreDialog::Score, this);
		scoreDialog->addField(KScoreDialog::Custom1, i18n("Par"), "Par");

		CourseInfo courseInfo;
		game->courseInfo(courseInfo, game->curFilename());

		scoreDialog->setConfigGroup(courseInfo.untranslatedName + QString(" Highscores"));

		for (HighScoreList::Iterator it = highScores.begin(); it != highScores.end(); ++it)
		{
			KScoreDialog::FieldInfo info;
			info[KScoreDialog::Name] = (*it).name;
			info[KScoreDialog::Custom1] = QString::number(curPar);

			scoreDialog->addScore((*it).score, info, false, true);
		}

		scoreDialog->setComment(i18n("High Scores for %1").arg(courseInfo.name));
		scoreDialog->show();
	}

	QTimer::singleShot(700, this, SLOT(closeGame()));
}