From bcf9514dd13e5643896731c704539e2abb117392 Mon Sep 17 00:00:00 2001 From: bray Date: Tue, 26 May 2020 23:54:30 +0200 Subject: [PATCH] supprimer fonctionne --- app/include/Menu.h | 2 +- app/include/Tortue.h | 1 + app/src/Menu.cpp | 19 +++++++++++-------- app/src/Tortue.cpp | 6 +++++- back.txt | 0 sketch_ino.cpp | 32 ++++++++++++++++++++++++++++++-- 6 files changed, 48 insertions(+), 12 deletions(-) delete mode 100644 back.txt diff --git a/app/include/Menu.h b/app/include/Menu.h index 9db294e..ac62c89 100644 --- a/app/include/Menu.h +++ b/app/include/Menu.h @@ -14,7 +14,7 @@ protected: int nbreChoices; int choice; std::list> list; - std::list listId; + std::list> listId; public: Menu(); std::string getMessage(); diff --git a/app/include/Tortue.h b/app/include/Tortue.h index 118caa4..9e0a226 100644 --- a/app/include/Tortue.h +++ b/app/include/Tortue.h @@ -34,6 +34,7 @@ public: const std::string &getSexe() const; std::string getInfo(); + static void delete1(); }; #endif //BE_TORTUE_H diff --git a/app/src/Menu.cpp b/app/src/Menu.cpp index 5730bdc..1d7585c 100644 --- a/app/src/Menu.cpp +++ b/app/src/Menu.cpp @@ -79,20 +79,23 @@ void Menu::previousChoice() { void Menu::menuBack() { if(!listId.empty()){ - id = listId.back(); + choice = 0; + id = listId.back().first; + nbreChoices = listId.back().second; listId.pop_back(); } + } void Menu::menuNext() { if(id ==0){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); id = 1; choice = 0; nbreChoices = 3; } else if (id == 1){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); switch (choice){ case 0 : id = 2; @@ -117,7 +120,7 @@ void Menu::menuNext() { } else if(id == 3){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); switch (choice){ case 0 : id = 5; @@ -137,7 +140,7 @@ void Menu::menuNext() { } } else if(id == 4){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); switch (choice){ case 0 : id = 7; @@ -166,16 +169,16 @@ void Menu::menuNext() { } } else if(id == 5){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); id = 11; choice = 2; } else if (id == 11){ - listId.push_back(id); + listId.push_back(*(new std::pair(id,nbreChoices))); id = 12; choice = 2; } - else if (id == 12){ + else if (id == 12 || id == 6){ listId.clear(); id = 0; choice = 0; diff --git a/app/src/Tortue.cpp b/app/src/Tortue.cpp index 3472ffb..9add21e 100644 --- a/app/src/Tortue.cpp +++ b/app/src/Tortue.cpp @@ -76,7 +76,7 @@ int Tortue::getNbTortue() { std::string Tortue::getInfo() { std::string message; message = "\nMy name is "+this->nom; - message += "\nI am 16 years old"; + message += "\n" + this->getAge(); message += "\n"+this->sexe; return message; } @@ -93,6 +93,10 @@ void Tortue::setSexe(const string &sexe) { Tortue::sexe = sexe; } +void Tortue::delete1() { + --nbTortue; +} + diff --git a/back.txt b/back.txt deleted file mode 100644 index e69de29..0000000 diff --git a/sketch_ino.cpp b/sketch_ino.cpp index f602d89..2e69b3d 100644 --- a/sketch_ino.cpp +++ b/sketch_ino.cpp @@ -129,7 +129,7 @@ void Board::loop() { if (menu->getId() == 5){ Keyboard::saisie = true ; - sleep(5); + sleep(4); if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { bus.requestFrom(2, inputBuf, 150); if (inputBuf[0] != '\0') { @@ -146,7 +146,7 @@ void Board::loop() { } } else if (menu->getId() == 11){ Keyboard::saisie = true ; - sleep(5); + sleep(4); if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { bus.requestFrom(2, inputBuf, 150); if (inputBuf[0] != '\0') { @@ -161,6 +161,7 @@ void Board::loop() { } } else if (menu->getId() == 12){ Keyboard::saisie = true ; + sleep(4); if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { bus.requestFrom(2, inputBuf, 150); if (inputBuf[0] != '\0') { @@ -172,6 +173,33 @@ void Board::loop() { 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++;