Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace MeksMathGame.Services;
- public class QuestionBuilder
- {
- public static List<Question> BuildList(string diff, string gameType)
- {
- var questions = new List<Question>()
- {
- new Question() {
- NumOne = GetNumber(diff, gameType),
- NumTwo = GetNumber(diff, gameType),
- Operation = GetOperation(gameType)
- }
- };
- return questions;
- }
- public static int GetNumber(string diff, string gameType)
- {
- if (gameType == "Addition" || gameType == "Subtraction")
- {
- return diff switch
- {
- "Easy" => rng.Next(0, 300),
- "Medium" => rng.Next(0, 600),
- "Hard" => rng.Next(0, 900),
- _ => throw new Exception("Unable To Determine Difficulty")
- };
- }
- else
- {
- return diff switch
- {
- "Easy" => rng.Next(0, 100),
- "Medium" => rng.Next(0, 200),
- "Hard" => rng.Next(0, 300),
- _ => throw new Exception("Unable To Determine Difficulty")
- };
- }
- }
- public static string? GetOperation(string gameType)
- {
- int rndIndex = rng.Next(0, _operationSymbols.Values);
- return gameType switch
- {
- "Addition" => _operationSymbols.Values[0],
- "Subtraction" => _operationSymbols.Values[1],
- "Multiplication" => _operationSymbols.Values[2],
- "Division" => _operationSymbols.Values[3],
- "Random" => _operationSymbols.Values[rndIndex],
- _ => throw new Exception("Unable To Determine Operation")
- };
- }
- }
- public enum Operation
- {
- Addition,
- Subtraction,
- Multiplication,
- Division
- }
- public class Question
- {
- public required decimal NumOne { get; init; }
- public required decimal NumTwo { get; init; }
- public required Operation Operation { get; init; }
- }
Advertisement
Add Comment
Please, Sign In to add comment