forked from the-csharp-academy/CodeReviews.Console.MathGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionGenerator.cs
More file actions
33 lines (29 loc) · 1.07 KB
/
Copy pathQuestionGenerator.cs
File metadata and controls
33 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class QuestionGenerator
{
private GameHistory _questionHistory;
public QuestionGenerator(GameHistory questionHistory)
{
_questionHistory = questionHistory;
}
private static readonly Dictionary<Operation, Func<BaseOperation>> operation = new Dictionary<Operation, Func<BaseOperation>>()
{
[Operation.Addition] = () => new AdditionOperation(),
[Operation.Subtraction] = () => new SubtractionOperation(),
[Operation.Multiplication] = () => new MultiplicationOperation(),
[Operation.Division] = () => new DivisionOperation(),
};
public List<BaseOperation> GenerateQuestions(Operation chosenOp)
{
if (!operation.TryGetValue(chosenOp, out var createOperation))
{
throw new Exception("specified function is not there");
}
List<BaseOperation> questions = new List<BaseOperation>();
for (int i = 0; i < 5; i++)
{
questions.Add(createOperation());
}
_questionHistory.SaveQuestions(questions);
return questions;
}
}