C
C#14mo ago
Mekasu0124

✅ Keeping Track Of Previous Games, Reset On Game Close - ReWrite

According to The C# Academy, I'm supposed to have a menu option where the user can see the previous games they played. I have this option located in my EndGame class where it asks the user do they want to play again, y/n, or view the history. I have started a previous games class https://pastebin.com/KjvFDFhB but I'm not sure on how to add the 4 lists (addGame, subGame, multGame, and divGames) into the main list previousHistory nor do I know how to iterate through the main list and print everything to the screen. Secondly, in my solution checker file https://pastebin.com/i9RaDz6m I have started the process on line 16, but I have a couple of problems there too. 1) how do I get get the int gameCount = 0; to keep track of the number game the user is on, and 2) how do I take my string writeString and insert it into the addGames list that is in a separate file? I know this probably sounds complicated, but to sum it up I have to be able to allow the user to see the previous games they played. I though it would be easier to keep track of the previous games in a different file, and just call that file to print the items to the console when the user chooses to at the end of the game. Thanks.
156 Replies
TheRanger
TheRanger14mo ago
you cant put a List<string> instance in a List<string> instance List<string> only accepts string its not List<List<string>>
Mekasu0124
Mekasu012414mo ago
right. they're all going to be strings.
TheRanger
TheRanger14mo ago
you could create a class and name it GameHistory or something
Mekasu0124
Mekasu012414mo ago
I did except I named it PreviousHistory that's the first link in the main message
TheRanger
TheRanger14mo ago
i know
Mekasu0124
Mekasu012414mo ago
oh my fault
TheRanger
TheRanger14mo ago
but PreviousHistory will contain a collection of Previously played Games right?
Mekasu0124
Mekasu012414mo ago
right ok so I renamed my file and class to GameHistory
TheRanger
TheRanger14mo ago
dont keep PreviousHistory
Mekasu0124
Mekasu012414mo ago
ok I reverted it
TheRanger
TheRanger14mo ago
addGames and the rest, what are you trying to add to their list?
Mekasu0124
Mekasu012414mo ago
and as far as trying to do nested lists,
public void ViewHistory()
{
List<string> previousHistory = new()
{
"Addition Games",
List<string> addGames = new List<string>(),
public void ViewHistory()
{
List<string> previousHistory = new()
{
"Addition Games",
List<string> addGames = new List<string>(),
is giving an error on addGames saying it's a syntax error
TheRanger
TheRanger14mo ago
thats invalid code
Mekasu0124
Mekasu012414mo ago
the string writeString that is located on line 16 of the second link in the main message
TheRanger
TheRanger14mo ago
so an example would look like
Mekasu0124
Mekasu012414mo ago
the solution checker is setup based off the operation + = * / to determine how to check the solution based off the game so I figured I could piggy back off of that to go inside the case "+" for the addition game, have the integer gameCount and the string being written to the addGames list in the previous games it would be a lot easier to explain if I could do a voice chat and show my screen
TheRanger
TheRanger14mo ago
Game 2: 2 + 2 = 4 -> solution correct
Game 2: 2 + 2 = 4 -> solution correct
?
Mekasu0124
Mekasu012414mo ago
right it's all a string but the previousHistory list is sub listed by the game types so how would I write the sub list into the main list?
TheRanger
TheRanger14mo ago
you can just create a class called Game and store these details into its Properties
Mekasu0124
Mekasu012414mo ago
i'm lost
TheRanger
TheRanger14mo ago
create a class called Game
Mekasu0124
Mekasu012414mo ago
do I delete my PreviousHistory class?
TheRanger
TheRanger14mo ago
no
Mekasu0124
Mekasu012414mo ago
ok I have my game class
TheRanger
TheRanger14mo ago
do u know what a property is?
Mekasu0124
Mekasu012414mo ago
a variable declared within the class like
class SomeClass
{
public int readonly gameCount = 0;
}
class SomeClass
{
public int readonly gameCount = 0;
}
TheRanger
TheRanger14mo ago
close but thats a field
class SomeClass
{
public int gameCount {get; set;}
}
class SomeClass
{
public int gameCount {get; set;}
}
Mekasu0124
Mekasu012414mo ago
oh then no. I haven't learned getters and setters yet
TheRanger
TheRanger14mo ago
then you can use fields
Mekasu0124
Mekasu012414mo ago
I know this sounds weird, but if I could show you my code/screen it would be a lot easier I guess for me. I have a Program.cs - main file MainMenu.cs AdditionGame.cs SubtractionGame.cs MultiplicationGame.cs DivisionGame.cs SolutionChecker.cs EndGame.cs and like the program.cs is called first, then it calls main menu, then that calls to whichever game the user selects and all 4 game screens share the solution checker and end game files.
TheRanger
TheRanger14mo ago
hmm you already have classes for AdditionGame and the rest? very hard, try using paste bin
Mekasu0124
Mekasu012414mo ago
right
TheRanger
TheRanger14mo ago
$paste
MODiX
MODiX14mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
TheRanger
TheRanger14mo ago
it looks like vscode, you can upload your files there
Mekasu0124
Mekasu012414mo ago
is visual studio
TheRanger
TheRanger14mo ago
ah well i did tell you to use that site, guess ill have to copy paste manually
Mekasu0124
Mekasu012414mo ago
you also said that I could upload my files....
TheRanger
TheRanger14mo ago
i mean onto that site
Mekasu0124
Mekasu012414mo ago
here is Program.cs, MainMenu.cs, AdditionGame.cs, SubtractionGame.cs, MultiplicationGame.cs and DivisionGame.cs https://paste.mod.gg/esqhjnxmzvhb/5
BlazeBin - esqhjnxmzvhb
A tool for sharing your source code with the world!
Mekasu0124
Mekasu012414mo ago
and here is SolutionChecker.cs, EndGame.cs and PreviousHistory.cs https://paste.mod.gg/tbpyzyahkjgv/2
BlazeBin - tbpyzyahkjgv
A tool for sharing your source code with the world!
Mekasu0124
Mekasu012414mo ago
please don't judge my code. I'm brand new to this language yea
TheRanger
TheRanger14mo ago
we dont judge people's code here the main reason we are here is to help people
Mekasu0124
Mekasu012414mo ago
I appreciate that. I tried really hard to make this code as efficient and clean as possible that's why there are so many files. I mean I could've written all 4 games in the same file, but that was too much code for me to keep up with honestly
TheRanger
TheRanger14mo ago
ok looking at ur code, it seems ur stuck in the SolutionChecker class, correct?
Mekasu0124
Mekasu012414mo ago
yes and no how can I explain it on line 16 of the solution checker I'm trying to keep up with the game count. the game being the number of questions the user has answered so if they put in that they wanted to answer 6 questions, then that would be 6 games and then I have on the next line the string that would be appeneded to the addition previous games list. So like if they entered that they wanted to answer 6 questions, then it would add each question to the list as they answered them. like
what is 6+6
user inputs 12
display to user that answer is correct then add that question and answer to the list in the format of Game 1: 6+6=12 -> solution correct
what is 6+6
user inputs 12
display to user that answer is correct then add that question and answer to the list in the format of Game 1: 6+6=12 -> solution correct
TheRanger
TheRanger14mo ago
i get it
Mekasu0124
Mekasu012414mo ago
ok good lol I'm sweating tryign to figure out how to explain this
TheRanger
TheRanger14mo ago
first your gameCount is a local variable
Mekasu0124
Mekasu012414mo ago
it should be global instead?
TheRanger
TheRanger14mo ago
which means it only exists in brackets between line 15 and line 25
Mekasu0124
Mekasu012414mo ago
ok I'll make it global within the class
class SolutionChecker
{
PreviousHistory prevHist = new();

public int gameCount = 0;
class SolutionChecker
{
PreviousHistory prevHist = new();

public int gameCount = 0;
TheRanger
TheRanger14mo ago
thats also bad
Mekasu0124
Mekasu012414mo ago
oh..... I"m sorry. so my only other option would be to make it global within the function not global but public
TheRanger
TheRanger14mo ago
everytime you are creating a new instance of SolutionChecker when you call the StartGame method
Mekasu0124
Mekasu012414mo ago
only one game is played at a time, so what should I do with it then?
TheRanger
TheRanger14mo ago
well you can probably store the gameCount as a static field in the PreviousHistory class since it would make sense to be placed there
Mekasu0124
Mekasu012414mo ago
above or inside of the ViewHistory method? my brain hurts >_<
TheRanger
TheRanger14mo ago
u cant define a field in a method
Mekasu0124
Mekasu012414mo ago
like in python, I would just put the game count variable as a self. in the init method what would be the c# equivalent to that
TheRanger
TheRanger14mo ago
a field
Mekasu0124
Mekasu012414mo ago
idk if you speak python or not lol soryr ok what would be an example of a field? this?
TheRanger
TheRanger14mo ago
class PreviousHistory { public static int gameCount = 0; is equivalent to a global variable in python
Mekasu0124
Mekasu012414mo ago
ok I have that now
TheRanger
TheRanger14mo ago
you should know how to increment it then do u start with Game 0 or Game 1?
Mekasu0124
Mekasu012414mo ago
class PreviousHistory
{
public static int gameCount = 0;
public void ViewHistory()
{
gameCount++;
class PreviousHistory
{
public static int gameCount = 0;
public void ViewHistory()
{
gameCount++;
TheRanger
TheRanger14mo ago
yeah lets keep that you should realize ur mistake soon anyway your class PreviousHistory should be static, you dont want to create many instances of it, right?
Mekasu0124
Mekasu012414mo ago
i'd rather not screw it up already please. what do I have wrong? I'm here to learn it right the first time please
TheRanger
TheRanger14mo ago
dont worry you will learn when you realize and im here with you
Mekasu0124
Mekasu012414mo ago
😟 ok. I changed my method to static instead of public
TheRanger
TheRanger14mo ago
what method? those 2 are different things
Mekasu0124
Mekasu012414mo ago
oh the class. not the method. sorry
TheRanger
TheRanger14mo ago
public static class PreviousHistory u want it public so you can access it from anywhere else you want it static so that you dont need to create instances of it, you can directly access the type
Mekasu0124
Mekasu012414mo ago
ok bet. got that
TheRanger
TheRanger14mo ago
back to solutionchecker
Mekasu0124
Mekasu012414mo ago
ok
TheRanger
TheRanger14mo ago
you want to add to the History the what you wrote in writeString, correct?
Mekasu0124
Mekasu012414mo ago
correct
TheRanger
TheRanger14mo ago
first make those
List<string> addGames = new();
List<string> subGames = new();
List<string> multGames = new();
List<string> divGames = new();
List<string> addGames = new();
List<string> subGames = new();
List<string> multGames = new();
List<string> divGames = new();
as fields in the PreviousHistory class you want them to exist forever, not temporarly
Mekasu0124
Mekasu012414mo ago
like I did the game count right?
TheRanger
TheRanger14mo ago
yes
Mekasu0124
Mekasu012414mo ago
and i want those public static as well right
TheRanger
TheRanger14mo ago
a local variable means that variable only exists in the method and is only accessible inside the method and gets deleted when the method ends sure
Mekasu0124
Mekasu012414mo ago
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}
}
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}
}
ok got those
TheRanger
TheRanger14mo ago
is writeString's purpose only to write into the PreviousHistory? ?
Mekasu0124
Mekasu012414mo ago
correct and what it writes is based off the game being played
TheRanger
TheRanger14mo ago
writeString will get ugly if you write the same code for each operator symbol so create a method in the PreviousHistory class that should do it for you you can call it AddHistory with parameters for num1, operatorSymbol, num2 and computerSolutionAdd ofcourse
Mekasu0124
Mekasu012414mo ago
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}

static void AddHistory(int num1, string operatorSymbol, int num2, int solution, string rightWrong)
{
if (rightWrong == "right")
{
string writeString = "Game " + gameCount + ": " + num1 + operatorSymbol + num2 + " -> solution correct";
}
else
{
string writeString = "Game " + gameCount + ": " + num1 + operatorSymbol + num2 + " -> solution wrong";
}
}
}
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}

static void AddHistory(int num1, string operatorSymbol, int num2, int solution, string rightWrong)
{
if (rightWrong == "right")
{
string writeString = "Game " + gameCount + ": " + num1 + operatorSymbol + num2 + " -> solution correct";
}
else
{
string writeString = "Game " + gameCount + ": " + num1 + operatorSymbol + num2 + " -> solution wrong";
}
}
}
ok got that I added a parameter though for the if statement....or should I not have?
TheRanger
TheRanger14mo ago
yeah cool but why not use a bool?
Mekasu0124
Mekasu012414mo ago
so instead of string rightWrong do bool rightWrong ok changed it. I like that better lol less code
TheRanger
TheRanger14mo ago
yes you should handle each operator and write your history to their correct list
Mekasu0124
Mekasu012414mo ago
ok one sec
TheRanger
TheRanger14mo ago
note, string interpolation is a thing
Mekasu0124
Mekasu012414mo ago
BlazeBin - ncvhgoliauht
A tool for sharing your source code with the world!
TheRanger
TheRanger14mo ago
string writeString = $"Game {gameCount}: {num1}{operatorSymbol}{num2} -> solution wrong";
string writeString = $"Game {gameCount}: {num1}{operatorSymbol}{num2} -> solution wrong";
Mekasu0124
Mekasu012414mo ago
that's the same as JavaScript except you wrap the string in back ticks instead. I couldn't figure that out for this language lol ok I fixed my string interpolation
TheRanger
TheRanger14mo ago
whats the point of the string with the solution wrong if you will never add it to the history?
Mekasu0124
Mekasu012414mo ago
oh.forgot about that part. copying the switch case down
TheRanger
TheRanger14mo ago
what do u mean?
Mekasu0124
Mekasu012414mo ago
BlazeBin - ocunqbkeslmp
A tool for sharing your source code with the world!
TheRanger
TheRanger14mo ago
good but
Mekasu0124
Mekasu012414mo ago
I feel like there's a cleaner way to write that
TheRanger
TheRanger14mo ago
yes try to write repeated code as less as possible example you already used switch above, try to handle both writeStrings into the same switch statement
Mekasu0124
Mekasu012414mo ago
switch (operatorSymbol)
{
case "+":
if (rightWrong)
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution correct";
addGames.Add(writeString);
}
else
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution wrong";
addGames.Add(writeString);
}
}
switch (operatorSymbol)
{
case "+":
if (rightWrong)
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution correct";
addGames.Add(writeString);
}
else
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution wrong";
addGames.Add(writeString);
}
}
like that?
TheRanger
TheRanger14mo ago
close, theres a better way handle it before you enter the switch statement
Mekasu0124
Mekasu012414mo ago
ok help me. I'm drawing blanks
TheRanger
TheRanger14mo ago

