Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions LucasCorreia.MathGame/math-game/Libary.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
53 changes: 53 additions & 0 deletions LucasCorreia.MathGame/math-game/Program.cs
Original file line number Diff line number Diff line change
@@ -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<int> rodadas = [];
List<double> 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);

}
}
16 changes: 16 additions & 0 deletions LucasCorreia.MathGame/math-game/README.md
Original file line number Diff line number Diff line change
@@ -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 !)
9 changes: 9 additions & 0 deletions LucasCorreia.MathGame/math-game/Teste.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Teste
{
public void Test()
{
Libary lb = new();

lb.NovasPerguntas(7,2,"/");
}
}
15 changes: 15 additions & 0 deletions LucasCorreia.MathGame/math-game/Time.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions LucasCorreia.MathGame/math-game/math-game.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>math_game</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading