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
3 changes: 3 additions & 0 deletions MathGame.lucidest/MathGame.lucidest.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="MathGame.lucidest/MathGame.lucidest.csproj" />
</Solution>
110 changes: 110 additions & 0 deletions MathGame.lucidest/MathGame.lucidest/Engine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MathGame
{
public class Engine
{
public static bool Addition()
{
int num1 = Random.Shared.Next(0, 13);
int num2 = Random.Shared.Next(0, 13);

Console.WriteLine($"{num1} + {num2} = ?");
Console.Write("\nAnswer: ");

string input = Console.ReadLine();

int answer = Validation.Validate(input);
int corrAns = num1 + num2;

if (corrAns == answer)
{
Console.WriteLine("That's correct, good job!");
return true;
}
else
{
Console.WriteLine($"Incorrect, correct answer: {corrAns}");
return false;
}
}

public static bool Subtraction()
{
int num1 = Random.Shared.Next(0, 13);
int num2 = Random.Shared.Next(0, 13);

Console.WriteLine($"{num1} - {num2} = ?");
Console.Write("\nAnswer: ");

string input = Console.ReadLine();

int answer = Validation.Validate(input);
int corrAns = num1 - num2;

if (corrAns == answer)
{
Console.WriteLine("That's correct, good job!");
return true;
}
else
{
Console.WriteLine($"Incorrect, correct answer: {corrAns}");
return false;
}
}

public static bool Multiplication()
{
int num1 = Random.Shared.Next(0, 13);
int num2 = Random.Shared.Next(0, 13);

Console.WriteLine($"{num1} * {num2} = ?");
Console.Write("\nAnswer: ");

string input = Console.ReadLine();

int answer = Validation.Validate(input);
int corrAns = num1 * num2;

if (corrAns == answer)
{
Console.WriteLine("That's correct, good job!");
return true;
}
else
{
Console.WriteLine($"Incorrect, correct answer: {corrAns}");
return false;
}
}

public static bool Division()
{
int num1 = Random.Shared.Next(1, 13);
int maxQuot = 100 / num1;
int corrQuot = Random.Shared.Next(0, maxQuot + 1);
int num2 = num1 * corrQuot;

Console.WriteLine($"{num2} / {num1} = ?");
Console.Write("\nAnswer: ");

string input = Console.ReadLine();

int answer = Validation.Validate(input);

if (corrQuot == answer)
{
Console.WriteLine("That's correct, good job!");
return true;
}
else
{
Console.WriteLine($"Incorrect, correct answer: {corrQuot}");
return false;
}
}
}
}
10 changes: 10 additions & 0 deletions MathGame.lucidest/MathGame.lucidest/MathGame.lucidest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
4 changes: 4 additions & 0 deletions MathGame.lucidest/MathGame.lucidest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using MathGame;

UI menu = new UI();
menu.StartGame();
111 changes: 111 additions & 0 deletions MathGame.lucidest/MathGame.lucidest/UI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MathGame;

public class UI
{
List<string> hist = new();
public int totalCount = 0;
public int winCount = 0;
public bool contPlaying = true;
private void DisplayMenu()
{
Console.WriteLine("-----------\tWelcome to the math game!\t-----------");
}
private int DisplayOptions()
{
Console.WriteLine("Please select from the options below for your challenge.");
Console.WriteLine("\n1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
Console.WriteLine("5. History");
Console.WriteLine("6. Quit");

Console.Write("\nSelection: ");
string input = Console.ReadLine();

while (!int.TryParse(input, out int result) || result < 1 || result > 6)
{
Console.WriteLine("\nPlease select from the options below for your challenge.");
Console.WriteLine("\n1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
Console.WriteLine("5. History");
Console.WriteLine("6. Quit");

Console.WriteLine("\nInvalid input. Please try again:");
Console.Write("\nSelection: ");
input = Console.ReadLine();
}
return int.Parse(input);
}

public void StartGame()
{
DisplayMenu();
do
{

int input = DisplayOptions();
switch (input)
{
case 1:
bool resultAdd = Engine.Addition();
if (resultAdd)
winCount++;
totalCount++;
if (resultAdd)
hist.Add("Addition - WIN");
else hist.Add("Addition - LOSS");
Console.WriteLine($"Score: {winCount}");
break;
case 2:
bool resultSub = Engine.Subtraction();
if (resultSub)
winCount++;
totalCount++;
if (resultSub)
hist.Add("Subtraction - WIN");
else hist.Add("Subtraction - LOSS");
Console.WriteLine($"Score: {winCount}");
break;
case 3:
bool resultMul = Engine.Multiplication();
if (resultMul)
winCount++;
totalCount++;
if (resultMul)
hist.Add("Multiplication - WIN");
else hist.Add("Multiplication - LOSS");
Console.WriteLine($"Score: {winCount}");
break;
case 4:
bool resultDiv = Engine.Division();
if (resultDiv)
winCount++;
totalCount++;
if (resultDiv)
hist.Add("Division - WIN");
else hist.Add("Division - LOSS");
Console.WriteLine($"Score: {winCount}");
break;
case 5:
Console.WriteLine();
foreach (string history in hist)
{
Console.WriteLine(history);
Console.WriteLine("-----------\t ------- \t-----------");
}
break;
case 6:
contPlaying = false;
break;
}
Console.WriteLine();
} while (contPlaying);
}
}
20 changes: 20 additions & 0 deletions MathGame.lucidest/MathGame.lucidest/Validation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MathGame
{
public class Validation
{
public static int Validate(string? input)
{
while (!int.TryParse(input, out int result) || string.IsNullOrWhiteSpace(input))
{
Console.WriteLine("Invalid input. Please try again.");
Console.Write("\nAnswer: ");
input = Console.ReadLine();
}
return int.Parse(input);
}
}
}
Loading