string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution correct";

if (rightWrong == false) writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution wrong";

switch (operatorSymbol)
{
case "+":
addGames.Add(writeString);
break;

case "-":
subGames.Add(writeString);
break;

case "*":
mulGames.Add(writeString);
break;

case "/":
divGames.Add(writeString);
break;

default:
Console.WriteLine("Invalid Operation Adding Game History To List.");
break;
}

string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution correct";

if (rightWrong == false) writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution wrong";

switch (operatorSymbol)
{
case "+":
addGames.Add(writeString);
break;

case "-":
subGames.Add(writeString);
break;

case "*":
mulGames.Add(writeString);
break;

case "/":
divGames.Add(writeString);
break;

default:
Console.WriteLine("Invalid Operation Adding Game History To List.");
break;
}
But, writeString feels repeated, only to modify 1 word so id do
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {(rightWrong? "correct" : "wrong")};
// or
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {RightOrWrong(rightWrong)}; // return from a method
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {(rightWrong? "correct" : "wrong")};
// or
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {RightOrWrong(rightWrong)}; // return from a method
Mekasu0124
Mekasu012414mo ago
that's such a pretty line lol one-liners haven't been taught yet in this academy
TheRanger
TheRanger14mo ago
but it makes your code cleaner
Mekasu0124
Mekasu012414mo ago
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}

