supprimer fonctionne

This commit is contained in:
Cameron Bray 2020-05-26 23:54:30 +02:00
parent eea602662f
commit bcf9514dd1
6 changed files with 48 additions and 12 deletions

View file

@ -14,7 +14,7 @@ protected:
int nbreChoices; int nbreChoices;
int choice; int choice;
std::list<std::pair<int,std::string>> list; std::list<std::pair<int,std::string>> list;
std::list<int> listId; std::list<std::pair<int,int>> listId;
public: public:
Menu(); Menu();
std::string getMessage(); std::string getMessage();

View file

@ -34,6 +34,7 @@ public:
const std::string &getSexe() const; const std::string &getSexe() const;
std::string getInfo(); std::string getInfo();
static void delete1();
}; };
#endif //BE_TORTUE_H #endif //BE_TORTUE_H

View file

@ -79,20 +79,23 @@ void Menu::previousChoice() {
void Menu::menuBack() { void Menu::menuBack() {
if(!listId.empty()){ if(!listId.empty()){
id = listId.back(); choice = 0;
id = listId.back().first;
nbreChoices = listId.back().second;
listId.pop_back(); listId.pop_back();
} }
} }
void Menu::menuNext() { void Menu::menuNext() {
if(id ==0){ if(id ==0){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
id = 1; id = 1;
choice = 0; choice = 0;
nbreChoices = 3; nbreChoices = 3;
} }
else if (id == 1){ else if (id == 1){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
switch (choice){ switch (choice){
case 0 : case 0 :
id = 2; id = 2;
@ -117,7 +120,7 @@ void Menu::menuNext() {
} }
else if(id == 3){ else if(id == 3){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
switch (choice){ switch (choice){
case 0 : case 0 :
id = 5; id = 5;
@ -137,7 +140,7 @@ void Menu::menuNext() {
} }
} }
else if(id == 4){ else if(id == 4){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
switch (choice){ switch (choice){
case 0 : case 0 :
id = 7; id = 7;
@ -166,16 +169,16 @@ void Menu::menuNext() {
} }
} }
else if(id == 5){ else if(id == 5){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
id = 11; id = 11;
choice = 2; choice = 2;
} }
else if (id == 11){ else if (id == 11){
listId.push_back(id); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
id = 12; id = 12;
choice = 2; choice = 2;
} }
else if (id == 12){ else if (id == 12 || id == 6){
listId.clear(); listId.clear();
id = 0; id = 0;
choice = 0; choice = 0;

View file

@ -76,7 +76,7 @@ int Tortue::getNbTortue() {
std::string Tortue::getInfo() { std::string Tortue::getInfo() {
std::string message; std::string message;
message = "\nMy name is "+this->nom; message = "\nMy name is "+this->nom;
message += "\nI am 16 years old"; message += "\n" + this->getAge();
message += "\n"+this->sexe; message += "\n"+this->sexe;
return message; return message;
} }
@ -93,6 +93,10 @@ void Tortue::setSexe(const string &sexe) {
Tortue::sexe = sexe; Tortue::sexe = sexe;
} }
void Tortue::delete1() {
--nbTortue;
}

View file

View file

@ -129,7 +129,7 @@ void Board::loop() {
if (menu->getId() == 5){ if (menu->getId() == 5){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(5); sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150); bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { if (inputBuf[0] != '\0') {
@ -146,7 +146,7 @@ void Board::loop() {
} }
} else if (menu->getId() == 11){ } else if (menu->getId() == 11){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(5); sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150); bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { if (inputBuf[0] != '\0') {
@ -161,6 +161,7 @@ void Board::loop() {
} }
} else if (menu->getId() == 12){ } else if (menu->getId() == 12){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150); bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { if (inputBuf[0] != '\0') {
@ -172,6 +173,33 @@ void Board::loop() {
menu->menuNext(); menu->menuNext();
} }
} }
} else if (menu->getId() == 6){
Keyboard::saisie = true ;
sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') {
input = "";
for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j];
}
int length = tortues->size();
iteratorT = tortues->begin();
for (int j = 0; j < length; ++j) {
if (iteratorT->getNom() == input) {
tortues->erase(iteratorT);
Tortue::delete1();
menu->menuNext();
}
++iteratorT;
}
if (iteratorT == tortues->end()) {
cout << "not in list" << endl;
menu->menuBack();
}
}
}
} }
cpt++; cpt++;