void Pong::slotDataAvailable() { QByteArray array = mPort->readAll(); switch(array[0]) { case InitGame: { mSeed = array.right(array.size() - 1).toUInt(); qsrand(mSeed); mThisPIsLeftP = false; slotNewGame(false); break; } case StartGame: { slotStartGame(false); break; } case NewGame: { slotNewGame(false); break; } case StopGame: { slotStopGame(false); break; } case MoveSecondPlayerUp: { if (mThisPIsLeftP) { mRightP->r->moveBy(0, -mPaddleInc); } else { mLeftP->r->moveBy(0, -mPaddleInc); } checkIfPlayersGoOutOfMap(); break; } case MoveSecondPlayerDown: { if (mThisPIsLeftP) { mRightP->r->moveBy(0, mPaddleInc); } else { mLeftP->r->moveBy(0, mPaddleInc); } checkIfPlayersGoOutOfMap(); break; } } }
MainWindow::MainWindow() { setCaption(tr("GA Bots " VERSION)); initActions(); initMenuBar(); initToolBar(); initStatusBar(); initGABotDoc(); initView(); ViewToolBar->setOn(true); ViewStatusBar->setOn(true); //ViewGame->setOn(true); connect(GABotDoc, SIGNAL(gameReady(bool)), this, SLOT(slotGameReady(bool))); connect(GABotDoc, SIGNAL(teamAScores()), View, SLOT(slotScoreA())); connect(GABotDoc, SIGNAL(teamBScores()), View, SLOT(slotScoreB())); connect(GABotDoc, SIGNAL(clearScores()), View, SLOT(slotClearScores())); connect(GABotDoc, SIGNAL(moveTeamA(Coordinate, Coordinate)), View, SLOT(slotMoveTeamA(Coordinate, Coordinate))); connect(GABotDoc, SIGNAL(moveTeamB(Coordinate, Coordinate)), View, SLOT(slotMoveTeamB(Coordinate, Coordinate))); connect(GABotDoc, SIGNAL(turnTeamA(Coordinate, Direction)), View, SLOT(slotTurnTeamA(Coordinate, Direction))); connect(GABotDoc, SIGNAL(turnTeamB(Coordinate, Direction)), View, SLOT(slotTurnTeamB(Coordinate, Direction))); connect(GABotDoc, SIGNAL(moveBall(Coordinate,Coordinate)), View, SLOT(slotMoveBall(Coordinate,Coordinate))); connect(GoGame, SIGNAL(activated()), this, SLOT(slotGoGame())); connect(GoGame, SIGNAL(activated()), GABotDoc, SLOT(slotStartTimer())); connect(StopGame, SIGNAL(activated()), GABotDoc, SLOT(slotStopTimer())); connect(StopGame, SIGNAL(activated()), this, SLOT(slotStopGame())); connect(View, SIGNAL(valueChanged(int)), this, SLOT(slotTickInterval(int))); connect(GABotDoc, SIGNAL(clearField()), View, SLOT(slotClearField())); connect(ResetScreen, SIGNAL(activated()), View, SLOT(slotClearField())); //not sure if we should clear the field whenever regenerating the team // connect(TeamAGenerate,SIGNAL(activated()), View, SLOT(slotClearField())); // connect(TeamBGenerate,SIGNAL(activated()), View, SLOT(slotClearField())); connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearField())); connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearScores())); connect(GABotDoc, SIGNAL(gameOver()), this, SLOT(slotGameOver())); }