/** * Menu de sélection de l'unité * @param choice Choix de l'action pour l'unité */ void unitMenu(int choice){ char yn[2]; printf("\n"); switch(choice){ case 1: clearScreen(); // Met à jour l'affichage pour le tour gridDisp(); if(!hasAttacked && !hasMoved){ movable(white); // Fait la liste des unités pouvant se déplacer clearScreen(); // Met à jours les couleurs des unités déplaçables gridDisp(); printf("\nSe déplacer ? y/n\n"); readS(yn); printf("\n"); if(strcmp(yn,"y") == 0 || strcmp(yn,"Y") == 0) { playMove(); }else if(strcmp(yn,"n") != 0 && strcmp(yn,"N") != 0){ printf("Saisie invalide\n"); } movable(black); }else if(hasAttacked){ color(red, "Vous ne pouvez pas déplacer votre unité après avoir attaqué !\n"); }else{ color(red, "Vous ne pouvez pas déplacer une unité à nouveau !\n"); } break; case 2: clearScreen(); // Met à jour l'affichage pour le tour gridDisp(); if(!hasAttacked){ attackable(white); // Attaquants en blanc clearScreen(); // Met à jours les couleurs des unités pouvant attaquer gridDisp(); printf("\nAttaquer ? y/n\n"); readS(yn); printf("\n"); if(strcmp(yn,"y") == 0 || strcmp(yn,"Y") == 0) { playAttack(); }else if(strcmp(yn,"n") != 0 && strcmp(yn,"N") != 0){ printf("Saisie invalide\n"); } attackable(black); // Attaquants en noir }else{ color(red, "Vous ne pouvez pas réattaquer !\n"); } break; case 3: movable(white); clearScreen(); gridDisp(); printList(noPlayer); printf("\nChanger de direction ? y/n\n"); readS(yn); printf("\n"); if(strcmp(yn,"y") == 0 || strcmp(yn,"Y") == 0) { changeDirection(); }else if(strcmp(yn,"n") != 0 && strcmp(yn,"N") != 0){ printf("Saisie invalide\n"); } movable(black); clearScreen(); gridDisp(); break; } }
void Game2D::timer(){ if (pause()) return; if (!evec_.size() && state_==1){ //if (level () >=2) state_=2; //else nextLevel (); } if (state_==1){ bool destroy=0; ship_.onFire(); ship_.timer(direction_, width (), height ()); for (int i=0; i<evec_.size(); i++){ int x1=evec_[i].x (); int y1=evec_[i].y (); int x2=evec_[i].x () + evec_[i].width(); int y2=evec_[i].y () + evec_[i].height(); //ship hit in vertical line if (direction_==1 || direction_==3){ if (isInInterval (ship_.y (), y1, y2) || isInInterval (ship_.y () + ship_.height()/2, y1, y2) || isInInterval (ship_.y () + ship_.height(), y1, y2)){ if (ship_.x() > x1) destroy=ship_.hitMinX(x2); //right else{ if (ship_.x() + ship_.width () > x1) destroy=ship_.hitMaxX(x1-ship_.width ()); //left } } } //ship hit in horizontal line if (direction_==0 || direction_==2){ if (isInInterval (ship_.x (), x1, x2) || isInInterval (ship_.x () + ship_.width()/2, x1, x2) || isInInterval (ship_.x () + ship_.width(), x1, x2)){ if (ship_.y() > y1) destroy=ship_.hitMinY(y2); //down else{ if (ship_.y() + ship_.height () > y1) destroy=ship_.hitMaxY(y1-ship_.height ()); //up } } } if (ship_.fire()){ bool damaged=0; QRect rc; ship_.getFireRect (rc, direction()); //in fire axis y if (direction_==1 || direction_==3){ if (isInInterval (rc.y(), y1, y2) || isInInterval (rc.y()+rc.height(), y1, y2)){ //cross fire line & left enemy || //cross fire line & right enemy if ((x1 > rc.x() && x1 < rc.x()+rc.width()) || (x2 < rc.x() && x2 > rc.x()+rc.width())){ damaged=1; } } } if (direction_==0 || direction_==2){ if (isInInterval (rc.x(), x1, x2) || isInInterval (rc.x()+rc.width(), x1, x2)){ //cross fire line & up enemy || //cross fire line & down enemy if ((y1 > rc.y() && y1 < rc.y()+rc.height()) || (y2 < rc.y() && y2 > rc.y()+rc.height())){ damaged=1; } } } if (damaged){ ++score_; evec_[i].addHealth (-(ship_.damage ())); if (evec_[i].health () == 0) evec_.erase (evec_.begin () + i); } } if (destroy){ state_=2; /*ship_.addHealth (-1); switch(direction_){ case 0: direction_=2; break; case 1: direction_=3; break; case 2: direction_=0; break; case 3: direction_=1; break; } if (ship_.health () == 0) state_=2; */ /*QMessageBox box; box.warning(0,"Game over", "Ship destroyed!", 0, 1); box.show(); */ } } incTime (); if (movable()) moveEnemy (); } }
movable function(movable m) { return movable(boost::move(m)); }