Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace MeksMathGame
- {
- class Program
- {
- static void EndGame()
- {
- Console.WriteLine("You've Answered All The Questions! Would You Like To Play Again? Y/N");
- string userOption = Console.ReadLine();
- if (userOption.ToLower() == "y")
- {
- Console.WriteLine("You Selected To Play Again. Re-Launching Application!\n");
- Thread.Sleep(3000);
- DifficultySelection();
- }
- else
- {
- Console.WriteLine("You Selected To Not Play Again. Closing Application!\n");
- Thread.Sleep(3000);
- }
- }
- static void CheckSolution(int num1, string operation, int num2, int userSolution, string gameType, string difficulty, int numOfQuestions)
- {
- switch (operation)
- {
- case "+":
- if (userSolution == (num1 + num2))
- {
- Console.WriteLine("Great Job! Next Question!\n");
- Thread.Sleep(3000);
- numOfQuestions--;
- if (numOfQuestions == 0)
- {
- EndGame();
- }
- else
- {
- StartGame(gameType, difficulty, numOfQuestions);
- };
- }
- else
- {
- Console.WriteLine("Incorrect Answer! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- };
- break;
- case "-":
- if (userSolution == (num1 - num2) | userSolution == (num2 - num1))
- {
- Console.WriteLine("Great Job! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- }
- else
- {
- Console.WriteLine("Incorrect Answer! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- };
- break;
- case "*":
- if (userSolution == (num1*num2))
- {
- Console.WriteLine("Great Job! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- }
- else
- {
- Console.WriteLine("Incorrect Answer! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- }
- break;
- case "/":
- // if the users solution is equal to the solution as an integer or a double, then it's correct
- // this needs to be tweaked along with lines 323-400
- if (userSolution == (num2/num1) | userSolution == (num2/num1))
- {
- Console.WriteLine("Great Job! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- }
- else
- {
- Console.WriteLine("Incorrect Answer! Next Question!\n");
- Thread.Sleep(3000);
- StartGame(gameType, difficulty, numOfQuestions - 1);
- }
- break;
- default:
- Console.WriteLine("Invalid Operation On Checking Solution. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- }
- }
- static void StartGame(string gameType, string difficulty, int numberOfQuestions)
- {
- Console.WriteLine("Game: " + gameType + "\nMode: " + difficulty.ToUpper());
- switch (gameType)
- {
- case "addition":
- switch (difficulty)
- {
- case "easy":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenEasyAdd = new Random();
- int num1Eadd = numberGenEasyAdd.Next(0, 601);
- int num2Eadd = numberGenEasyAdd.Next(0, 601);
- Console.WriteLine("What Is The Summation Of: " + num1Eadd + " + " + num2Eadd);
- int userSolutionEadd = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Eadd, "+", num2Eadd, userSolutionEadd, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "medium":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMediumAdd = new Random();
- int num1Madd = numberGenMediumAdd.Next(600, 1201);
- int num2Madd = numberGenMediumAdd.Next(600, 1201);
- Console.WriteLine("What Is The Summation Of: " + num1Madd + " + " + num2Madd);
- int userSolutionMadd = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Madd, "+", num2Madd, userSolutionMadd, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "hard":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenHardAdd = new Random();
- int num1Hadd = numberGenHardAdd.Next(1200, 1801);
- int num2Hadd = numberGenHardAdd.Next(1200, 1801);
- Console.WriteLine("What Is The Summation Of: " + num1Hadd + " + " + num2Hadd);
- int userSolutionHadd = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Hadd, "+", num2Hadd, userSolutionHadd, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "expert":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenExpertAdd = new Random();
- int num1ExAdd = numberGenExpertAdd.Next(1800, 2401);
- int num2ExAdd = numberGenExpertAdd.Next(1800, 2401);
- Console.WriteLine("What Is The Summation Of: " + num1ExAdd + " + " + num2ExAdd);
- int userSolutionExAdd = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1ExAdd, "+", num2ExAdd, userSolutionExAdd, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "master":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMaAdd = new Random();
- int num1MaAdd = numberGenMaAdd.Next(2400, 3001);
- int num2MaAdd = numberGenMaAdd.Next(2400, 3001);
- Console.WriteLine("What Is The Summation Of: " + num1MaAdd + " + " + num2MaAdd);
- int userSolutionMaAdd = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1MaAdd, "+", num2MaAdd, userSolutionMaAdd, gameType, difficulty, numberOfQuestions);
- };
- break;
- default:
- Console.WriteLine("Invalid Operation On Addition Game. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- };
- break;
- case "subtraction":
- switch (difficulty)
- {
- case "easy":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenEsub = new Random();
- int num1Esub = numberGenEsub.Next(0, 601);
- int num2Esub = numberGenEsub.Next(0, 601);
- Console.WriteLine("What Is The Difference Between: " + num1Esub + " - " + num2Esub);
- int userSolutionEsub = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Esub, "-", num2Esub, userSolutionEsub, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "medium":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMsub = new Random();
- int num1Msub = numberGenMsub.Next(600, 1201);
- int num2Msub = numberGenMsub.Next(600, 1201);
- Console.WriteLine("What is The Difference Between: " + num1Msub + " - " + num2Msub);
- int userSolutionMsub = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Msub, "-", num2Msub, userSolutionMsub, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "hard":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenHsub = new Random();
- int num1Hsub = numberGenHsub.Next(1200, 1801);
- int num2Hsub = numberGenHsub.Next(1200, 1801);
- Console.WriteLine("What Is The Difference Between: " + num1Hsub + " - " + num2Hsub);
- int userSolutionHsub = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Hsub, "-", num2Hsub, userSolutionHsub, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "expert":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenExSub = new Random();
- int num1ExSub = numberGenExSub.Next(1800, 2401);
- int num2ExSub = numberGenExSub.Next(1800, 2401);
- Console.WriteLine("What Is The Difference Between: " + num1ExSub + " - " + num2ExSub);
- int userSolutionExSub = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1ExSub, "-", num2ExSub, userSolutionExSub, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "master":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMaSub = new Random();
- int num1MaSub = numberGenMaSub.Next(2400, 3001);
- int num2MaSub = numberGenMaSub.Next(2400, 3001);
- Console.WriteLine("What Is The Difference Between: " + num1MaSub + " - " + num2MaSub);
- int userSolutionMaSub = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1MaSub, "-", num2MaSub, userSolutionMaSub, gameType, difficulty, numberOfQuestions);
- };
- break;
- default:
- Console.WriteLine("Invalid Operation In Subtraction Game. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- };
- break;
- case "multiplication":
- switch (difficulty)
- {
- case "easy":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenEmul = new Random();
- int num1Emul = numberGenEmul.Next(0, 601);
- int num2Emul = numberGenEmul.Next(0, 601);
- Console.WriteLine("What Is The Product Of: " + num1Emul + " * " + num2Emul);
- int userSolutionEmul = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Emul, "*", num2Emul, userSolutionEmul, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "medium":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMmul = new Random();
- int num1Mmul = numberGenMmul.Next(600, 1201);
- int num2Mmul = numberGenMmul.Next(600, 1201);
- Console.WriteLine("What Is The Product Of: " + num1Mmul + " * " + num2Mmul);
- int userSolutionMmul = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Mmul, "*", num2Mmul, userSolutionMmul, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "hard":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenHmul = new Random();
- int num1Hmul = numberGenHmul.Next(1200, 1801);
- int num2Hmul = numberGenHmul.Next(1200, 1801);
- Console.WriteLine("What Is The Product Of: " + num1Hmul + " * " + num2Hmul);
- int userSolutionHmul = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Hmul, "*", num2Hmul, userSolutionHmul, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "expert":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenExMul = new Random();
- int num1ExMul = numberGenExMul.Next(1800, 2401);
- int num2ExMul = numberGenExMul.Next(1800, 2401);
- Console.WriteLine("What Is The Product Of: " + num1ExMul + " * " + num2ExMul);
- int userSolutionExMul = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1ExMul, "*", num2ExMul, userSolutionExMul, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "master":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMaMul = new Random();
- int num1MaMul = numberGenMaMul.Next(2400, 3001);
- int num2MaMul = numberGenMaMul.Next(2400, 3001);
- Console.WriteLine("What Is The Product Of: " + num1MaMul + " * " + num2MaMul);
- int userSolutionMaMul = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1MaMul, "*", num2MaMul, userSolutionMaMul, gameType, difficulty, numberOfQuestions);
- };
- break;
- default:
- Console.WriteLine("Invalid Operation In Multiplication Game. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- };
- break;
- /*
- this section needs to be tweaked to match doubles as sometimes there are smaller
- numbers divided by bigger numbers like 24 / 156 which would be a double or float
- and the same tweaks need to occur in the CheckSolution() method to be able to check
- the users solution appropriately
- */
- case "division":
- switch (difficulty)
- {
- case "easy":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenEdiv = new Random();
- int num1Ediv = numberGenEdiv.Next(0, 601);
- int num2Ediv = numberGenEdiv.Next(0, 601);
- Console.WriteLine("What Is The Product Of: " + num2Ediv + " / " + num1Ediv);
- int userSolutionEdiv = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Ediv, "*", num2Ediv, userSolutionEdiv, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "medium":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMdiv = new Random();
- int num1Mdiv = numberGenMdiv.Next(600, 1201);
- int num2Mdiv = numberGenMdiv.Next(600, 1201);
- Console.WriteLine("What Is The Quotient Of: " + num2Mdiv + " / " + num1Mdiv);
- int userSolutionMdiv = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Mdiv, "/", num2Mdiv, userSolutionMdiv, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "hard":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenHdiv = new Random();
- int num1Hdiv = numberGenHdiv.Next(1200, 1801);
- int num2Hdiv = numberGenHdiv.Next(1200, 1801);
- Console.WriteLine("What Is The Quotient Of: " + num2Hdiv + " / " + num1Hdiv);
- int userSolutionHdiv = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1Hdiv, "/", num2Hdiv, userSolutionHdiv, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "expert":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenExDiv = new Random();
- int num1ExDiv = numberGenExDiv.Next(1800, 2401);
- int num2ExDiv = numberGenExDiv.Next(1800, 2401);
- Console.WriteLine("What Is The Quotient Of: " + num2ExDiv + " / " + num1ExDiv);
- int userSolutionExDiv = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1ExDiv, "/", num2ExDiv, userSolutionExDiv, gameType, difficulty, numberOfQuestions);
- };
- break;
- case "master":
- for (int i = 1; i < numberOfQuestions; i++)
- {
- Random numberGenMaDiv = new Random();
- int num1MaDiv = numberGenMaDiv.Next(2400, 3001);
- int num2MaDiv = numberGenMaDiv.Next(2400, 3001);
- Console.WriteLine("What Is The Quotient Of: " + num2MaDiv, " / " + num1MaDiv);
- int userSolutionMaDiv = Convert.ToInt32(Console.ReadLine());
- CheckSolution(num1MaDiv, "/", num2MaDiv, userSolutionMaDiv, gameType, difficulty, numberOfQuestions);
- };
- break;
- default:
- Console.WriteLine("Invalid Operation In Division Game. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- };
- break;
- default:
- Console.WriteLine("Invalid Operation In Launching Game. Re-Running Program!\n");
- Thread.Sleep(6000);
- DifficultySelection();
- break;
- };
- }
- // select the game to play
- static void GameSelection(string difficulty)
- {
- Console.WriteLine("Please Select Which Game To Play");
- List<string> gameTypes = new()
- {
- "Addition",
- "Subtraction",
- "Multiplication",
- "Division"
- };
- for (int i = 0; i < gameTypes.Count; i++)
- {
- Console.WriteLine(i + 1 + ") " + gameTypes[i]);
- };
- int gameSelection = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("How Many Questions Would You Like To Answer? ");
- int numberOfQuestions = Convert.ToInt32(Console.ReadLine());
- switch (gameSelection)
- {
- case 1:
- Console.WriteLine("\nLaunching: " + gameTypes[gameSelection - 1] + "\nMode: " + difficulty.ToUpper() + "\nNumber Of Questions: " + numberOfQuestions);
- Thread.Sleep(5000);
- StartGame(gameTypes[gameSelection-1].ToLower(), difficulty.ToLower(), numberOfQuestions);
- break;
- case 2:
- Console.WriteLine("\nLaunching: " + gameTypes[gameSelection - 1] + "\nMode: " + difficulty.ToUpper() + "\nNumber Of Questions: " + numberOfQuestions);
- Thread.Sleep(5000);
- StartGame(gameTypes[gameSelection-1].ToLower(), difficulty.ToLower(), numberOfQuestions);
- break;
- case 3:
- Console.WriteLine("\nLaunching: " + gameTypes[gameSelection - 1] + "\nMode: " + difficulty.ToUpper() + "\nNumber Of Questions: " + numberOfQuestions);
- Thread.Sleep(5000);
- StartGame(gameTypes[gameSelection-1].ToLower(), difficulty.ToLower(), numberOfQuestions);
- break;
- case 4:
- Console.WriteLine("\nLaunching: " + gameTypes[gameSelection - 1] + "\nMode: " + difficulty.ToUpper() + "\nNumber Of Questions: " + numberOfQuestions);
- Thread.Sleep(5000);
- StartGame(gameTypes[gameSelection-1].ToLower(), difficulty.ToLower(), numberOfQuestions);
- break;
- default:
- Console.WriteLine("Invalid Operation Starting Game. Try Again!\n");
- GameSelection("undefined");
- break;
- };
- }
- // select difficulty type
- static void DifficultySelection()
- {
- List<string> difficulties = new List<string>
- {
- "Easy",
- "Medium",
- "Hard",
- "Expert",
- "Master"
- };
- Console.WriteLine("Please Select A Game Difficulty");
- for (int i = 0; i < difficulties.Count; i++)
- {
- Console.WriteLine(i+1 + ") " + difficulties[i]);
- };
- int difficultySelection = Convert.ToInt32(Console.ReadLine());
- switch (difficultySelection)
- {
- case 1:
- Console.WriteLine("Easy Mode Selected\n");
- GameSelection("easy");
- break;
- case 2:
- Console.WriteLine("Medium Mode Selected\n");
- GameSelection("medium");
- break;
- case 3:
- Console.WriteLine("Hard Mode Selected\n");
- GameSelection("hard");
- break;
- case 4:
- Console.WriteLine("Expert Mode Selected\n");
- GameSelection("expert");
- break;
- case 5:
- Console.WriteLine("Master Mode Selected\n");
- GameSelection("master");
- break;
- default:
- Console.WriteLine("Invalid Operation Selecting Difficulty. Try Again!\n");
- DifficultySelection();
- break;
- };
- }
- // start the program with the welcome message
- static void Main(string[] args)
- {
- Console.WriteLine("Welcome To Mek's Math Game!\n");
- Thread.Sleep(600);
- Console.WriteLine(
- "This is meant to be a learning game for your enjoyment. All recorded games are erased once" +
- " the program has been closed. In future updates, we do plan to add in the ability of saving" +
- " previous games so that they're always available to the user. If you have any ideas that you" +
- " would like to add to the game, or would like to see implimented, please send an email to" +
- " [email protected] with the subject of Mek's Math Game - Suggestions\n"
- );
- Thread.Sleep(1200);
- DifficultySelection();
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement