MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); left_panel=new FilePanel(ui->centralWidget); right_panel=new FilePanel(ui->centralWidget); currentPanel=left_panel; menu=new QMenu; ui->gridLayout->addWidget(left_panel->layoutWidget,1,0,1,1); ui->gridLayout->addWidget(right_panel->layoutWidget,1,1,1,1); connect(left_panel,SIGNAL(tryOpen(QModelIndex)),this,SLOT(open(QModelIndex))); connect(left_panel,SIGNAL(tryJump(QString)),this,SLOT(jumpTo(QString))); connect(left_panel,SIGNAL(panelActivated(FilePanel*)),this,SLOT(setCurrentPanel(FilePanel*))); connect(left_panel,SIGNAL(tryDelete()),this,SLOT(start_del())); connect(right_panel,SIGNAL(tryOpen(QModelIndex)),this,SLOT(open(QModelIndex))); connect(right_panel,SIGNAL(tryJump(QString)),this,SLOT(jumpTo(QString))); connect(right_panel,SIGNAL(panelActivated(FilePanel*)),this,SLOT(setCurrentPanel(FilePanel*))); connect(right_panel,SIGNAL(tryDelete()),this,SLOT(start_del())); initDrives(); connect(right_panel,SIGNAL(tryMount(QString)),this,SLOT(mountDrive(QString))); connect(left_panel,SIGNAL(tryMount(QString)),this,SLOT(mountDrive(QString))); left_panel->setModel(new fileModel); right_panel->setModel(new fileModel); setup_contextMenu(); left_panel->setPopupMenu(menu); right_panel->setPopupMenu(menu); setup_toolbar(); setup_favoritiesPath(); left_panel->loadSettings("Left"); right_panel->loadSettings("Right"); connect(left_panel,SIGNAL(tryDrop(QList<QUrl>,QString,Qt::DropAction)),this,SLOT(drop(QList<QUrl>,QString,Qt::DropAction))); connect(right_panel,SIGNAL(tryDrop(QList<QUrl>,QString,Qt::DropAction)),this,SLOT(drop(QList<QUrl>,QString,Qt::DropAction))); connect(left_panel,SIGNAL(moveChecked(bool)),right_panel,SLOT(checkMove(bool))); connect(right_panel,SIGNAL(moveChecked(bool)),left_panel,SLOT(checkMove(bool))); QFileSystemWatcher *watcher=new QFileSystemWatcher; watcher->addPath("/dev/disk/by-uuid"); connect(watcher,SIGNAL(directoryChanged(QString)),this,SLOT(drivesChanged(QString))); }
/** * Returns a list of all valid moves for \p pWho * * \param pMoves a vector where the list of moves will be appended * \param pWho the \ref ECell code (CELL_OWN or CELL_OTHER) of the * player making the move */ void GameState::findPossibleMoves(std::vector<GameState> &pStates) const { pStates.clear(); if (mLastMove.isEOG()) return; if (mMovesUntilDraw <= 0) { pStates.push_back(GameState(*this, Move(Move::MOVE_DRAW))); return; } // Normal moves are forbidden if any jump is found bool lFound=false; int lPieces[cPlayerPieces]; uint8_t lMoveBuffer[cPlayerPieces]; std::vector<Move> lMoves; int lNumPieces=0; for (int i = 1; i <= cSquares; ++i) { // Is this a piece which belongs to the player making the move? if (at(i) & mNextPlayer) { bool lIsKing = at(i)&CELL_KING; if (tryJump(lMoves, cellToRow(i), cellToCol(i), lIsKing, lMoveBuffer)) lFound=true; lPieces[lNumPieces++]=i; } } // Try normal moves if no jump was found if (!lFound) { for (int k = 0; k < lNumPieces; ++k) { int lCell = lPieces[k]; bool lIsKing = at(lCell) & CELL_KING; tryMove(lMoves, lCell, lIsKing); } } // Convert moves to GameStates for (unsigned i = 0; i < lMoves.size(); ++i) pStates.push_back(GameState(*this, lMoves[i])); // Admit loss if no moves can be found if (pStates.size() == 0) pStates.push_back(GameState(*this, Move(mNextPlayer == CELL_WHITE ? Move::MOVE_RW : Move::Move::MOVE_WW))); }
/** * Tries to make a jump from a certain position of the board * * \param pMoves a vector where the valid moves will be inserted * \param pOther the \ref ECell code corresponding to the player who is not making the move * \param pR the row of the cell we are moving from * \param pC the col * \param pKing true if the moving piece is a king * \param pBuffer a buffer where the list of jump positions is * inserted (for multiple jumps) * \param pDepth the number of multiple jumps before this attempt */ bool GameState::tryJump(std::vector<Move> &pMoves, int pR, int pC, bool pKing, uint8_t *pBuffer, int pDepth) const { // Remove ourself temporarily uint8_t lOldSelf = at(pR, pC); mutableAt(pR, pC) = CELL_EMPTY; pBuffer[pDepth]=rowColToCell(pR,pC); bool lFound=false; uint8_t lOther = mNextPlayer ^ (CELL_WHITE|CELL_RED); // Try capturing downwards if(mNextPlayer==CELL_RED||pKing) { // Try capturing left if((at(pR+1,pC-1)&lOther) && at(pR+2,pC-2)==CELL_EMPTY) { lFound=true; uint8_t lOldValue=at(pR+1,pC-1); mutableAt(pR+1,pC-1)=CELL_EMPTY; tryJump(pMoves,pR+2,pC-2,pKing,pBuffer,pDepth+1); mutableAt(pR+1,pC-1)=lOldValue; } // Try capturing right if((at(pR+1,pC+1)&lOther) && at(pR+2,pC+2)==CELL_EMPTY) { lFound=true; uint8_t lOldValue=at(pR+1,pC+1); mutableAt(pR+1,pC+1)=CELL_EMPTY; tryJump(pMoves,pR+2,pC+2,pKing,pBuffer,pDepth+1); mutableAt(pR+1,pC+1)=lOldValue; } } // Try capturing upwards if(mNextPlayer==CELL_WHITE||pKing) { // Try capturing left if((at(pR-1,pC-1)&lOther) && at(pR-2,pC-2)==CELL_EMPTY) { lFound=true; uint8_t lOldValue=at(pR-1,pC-1); mutableAt(pR-1,pC-1)=CELL_EMPTY; tryJump(pMoves,pR-2,pC-2,pKing,pBuffer,pDepth+1); mutableAt(pR-1,pC-1)=lOldValue; } // Try capturing right if((at(pR-1,pC+1)&lOther) && at(pR-2,pC+2)==CELL_EMPTY) { lFound=true; uint8_t lOldValue=at(pR-1,pC+1); mutableAt(pR-1,pC+1)=CELL_EMPTY; tryJump(pMoves,pR-2,pC+2,pKing,pBuffer,pDepth+1); mutableAt(pR-1,pC+1)=lOldValue; } } // Restore ourself mutableAt(pR, pC) = lOldSelf; if(!lFound&&pDepth>0) pMoves.push_back(Move(pBuffer,pDepth+1)); return lFound; }
void Lunger::step() { Player* player = level.getPlayer(); if(!haveDirection) { movingRight = (player->x + player->w/2) > (x + w/2); haveDirection = true; } if(landedDown) { float xDist = player->x + player->w/2 - (x + w/2); float yDist = player->y + player->h/2 - (y + h/2); bool facingPlayer = movingRight == ((player->x + player->w/2) > (x + w/2)); if(player->landedDown && facingPlayer && fabs(yDist) < Tile::TILE_SIZE && fabs(xDist) < 3 * Tile::TILE_SIZE) { tryLunge(); } } if(!lunging) { if(movingRight) { dx += ACCEL_RATE; if(dx > MOVE_SPEED) { dx = MOVE_SPEED; } } else { dx -= ACCEL_RATE; if(dx < -MOVE_SPEED) { dx = -MOVE_SPEED; } } } else { dx *= 0.95; if(fabs(dx) < 0.1) { lunging = false; } } dy += GRAVITY; x += dx; y += dy; collideLevel(); if(landedLeft || landedRight) { tryJump(); haveDirection = false; } currSprite->setFlipped(!movingRight); currSprite->step(); }
void MainWindow::timerEvent ( QTimerEvent * event ){ // ----------- partie personnage if (gravity<0){ personnage->setCurrentH(personnage->getCurrentH()+1); if(personnage->getCurrentH()>= personnage->getMaxH() || collisionTest(0,-1)){ gravity = baseGravity; personnage->setCurrentH(0); } else{ personnage->setCurrentS(6); personnage->immobile(); } } else if(collisionTest(0,1)){ if(gravity == 1) personnage->setCurrentS(4); //LANDING gravity = 0; } else { gravity = baseGravity; personnage->setCurrentS(3); // FALLING personnage->immobile(); } int x = 0; if(gravity == 0 && controleur->getStateKeys(0)) tryJump(); if(controleur->getStateKeys(2)){ if (personnage->tryDropBombe()){ // ajouter un truc du style personnage->hasBonusBombe() ajouterBombe(personnage->getX()+personnage->getLargeur()/2,personnage->getY()+ personnage->getHauteur()); controleur->setPressed(Qt::Key_Down,false); } } if(controleur->getStateKeys(1)){ x +=- 1; personnage->courireG(); } else if(controleur->getStateKeys(3)){ x += 1; personnage->courireD(); } if(x == 0 && gravity == 0 /*&& personnage->getCurrentS() != 3*/) personnage->immobile(); // TODO ? asscocier les bombes au joueur, soit avec le trigger du Joueur, soir en ayant bombes[NumJ][bombes] if(/*personnage->hasBonusTrigger == trigger &&*/controleur->getStateKeys(4)){ triggerAll(); controleur->setPressed(Qt::Key_Space,false); } tryMove(0,gravity); tryMove(x,0); // ----------- partie bombes int tmpSizeB = bombes.size(); for(int i = 0; i<tmpSizeB; i++){ if(bombes[i]->isExploding()){ explosion(bombes[i],0,0); explosion(bombes[i],0,1); explosion(bombes[i],0,-1); explosion(bombes[i],1,0); explosion(bombes[i],-1,0); } if(bombes[i]->hasExploded()){ int tmpSizeE = bombes[i]->getExplosions().size(); for(int j = 0; j< tmpSizeE; j++) scene->removeItem(bombes[i]->getExplosions().at(j)); scene->removeItem((bombes[i])->getPicture()); bombes.remove(i); tmpSizeB--; personnage->decrNbBombe(); } } }