Projet_VictorAvecUnK/app/src/Menu.cpp

202 lines
5.1 KiB
C++

//
// Created by camer on 22/05/2020.
//
#include "../include/Menu.h"
Menu::Menu() : id(0), choice(0), nbreChoices(1) {
list.push_back(*(new std::pair<int,
std::string>(1,"\n Liste tortue ")));
list.push_back(*(new std::pair<int,
std::string>(1,"\n Management tortue ")));
list.push_back(*(new std::pair<int,
std::string>(1,"\n Gestion terrarium ")));
list.push_back(*(new std::pair<int,
std::string>(2,"\nInformation Tortue : ")));
list.push_back(*(new std::pair<int,
std::string>(3,"\n Ajouter tortue")));
list.push_back(*(new std::pair<int,
std::string>(3,"\n supprimer tortue")));
list.push_back(*(new std::pair<int,
std::string>(4,"\n Temperature max")));
list.push_back(*(new std::pair<int,
std::string>(4,"\n Temperature min")));
list.push_back(*(new std::pair<int,
std::string>(4,"\n Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(4,"\n Profondeur min")));
list.push_back(*(new std::pair<int,
std::string>(5,"\n Nom de la tortue a ajouter")));
list.push_back(*(new std::pair<int,
std::string>(11,"\n Naissance")));
list.push_back(*(new std::pair<int,
std::string>(12,"\n Sexe")));
list.push_back(*(new std::pair<int,
std::string>(6,"\n Nom de la tortue a supprimer")));
list.push_back(*(new std::pair<int,
std::string>(7,"\n Temperature max")));
list.push_back(*(new std::pair<int,
std::string>(8,"\n Temperature min")));
list.push_back(*(new std::pair<int,
std::string>(9,"\n Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(10,"\n Profondeur min")));
}
std::string Menu::getMessage() {
int cpt = 0;
std::string message = "";
std::list<std::pair<int,std::string>>::iterator it;
for (it = list.begin(); it != list.end() ; it++) {
if (it->first == id){
if (cpt == choice && id != 2){
message += it->second + "<--";
} else {
message += it->second;
}
++cpt;
}
}
return message;
}
void Menu::nextChoice() {
choice = (choice + 1) % (nbreChoices);
}
void Menu::previousChoice() {
if (choice == 0) choice = nbreChoices;
choice = (choice - 1);
}
void Menu::menuBack() {
if(!listId.empty()){
id = listId.back();
listId.pop_back();
}
}
void Menu::menuNext() {
if(id ==0){
listId.push_back(id);
id = 1;
choice = 0;
nbreChoices = 3;
}
else if (id == 1){
listId.push_back(id);
switch (choice){
case 0 :
id = 2;
choice = 0;
nbreChoices = Tortue::getNbTortue();
break;
case 1 :
id = 3;
choice = 0;
nbreChoices = 2;
break;
case 2 :
id = 4;
choice = 0;
nbreChoices = 4;
break;
default:
id = 0;
choice = 0;
nbreChoices = 1;
}
}
else if(id == 3){
listId.push_back(id);
switch (choice){
case 0 :
id = 5;
choice = 0;
nbreChoices = 1;
break;
case 1 :
id = 6;
choice = 0;
nbreChoices = 1;
break;
default:
id = 0;
choice = 0;
nbreChoices = 1;
}
}
else if(id == 4){
listId.push_back(id);
switch (choice){
case 0 :
id = 7;
choice = 0;
nbreChoices = 1;
break;
case 1 :
id = 8;
choice = 0;
nbreChoices = 1;
break;
case 2 :
id = 9;
choice = 0;
nbreChoices = 1;
break;
case 3 :
id = 10;
choice = 0;
nbreChoices = 1;
break;
default:
id = 0;
choice = 0;
nbreChoices = 1;
}
}
else if(id == 5){
listId.push_back(id);
id = 11;
}
else if (id == 11){
listId.push_back(id);
id = 12;
}
}
std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) {
std:: string message = "";
message = "\nTemperature : " + std::to_string(temp) + " \n";
message += "Pression : " + std::to_string(press) + " \n";
if (rad) message += "Etat du radiateur : ON \n";
else message += "Etat du radiateur : OFF \n";
if (tap) message += "Etat du robinet : ON \n";
else message += "Etat du robinet : OFF \n";
message += "Il y a "+std::to_string(nbTortue)+" Tortues \0";
return message;
}
int Menu::getId() const {
return id;
}
int Menu::getChoice() const {
return choice;
}