diff --git a/LucasCorreia.MathGame/math-game/Libary.cs b/LucasCorreia.MathGame/math-game/Libary.cs new file mode 100644 index 00000000..fb6de24c --- /dev/null +++ b/LucasCorreia.MathGame/math-game/Libary.cs @@ -0,0 +1,108 @@ +public class Libary +{ + private Random randNum = new(); + + private string[] operadores = {"+", "-", "x", "/"}; + public int Easy() + { + int ponto = 0; + for (int i = 0; i < 5; i++) + { + string operador = operadores[randNum.Next(operadores.Length)]; + int num1 = randNum.Next(11); + int num2 = randNum.Next(11); + NovasPerguntas(num1,num2,operador); + int resposta = Convert.ToInt32(Console.ReadLine()); + bool resultado = Resposta(num1,num2,operador,resposta); + if (resultado) + { + ponto++; + } + } + + return ponto; + } + + public int Inter() + { + int ponto = 0; + for (int i = 0; i < 5; i++) + { + string operador = operadores[randNum.Next(operadores.Length)]; + int num1 = randNum.Next(51); + int num2 = randNum.Next(51); + NovasPerguntas(num1,num2,operador); + int resposta = Convert.ToInt32(Console.ReadLine()); + bool resultado = Resposta(num1,num2,operador,resposta); + if (resultado) + { + ponto++; + } + } + + return ponto; + } + + public int Dificult() + { + int ponto = 0; + for (int i = 0; i < 5; i++) + { + string operador = operadores[randNum.Next(operadores.Length)]; + int num1 = randNum.Next(101); + int num2 = randNum.Next(101); + NovasPerguntas(num1,num2,operador); + int resposta = Convert.ToInt32(Console.ReadLine()); + bool resultado = Resposta(num1,num2,operador,resposta); + if (resultado) + { + ponto++; + } + } + + return ponto; + } + + public void NovasPerguntas(int x, int y, string operador) + { + if (operador == "/" && x % y != 0 ) + { + operador = operadores[randNum.Next(3)]; + } + Console.WriteLine("Qual é resultado da conta abaixo ?"); + Console.WriteLine($"{x} {operador} {y}"); + } + + public bool Resposta(int x, int y, string operador, int z) + { + switch (operador) + { + case "+": + if ((x + y) == z) + { + return true; + } + break; + case "-": + if ((x - y) == z) + { + return true; + } + break; + case "/": + if ((x / y) == z) + { + return true; + } + break; + case "x": + if ((x * y) == z) + { + return true; + } + break; + } + + return false; + } +} \ No newline at end of file diff --git a/LucasCorreia.MathGame/math-game/Program.cs b/LucasCorreia.MathGame/math-game/Program.cs new file mode 100644 index 00000000..d1895d67 --- /dev/null +++ b/LucasCorreia.MathGame/math-game/Program.cs @@ -0,0 +1,53 @@ +using System.Diagnostics; + +public class Program +{ + public static void Main() + { + int op = 0; + int pontos = 0; + Libary lb = new(); + double tempo_jogo = 0; + List rodadas = []; + List tempo_rodadas = []; + do + { + Console.WriteLine("===============================\nBem vindo ao Jogo Matématico.\n==============================="); + Console.WriteLine("\nEscolha uma opção abaixo:"); + Console.WriteLine("1- Jogo fácil\n2- Jogo intermédiario\n3- Jogo Difícil\n4- Listar Pontuações\n0- Sair do jogo"); + op = Convert.ToInt32(Console.ReadLine()); + Console.Clear(); + switch (op) + { + case 1: + tempo_jogo = Time.MedirTempo(() => pontos = lb.Easy()); + rodadas.Add(pontos); + tempo_rodadas.Add(tempo_jogo); + break; + case 2: + pontos = lb.Inter(); + rodadas.Add(pontos); + break; + case 3: + pontos = lb.Dificult(); + rodadas.Add(pontos); + break; + case 4: + Console.WriteLine("=====================\n=PONTUAÇÃO DOS JOGOS=\n====================="); + for (int i = 0; i < rodadas.Count; i++) + { + Console.WriteLine($"Rodada {i + 1}° -> {rodadas[i]} pontos | Tempo -> {(int)tempo_rodadas[i]} segundos"); + } + Console.ReadLine(); + Console.WriteLine(); + break; + case 0: + break; + default: + Console.WriteLine("Opção inválida"); + break; + } + }while(op != 0); + + } +} \ No newline at end of file diff --git a/LucasCorreia.MathGame/math-game/README.md b/LucasCorreia.MathGame/math-game/README.md new file mode 100644 index 00000000..6e5a3bb6 --- /dev/null +++ b/LucasCorreia.MathGame/math-game/README.md @@ -0,0 +1,16 @@ +# Desafio Jogo da Matemática + +Criar um jogo que consiste em perguntar ao jogador qual é resultado de uma pergunta de matemática (ou seja, 9 x 9 = ?), coletar a entrada e adiconar um ponto em caso de uma resposta coreta. + +## Requisitos do projeto + +- [X] Ter pelo menos 5 perguntas. +- [X] As divisões resultam apenas em INTEGERS e os dividendos devem passar de 0 a 100. Além disso não deve apresentar a divisão 7/2 para o usuário, já que não resulta em um número inteiro. +- [X] Os usuários devem receber um menu para escolher uma operação. +- [X] Deve gravar jogos anteriores em uma lista e deve haver uma opção no menu para o usuário visualizar um histórico de jogos anteriores. + +## Desafios +- [X] Implementar níveis de dificuldade. +- [X] Adicione um tempororizador para acompanhar quanto o usuário leva para terminar o jogo. +- [X] Crie uma opção de 'jogo aleátorio' onde os jogadores serão apresentados com perguntas de operações aleatórios. (* Praticamente todos que eu fiz são aleátorios.) +- [X] Tentar usar apenas um método para todos os jogos. Utilizar o Princípio DRY. ( Não achei algo !) \ No newline at end of file diff --git a/LucasCorreia.MathGame/math-game/Teste.cs b/LucasCorreia.MathGame/math-game/Teste.cs new file mode 100644 index 00000000..7eb3573c --- /dev/null +++ b/LucasCorreia.MathGame/math-game/Teste.cs @@ -0,0 +1,9 @@ +public class Teste +{ + public void Test() + { + Libary lb = new(); + + lb.NovasPerguntas(7,2,"/"); + } +} \ No newline at end of file diff --git a/LucasCorreia.MathGame/math-game/Time.cs b/LucasCorreia.MathGame/math-game/Time.cs new file mode 100644 index 00000000..49a4a339 --- /dev/null +++ b/LucasCorreia.MathGame/math-game/Time.cs @@ -0,0 +1,15 @@ +using System.Diagnostics; + +public class Time +{ + public static double MedirTempo(Action acao) + { + Stopwatch tempo = Stopwatch.StartNew(); + + acao(); + + tempo.Stop(); + + return tempo.Elapsed.TotalSeconds; + } +} \ No newline at end of file diff --git a/LucasCorreia.MathGame/math-game/math-game.csproj b/LucasCorreia.MathGame/math-game/math-game.csproj new file mode 100644 index 00000000..d4b756a1 --- /dev/null +++ b/LucasCorreia.MathGame/math-game/math-game.csproj @@ -0,0 +1,11 @@ + + + + Exe + net10.0 + math_game + enable + enable + + +