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
25 changes: 25 additions & 0 deletions ConsoleApp1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{2B7C869A-7B29-4973-8E40-D4280C301D19}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2B7C869A-7B29-4973-8E40-D4280C301D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B7C869A-7B29-4973-8E40-D4280C301D19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B7C869A-7B29-4973-8E40-D4280C301D19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B7C869A-7B29-4973-8E40-D4280C301D19}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FA0C5B78-59FC-4F91-A35F-4547F4FE40F8}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions MathGame.leolin2810/ConsoleApp1.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>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
24 changes: 24 additions & 0 deletions MathGame.leolin2810/ConsoleApp1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1.csproj", "{7B5B0BC2-7E08-E58C-6436-F53A2B87BA1D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B5B0BC2-7E08-E58C-6436-F53A2B87BA1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B5B0BC2-7E08-E58C-6436-F53A2B87BA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B5B0BC2-7E08-E58C-6436-F53A2B87BA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B5B0BC2-7E08-E58C-6436-F53A2B87BA1D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {72B9E995-B8AB-4117-A663-A4DA72F723CF}
EndGlobalSection
EndGlobal
107 changes: 107 additions & 0 deletions MathGame.leolin2810/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
namespace ConsoleApp1
{
class Game
{
// Defaults to 5 problems per game, but can be changed by user input
private int problemCount = 5;
public List<Problem> problems = new();
private int operation = 5;
private int difficulty = 1;
private int score;
private int time;

public void AddScore(int score)
{
score += score;
}

public Game(int problemCountEntry = 5, int operationEntry = 5, int difficultyEntry = 1)
{
problemCount = problemCountEntry;
operation = operationEntry;
difficulty = difficultyEntry;
}
// Current Setting Display
public void DisplaySettings()
{
Console.WriteLine("Current Settings:");
DisplayProblemCount();
DisplayOperationType();
DisplayDifficulty();
DisplayTime();
}

private void DisplayProblemCount()
{
Console.WriteLine($"Current number of problems: {problemCount}");
}
private void DisplayOperationType()
{
switch (operation)
{
case 1:
{
Console.WriteLine("Current operation: Addition");
break;
}
case 2:
{
Console.WriteLine("Current operation: Subtraction");
break;
}
case 3:
{
Console.WriteLine("Current operation: Multiplication");
break;
}
case 4:
{
Console.WriteLine("Current operation: Division");
break;
}
case 5:
{
Console.WriteLine("Current operation: Random");
break;
}
}
}
private void DisplayDifficulty()
{
Console.WriteLine($"Current difficulty: {difficulty}");
}

public void DisplayScore()
{
Console.WriteLine($"Your score was {score} out of {problemCount}.");
}

public void ClearProblemList()
{
problems.Clear();
}

public void GenerateProblems()
{

for (int i = 0; i < problemCount; i++)
{
Problem problem = new();
problem.GenerateEquation(operation, difficulty);
problems.Add(problem);
}
}

public void SetTime(DateTime start, DateTime end)
{
TimeSpan duration = end - start;
time = duration.Seconds;
}

public void DisplayTime()
{
Console.WriteLine($"Your time was {time} seconds.");
}
}
}

159 changes: 159 additions & 0 deletions MathGame.leolin2810/Problem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
namespace ConsoleApp1
{
class Problem
{
private string equation = "";
private int solution;
private int moduloCheck;
private int maxVal;

private void SetMaxVal(int difficulty)
{
switch (difficulty)
{
case 1:
{
maxVal = 10;
break;
}
case 2:
{
maxVal = 50;
break;
}
case 3:
{
maxVal = 100;
break;
}
}
}
public void GenerateEquation(int operation = 5, int difficulty = 1)
{
Random random = new();
SetMaxVal(difficulty);

if (operation == 5)
{
operation = random.Next(0, 4)+1;
}


switch (operation)
{
// Addition
case 1:
{

Random randint1 = new();
Random randint2 = new();

int addend1 = randint1.Next(0, maxVal);
int addend2 = randint2.Next(0, maxVal);

equation = $"{addend1} + {addend2}";
solution = addend1 + addend2;
break;
}
// Subtraction
case 2:
{
do
{
Random randint1 = new();
Random randint2 = new();

int minuend = randint1.Next(0, maxVal);
int subtractend = randint2.Next(0, maxVal);

equation = $"{minuend} - {subtractend}";
solution = minuend - subtractend;
}
while (solution < 0);

break;
}
//Multiplication
case 3:
{
Random randint1 = new();
Random randint2 = new();

int factor1 = randint1.Next(0, maxVal);
int factor2 = randint2.Next(0, maxVal);

equation = $"{factor1} * {factor2}";
solution = factor1 * factor2;
break;
}
// Division
case 4:
{
do
{
Random randint1 = new();
Random randint2 = new();

int dividend = randint1.Next(0, maxVal);
int divisor = randint2.Next(0, maxVal);

equation = $"{dividend} \u00f7 {divisor}";

try
{
solution = dividend / divisor;
}
catch (DivideByZeroException ex)
{
continue;
}

moduloCheck = dividend % divisor;
//try
//{

//}
//catch (DivideByZeroException ex)
//{
// continue;
//}
}
while (moduloCheck != 0 || solution <= 0);

break;

}
}
}

public void DisplayEquation()
{
Console.WriteLine("What is the solution to the following equation?");
Console.WriteLine(equation);
//Console.WriteLine(Solution);
}

public int CheckSolution(string input)
{
int Input;
if (int.TryParse(input, out Input))
{
if (Input == solution)
{
Console.WriteLine("Correct!");
return 1;
}
else
{
Console.WriteLine($"Incorrect. The correct answer is {solution}.");
return 0;
}
}
else
{
Console.WriteLine($"Invalid input. The correct answer is {solution}.");
return 0;
}
}
}
}
Loading