-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
301 lines (250 loc) · 7.88 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
Gabriel Alves Kuabara - nUSP 11275043
Daniel Carvalho Dantas - nUSP 10685702
Pedro Afonso Perez Chagas - nUSP 7777970
Antonio Italo Lima Lopes - nUSP 12542290
*/
/*
Rascunho do Projeto: MidnightGororoba
- Classe usuário
- Ingredientes
- Métodos:
- Adicionar ingrediente
- Perguntar nome e quantidade
- Verificar se já existe na lista
- Remover ingrediente
- Perguntar nome e quantidade
- Remover quantidades
- Ver ingredientes
- Limpar ingredientes
- Classe Receita
- Ingredientes essenciais
- Ingredientes opcionais
- Loop Principal
- Adicionar Ingredientes
- Informe o número de ingredientes
- lista de ingredientes
- Remover Ingredientes
- Ver ingredientes atuais
- Ver receitas possíveis com ingredientes atuais
- Busca linear contando quantos ingredientes dão match
- Fechar Programa
- Banco de dados com receitas
- Interfaces
- Inicio:
- Welcome to Midnight Gororoba
- Pedir para pressionar uma tecla
- Menu:
- Inserir ingredientes
- Remover ingredientes
- Buscar receitas
- "Já achei minha receita, obrigado MidnightGororoba!"
- Artes ASCII
- Welcome to Midnight Gororoba
- Vergonha da Profission
- Ratatouile?
- *****Ratatonho*****
- Imagens de receitas?
*/
/*
Interface:
- Start: Pepe lindo
- Mudar mensagem de inicio
- Colocar enter dentro de caixinha
- Colocar mensagem
- Menu:
- Uma caixinha para cada opção (1 a 5)
- Escolha uma opção:
- SYSTEM.clear
- Inserir Ingredientes:
- Tabela Similar ao menu para repetir ou voltar ao menu
- ASCII Art acompanhando (Ratatonho???)
- Mensagem de efeito
- Pedindo o ingrediente
- Mensagem de confirmação
- Requisitando outro ingrediente ou menu
- Mensagem para ingrediente repetido ("sabe ler não?")
- Retirar Ingredientes:
- Tabela Similar ao menu para repetir ou voltar ao menu
- ASCII Art acompanhando
- Mensagem de efeito
- Mensagem Pedindo ingrediente
- Confirmação de remoção
- Mensagem para ingrediente que não foi colocado ("sabe ler não?")
- Listar Ingredientes:
- Tem ingrediente:
- Listar os ingredientes em tabela
- Volta pra menu
- Não tem ingredientes:
- Se não houver ingredientes listados, vergonha da profission?
- "Inflação tá alta, né meu filho?"
- Volta pro menu
- Buscar Receitas:
- Botar ASCII art do chefe incrível como tela de loading - 2/3s
- Receitas Listadas em tabelas
- Se não encontrar receitas, vergonha da profission e mandar ir no mercado.
- Voltar para menu
- Sair do programa:
- ASCII meme
- vai ser peidão mesmo?
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include "recipe.cpp"
#include "user.cpp"
#include "asciiArts.cpp"
using namespace std;
vector<Recipe> recipes, possibleRecipes;
void startRecipes() {
ifstream file("receitas.txt");
string line;
while(getline(file, line) && file.good()) {
cout << line << endl;
if (line.empty()) break;
recipes.push_back(Recipe(line));
}
}
bool compareRecipes(Recipe a, Recipe b) {
return (a.nOptionals >= b.nOptionals);
}
bool isSubstring(string a, string b) {
for(int i = 0; i + a.size() <= b.size(); ++i) {
if(b.substr(i, a.size()) == a)
return true;
}
return false;
}
void calculateMatches(User& user) {
possibleRecipes.clear();
for(int i = 0; i < recipes.size(); ++i) {
Recipe& recipe = recipes[i];
recipe.nNeeds = 0;
recipe.nOptionals = 0;
for(int j = 0; j < recipe.needs.size(); ++j) {
for(int k = 0; k < user.ingredients.size(); ++k) {
if(isSubstring(user.ingredients[k], recipe.needs[j]))
++recipe.nNeeds;
}
}
for(int j = 0; j < recipe.optionals.size(); ++j) {
for(int k = 0; k < user.ingredients.size(); ++k) {
if(isSubstring(user.ingredients[k], recipe.optionals[j]))
++recipe.nOptionals;
}
}
if(recipe.nNeeds == recipe.needs.size()) {
possibleRecipes.push_back(recipe);
}
}
sort(possibleRecipes.begin(), possibleRecipes.end(), compareRecipes);
}
void printPossibleRecipes() {
if(possibleRecipes.size() == 0) {
printShame();
sleep(3);
system("clear");
return;
}
printChef();
cout << "\n\t\t\t\t\t\t Procurando receitas...\n";
sleep(2);
system("clear");
printCroissant();
cout << BOLDCYAN;
cout << "\t\t\t\t\t_____________________________________________\n";
cout << "\t\t\t\t\t| | |\n";
cout << "\t\t\t\t\t| " << 0 << " |";
cout << " Voltar para o Menu Principal ";
cout << "|\n\t\t\t\t\t|_______|___________________________________|\n";
for(int i = 0; i < possibleRecipes.size(); ++i) {
cout << "\t\t\t\t\t| | |\n";
cout << "\t\t\t\t\t| " << i + 1 << " |";
int l = possibleRecipes[i].name.size();
for(int j = 0; 2*(j + 1) <= (35 - l); ++j) {
cout << " ";
}
cout << possibleRecipes[i].name;
for(int j = 0; j < 35 - l - ((35 - l)/2); ++j) {
cout << " ";
}
cout << "|\n\t\t\t\t\t|_______|___________________________________|\n";
}
cout << RESET;
while (true) {
cout << "\nSelecione uma das Receitas: ";
int select;
cin >> select;
while (!cin.good()) {
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
if (select == 0) {
system("clear");
break;
}
else if (select > 0 && select <= possibleRecipes.size()){ // ]0, size]
possibleRecipes[select - 1].printRecipe();
}
else{
printAdvice();
cout << "\n\t\t\t\t\t\t\t Voltando para o menu...\n";
sleep(3);
system("clear");
break;
}
}
}
void menu () {
User user = User();
int option;
while(true) {
printMenu();
cout << "Escolha uma opção: ";
cin >> option;
while (!cin.good()) {
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
system("clear");
switch (option) {
case 1:
user.addIngredient();
break;
case 2:
user.removeIngredient();
break;
case 3:
user.printAllIngredients();
break;
case 4:
calculateMatches(user);
printPossibleRecipes();
break;
case 5:
printPepe();
getchar();
return;
default:
printAdvice();
break;
}
}
}
void printInitialScreen() {
system("clear");
printWelcome();
getchar();
system("clear");
}
int main() {
startRecipes();
printInitialScreen();
menu();
return 0;
}