#include <iostream>
#include <time.h>
#include <string>
#include <set>
<code>
using namespace std;
int main()
{
setlocale (LC_ALL, "portuguese");
int ranki, ranki2;
ranki = 1;
char escolha = 'v', dificuldade;
//Início
while (escolha == 'v'){
//Verificar a dificuldade
if (dificuldade == 'f' ){
cout << "Dificuldade atual: "; cout << "Fácil" << endl; }
else if (dificuldade == 'd'){
cout << "Dificuldade atual: "; cout << "Difícil" << endl; }
else{ cout << "Dificuldade atual: "; cout << "Média" << endl; }
//Menu
//Caso queira adicionar mais uma opção, coloque a letra inicial da opção Ex.: r de Ranking. Então faça mais um else if com essa opção e coloque no menu.
cout << "Para escolher, digite a primeira letra da opção." << endl;
cout << "//Jogar" << endl;
cout << "//Dificuldade" << endl;
cout << "//Sobre" << endl;
cout << "//Fim" << endl;
cout << "//Ranking" <<endl;
cin >> escolha;
system("cls");
//Sobre
if (escolha == 's'){
cout << "jogo feito por." << endl;
cout << "//Voltar" << endl;
cin >> escolha;
system("cls");
}
//Fim
else if (escolha == 'r'){
cout<< ranki;
}
else if (escolha == 'f'){
return 0;
}
//Dificuldade
else if (escolha == 'd'){
cout << "//Fácil: 3 dígitos, 08 tentativas." << endl;
cout << "//Média: 4 dígitos, 10 tentativas.(Padrão Inicial)" << endl;
cout << "//Difícil: 5 dígitos, 12 tentativas." << endl;
cout << "//Voltar" << endl;
cin >> dificuldade;
//Fácil
if (dificuldade == 'f'){
srand (time(NULL));
int numero;
string valor;
for(int i = 0; i < 3; i++){
numero = rand()%3+1;
cout << numero<< " ";
valor += to_string(numero);
}
cout << endl << endl << valor;
}
//Difícil
else if (dificuldade == 'd'){
srand (time(NULL));
int numero;
string valor;
for(int i = 0; i < 5; i++){
numero = rand()%5+1;
cout << numero<< " ";
valor += to_string(numero);
}
cout << endl << endl << valor;
}
//Média
else{
srand (time(NULL));
int numero;
string valor;
for(int i = 0; i < 4; i++){
numero = rand()%4+1;
cout << numero<< " ";
valor += to_string(numero);
}
cout << endl << endl << valor;
}
system("cls");
escolha = 'v';
}
//O Jogo
else if (escolha == 'j') {
do{
string senha;
system("cls");
srand(time(NULL));
int numero;
string valor;
set<int> numerosgerados; // Para registrar os numeros
// Checagem de dificuldade e geração dos números
int maxnumero;
if (dificuldade == 'f') {
maxnumero = 3;
}
else if (dificuldade == 'd') {
maxnumero = 5;
}
else {
maxnumero = 4;
}
while (numerosgerados.size() < maxnumero) {
numero = rand() % 6 + 1;
if (numerosgerados.find(numero) == numerosgerados.end()) {
numerosgerados.insert(numero);
valor += to_string(numero);
}
}
//cout << "Número gerado: " << valor << endl; para testes
// Verificação de tentativas
int tentativas;
if (dificuldade == 'f'){
tentativas = 8;
}
else if (dificuldade == 'd'){
tentativas = 12;
}
else {
tentativas = 10;
}
while (tentativas > 0 && senha != valor ){
cout << "Tentativas restantes: " << tentativas << endl;
// Resposta do usuário e a comparação
cout << "Digite um número com " << maxnumero << " dígitos: ";
cin >> senha;
system("cls");
cout << senha << endl;
int acertosNaPosicao = 0;
int acertosForaPosicao = 0;
for (int i = 0; i < maxnumero; i++) {
if (senha[i] == valor[i]) {
acertosNaPosicao++;
}
else if (valor.find(senha[i]) != string::npos) {
acertosForaPosicao++;
}
}
//retorno
cout << "Dígitos corretos na posição correta: " << acertosNaPosicao << endl;
cout << "Dígitos corretos, mas na posição errada: " << acertosForaPosicao << endl;
tentativas = tentativas - 1;
if (senha == valor){
system("cls");
cout << "Você ganhou, a senha era mesmo " << valor << endl;
}
else if (tentativas == 0){
system("cls");
cout << "Você perdeu, a senha era: " << valor << endl;
}
numerosgerados.clear();
}
if (senha == valor || tentativas == 0) {
//Opções depois do jogo acabar
cout << "//Jogar Novamente." << endl;
cout << "//Voltar ao Menu." << endl;
cout<< "//Acessar Ranking" <<endl;
cin >> escolha;
system("cls");
}
}while (escolha == 'j');
}
}
return 0;
}