void PlayField::startGame() { //the game has a fixed difficulty level only if there is an AI Kg::difficulty()->setGameRunning(m_controller->hasAI()); startPlacingShips(); emit placeShips(); }
MainWindow::MainWindow(const QUrl& url) { m_main = new PlayField(this, statusBar()); setCentralWidget(m_main); Kg::difficulty()->addStandardLevelRange( KgDifficultyLevel::Easy, KgDifficultyLevel::Hard, //range KgDifficultyLevel::Hard //default ); KgDifficultyGUI::init(this); connect(Kg::difficulty(), SIGNAL (currentLevelChanged(const KgDifficultyLevel*)), m_main, SLOT (levelChanged())); setupActions(); connect(m_main, SIGNAL(welcomeScreen()), this, SLOT(welcomeScreen())); connect(m_main, SIGNAL(placeShips()), this, SLOT(startingGame())); m_main->newGame(); if(! url.isEmpty() ) m_main->createClient(url); }
bool MainServer::setField( const QString& cmd, Clients::iterator client ) { QRegExp rx( "field:([01]+):" ); if( rx.indexIn( cmd ) != -1 ) { if( client->status == ST_AUTHORIZED ) { qDebug() << "Field: " << rx.cap( 1 ); if( !placeShips( rx.cap( 1 ), client ) ) return false; qDebug() << "Len=100"; client->status = ST_READY; return true; } } return false; }
bool MyFrameListener::createBoard() { int myX=0; int myY=0; // iniciar longitud barcos. (1,2,3,4,5) for (int i=0; i<_NUMSHIPS; i++) { myShips[i] = i+1; _maxFires += i+1; } // Colocacion de los barcos placeShips(myShips, myBoard); // Creacion del tablero CPU for (int i=0; i<_XMAX; i++) { for (int j=0; j<_YMAX; j++) { Ogre::Entity* ent1; if (myBoard[i][j] == 1) { ent1 = _sceneManager->createEntity("CuboAgua.mesh"); ent1->setQueryFlags(2); } else { ent1 = _sceneManager->createEntity("CuboAgua.mesh"); ent1->setQueryFlags(1); } Ogre::SceneNode* node1 = _sceneManager->createSceneNode(); node1->attachObject(ent1); node1->translate(i*2.2,j*2.2,-50); _sceneManager->getRootSceneNode()->addChild(node1); } } placeShips(myShips, myBoardPlayer); // creacion del tablero player for (int i=0; i<_XMAX; i++) { for (int j=0; j<_YMAX; j++) { Ogre::Entity* ent1; if (myBoardPlayer[i][j] == 1) ent1 = _sceneManager->createEntity("CuboBarco.mesh"); else ent1 = _sceneManager->createEntity("CuboAgua.mesh"); ent1->setQueryFlags(4); Ogre::SceneNode* node1 = _sceneManager->createSceneNode(); node1->attachObject(ent1); node1->setPosition(_posXBoardPlayer+(i*2.2),_posYBoardPlayer,_posZBoardPlayer+(j*2.2)); // añadir nodo para ir eliminando por parte de la CPU _playerNodeBoard[i][j] = node1; _sceneManager->getRootSceneNode()->addChild(node1); } } return true; }