static void AddHistory(int num1, string operatorSymbol, int num2, int solution, bool rightWrong)
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {(rightWrong ? "correct" : "wrong")}";

switch (operatorSymbol)
{
case "+":
addGames.Add(writeString);
break;

case "-":
subGames.Add(writeString);
break;

case "*":
mulGames.Add(writeString);
break;

case "/":
divGames.Add(writeString);
break;

default:
Console.WriteLine("Invalid Operation Writing Game History.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}
}
public static class PreviousHistory
{
public static int gameCount = 0;

public static List<string> addGames = new();
public static List<string> subGames = new();
public static List<string> mulGames = new();
public static List<string> divGames = new();

public void ViewHistory()
{
gameCount++;
}

static void AddHistory(int num1, string operatorSymbol, int num2, int solution, bool rightWrong)
{
string writeString = $"Game {gameCount}: {num1} {operatorSymbol} {num2} -> solution {(rightWrong ? "correct" : "wrong")}";

switch (operatorSymbol)
{
case "+":
addGames.Add(writeString);
break;

case "-":
subGames.Add(writeString);
break;

case "*":
mulGames.Add(writeString);
break;

case "/":
divGames.Add(writeString);
break;

default:
Console.WriteLine("Invalid Operation Writing Game History.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}
}
ok here we are
TheRanger
TheRanger14mo ago
ud need to handle that too Console.WriteLine("Invalid Operation Writing Game History."); for right and wrong
Mekasu0124
Mekasu012414mo ago
default:
Console.WriteLine($"Invalid Operation Writing Game History. {(rightWrong ? "correct" : "wrong")}");
Thread.Sleep(2000);
Environment.Exit(0);
break;
default:
Console.WriteLine($"Invalid Operation Writing Game History. {(rightWrong ? "correct" : "wrong")}");
Thread.Sleep(2000);
Environment.Exit(0);
break;
I feel smart af boy lmao
TheRanger
TheRanger14mo ago
do u really want it to print Invalid Operation Writing Game History. correct for the right answer? what does that even mean 😅
Mekasu0124
Mekasu012414mo ago
idk lol I don't know anything about error handling in c#
TheRanger
TheRanger14mo ago
use if? else? or ternary operator ternary operator is just equivalent of if else but makes it one lined eg this is a ternary operator rightWrong ? "correct" : "wrong"
Mekasu0124
Mekasu012414mo ago
right. I get that. I just don't know what to put like I feel dumb again
TheRanger
TheRanger14mo ago
something like Operation successfully added to Game History ?
Mekasu0124
Mekasu012414mo ago
but if the switch case defaults, then the operation failed
TheRanger
TheRanger14mo ago
oh right didnt realize
Mekasu0124
Mekasu012414mo ago
so I put it back to Console.WriteLine("Invalid Operation Writing Game History.");
TheRanger
TheRanger14mo ago
sure
Mekasu0124
Mekasu012414mo ago
ok so we have a function for adding the statement to the correct list so what's next?
TheRanger
TheRanger14mo ago
whats missing? trying to print the history, correct?
Mekasu0124
Mekasu012414mo ago
ok so back in solution checker when I try to call the PreviousHistory class to create an instance it tells me Cannot declare a variable of static type 'PreviousHistory' like we have a way to add the games to the correct lists, but we haven't called it in the solution checker, and haven't written a way for the user to see it when they reach EndGame and it asks them do they want to see their previous games
TheRanger
TheRanger14mo ago
well its a static class, u cant create an instance of it so delete that line
Mekasu0124
Mekasu012414mo ago
class SolutionChecker
{
public void CheckSolution(int num1, string operatorSymbol, int num2, int userSolution)
{
int tries = 3;

switch (operatorSymbol)
{
case "+":
int computerSolutionAdd = num1 + num2;

if (userSolution == computerSolutionAdd)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nCorrect! Great Job! Next Question Incoming!");
PreviousHistory.AddHistory(num1, operatorSymbol, num2, computerSolutionAdd,true);
Thread.Sleep(2000);
Console.Clear();
}
else
{
Console.ForegroundColor= ConsoleColor.Red;
Console.WriteLine(
"Incorrect!\n" +
"Computer Solution: " + computerSolutionAdd + "\n" +
"Your Solution: " + userSolution + "\n" +
"Next Question Incoming!\n"
);
PreviousHistory.AddHistory(num1, operatorSymbol + num2, num2, computerSolutionAdd, false);
Thread.Sleep(2000);
Console.Clear();
}
break;
class SolutionChecker
{
public void CheckSolution(int num1, string operatorSymbol, int num2, int userSolution)
{
int tries = 3;

switch (operatorSymbol)
{
case "+":
int computerSolutionAdd = num1 + num2;

if (userSolution == computerSolutionAdd)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nCorrect! Great Job! Next Question Incoming!");
PreviousHistory.AddHistory(num1, operatorSymbol, num2, computerSolutionAdd,true);
Thread.Sleep(2000);
Console.Clear();
}
else
{
Console.ForegroundColor= ConsoleColor.Red;
Console.WriteLine(
"Incorrect!\n" +
"Computer Solution: " + computerSolutionAdd + "\n" +
"Your Solution: " + userSolution + "\n" +
"Next Question Incoming!\n"
);
PreviousHistory.AddHistory(num1, operatorSymbol + num2, num2, computerSolutionAdd, false);
Thread.Sleep(2000);
Console.Clear();
}
break;
I did that and realized you said to call it directly and now where I'm calling it, it's telling me that I can't call it because of it's protection level so should the method be a public void instead of a static void? and where am I incrementing the game count variable?
TheRanger
TheRanger14mo ago
public static void u want it to be public AND static
Mekasu0124
Mekasu012414mo ago
ok gotcha gotcha and I'm presuming that I would increment gameCount inside of the AddHistory function instead of the ViewHistory function
TheRanger
TheRanger14mo ago
this one looks wrong
PreviousHistory.AddHistory(num1, operatorSymbol + num2, num2, computerSolutionAdd, false);
PreviousHistory.AddHistory(num1, operatorSymbol + num2, num2, computerSolutionAdd, false);
operatorSymbol + num2 ?
Mekasu0124
Mekasu012414mo ago
yep definitely the AI's doing . lol not mine updated and fixed solution checker https://paste.mod.gg/umkjjyglnawy/0 updated and fixed PreviousHistory class https://paste.mod.gg/zrywqxrxymhp/0
TheRanger
TheRanger14mo ago
looks line so far
Mekasu0124
Mekasu012414mo ago
ok bet. so now printing it all to the screen. nested lists
TheRanger
TheRanger14mo ago
yet ur code can be cleaner
Mekasu0124
Mekasu012414mo ago
I want it to show all the games at the same time oh? how? and which file?
TheRanger
TheRanger14mo ago
like we said try to write repeated code as less as possible thats why methods exist you can clean it later tho, not now the CheckSolution method
Mekasu0124
Mekasu012414mo ago
yep figured that file lol
TheRanger
TheRanger14mo ago
you can see each case has the same code, except only 1 line is different we will clean it later tho
Mekasu0124
Mekasu012414mo ago
ok good lol because I"m struggling
TheRanger
TheRanger14mo ago
what are u missing now, printing the history?
Mekasu0124
Mekasu012414mo ago
bringing all the list down into one, then iterating that main list, and having it print like
TheRanger
TheRanger14mo ago
you can define a method called PrintHistory in the PreviousHistory class
Mekasu0124
Mekasu012414mo ago
Addition Games:
Game 1:
Game 2:

Subtraction Games:
Game 1:
Game2:
Addition Games:
Game 1:
Game 2:

Subtraction Games:
Game 1:
Game2:
and so on
TheRanger
TheRanger14mo ago
and let that method do the printing
Mekasu0124
Mekasu012414mo ago
ok I have my method
TheRanger
TheRanger14mo ago
i need to do something, brb in 30 minutes
Mekasu0124
Mekasu012414mo ago
ok np Yay!!! I was able to figure out how to get the list nested, and print the items to the screen, and I added in another option of being able to play again or exit the game from the previous games screen. Thank you so much!
TheRanger
TheRanger14mo ago
back finished already?
Mekasu0124
Mekasu012414mo ago
https://github.com/mekasu0124/MeksMathGame yes :3 the only things i missed for the academy's challenges was to add a timer to track how long that user takes to finish the game and create a random game option where the players will be presented with questions from random operations
TheRanger
TheRanger14mo ago
if you care about performance its a waste to create a list history in the print history method you can just print directly from the lists
Mekasu0124
Mekasu012414mo ago
ok what do you suggest I write it as? I'm all ears
TheRanger
TheRanger14mo ago
something like
Console.WriteLine("Addition Games");
foreach(var foo in addGames)
{
Console.WriteLine(foo);
}
Console.WriteLine("Addition Games");
foreach(var foo in addGames)
{
Console.WriteLine(foo);
}
btw foreach is better than a normal for loop in this context
Mekasu0124
Mekasu012414mo ago
but wouldn't that be repetative?
TheRanger
TheRanger14mo ago
not as repetitive as the history code
Mekasu0124
Mekasu012414mo ago
ok I got you. I fixed it how would I go about putting a timer? It would start when it launched one of the 4 games, and end when the game ended?
TheRanger
TheRanger14mo ago
try and see what happens
Mekasu0124
Mekasu012414mo ago
I could create a timer class to handle the formatting and such so something like
class AdditionGame
{
private static readonly Random rng = new();

public void StartGame(string difficulty, int numOfQues)
{
int tries = 3;

SolutionChecker checkSolution = new();
EndGame endGame = new();

Timer.StartTimer(true);

if (difficulty == "easy")
{
for (int i = 0; i < numOfQues; i++)
{
int num1 = rng.Next(1, 34);
int num2 = rng.Next(1, 34);

int userSolution = PresentQuestion(num1, num2);

checkSolution.CheckSolution(num1, "+", num2, userSolution);
}
Timer.StartTimer(false);
endGame.EndGameScreen();
}
class AdditionGame
{
private static readonly Random rng = new();

public void StartGame(string difficulty, int numOfQues)
{
int tries = 3;

SolutionChecker checkSolution = new();
EndGame endGame = new();

Timer.StartTimer(true);

if (difficulty == "easy")
{
for (int i = 0; i < numOfQues; i++)
{
int num1 = rng.Next(1, 34);
int num2 = rng.Next(1, 34);

int userSolution = PresentQuestion(num1, num2);

checkSolution.CheckSolution(num1, "+", num2, userSolution);
}
Timer.StartTimer(false);
endGame.EndGameScreen();
}
and then I have
class Timer
{
public static int timer = 0;

public static void StartTimer(bool check)
{
while (check)
{
timer++;
Thread.Sleep(1000);
};
return timer;
}
}
class Timer
{
public static int timer = 0;

public static void StartTimer(bool check)
{
while (check)
{
timer++;
Thread.Sleep(1000);
};
return timer;
}
}
the only problem is being able to get that timer added to the history statements unless I write the timer directly into the games no I can't do that. it's ok. It's just a challenge. not a requirement I wouldn't mind to find a way to incorporate a random game that would randomly pick one of the four math equations yea I can't figure that out either. It's a bit out of my depth. thank you bunches for your help! ❤️