mekasu0124

Untitled

Oct 17th, 2023
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace MeksMathGame.Services;
  5.  
  6. public class QuestionBuilder
  7. {
  8.     public static List<Question> BuildList(string diff, string gameType)
  9.     {
  10.         var questions = new List<Question>()
  11.         {
  12.             new Question() {
  13.                 NumOne = GetNumber(diff, gameType),
  14.                 NumTwo = GetNumber(diff, gameType),
  15.                 Operation = GetOperation(gameType)
  16.             }
  17.         };
  18.  
  19.         return questions;
  20.     }
  21.  
  22.     public static int GetNumber(string diff, string gameType)
  23.     {
  24.         if (gameType == "Addition" || gameType == "Subtraction")
  25.         {
  26.             return diff switch
  27.             {
  28.                 "Easy" => rng.Next(0, 300),
  29.                 "Medium" => rng.Next(0, 600),
  30.                 "Hard" => rng.Next(0, 900),
  31.                 _ => throw new Exception("Unable To Determine Difficulty")
  32.             };
  33.         }
  34.         else
  35.         {
  36.             return diff switch
  37.             {
  38.                 "Easy" => rng.Next(0, 100),
  39.                 "Medium" => rng.Next(0, 200),
  40.                 "Hard" => rng.Next(0, 300),
  41.                 _ => throw new Exception("Unable To Determine Difficulty")
  42.             };
  43.         }
  44.     }
  45.  
  46.     public static string? GetOperation(string gameType)
  47.     {
  48.         int rndIndex = rng.Next(0, _operationSymbols.Values);
  49.  
  50.         return gameType switch
  51.         {
  52.             "Addition" => _operationSymbols.Values[0],
  53.             "Subtraction" => _operationSymbols.Values[1],
  54.             "Multiplication" => _operationSymbols.Values[2],
  55.             "Division" => _operationSymbols.Values[3],
  56.             "Random" => _operationSymbols.Values[rndIndex],
  57.             _ => throw new Exception("Unable To Determine Operation")
  58.         };
  59.     }
  60. }
  61.  
  62. public enum Operation
  63. {
  64.     Addition,
  65.     Subtraction,
  66.     Multiplication,
  67.     Division
  68. }
  69.  
  70. public class Question
  71. {
  72.     public required decimal NumOne { get; init; }
  73.     public required decimal NumTwo { get; init; }
  74.     public required Operation Operation { get; init; }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment