-
Notifications
You must be signed in to change notification settings - Fork 0
/
Choice.cs
56 lines (51 loc) · 1.46 KB
/
Choice.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Generator
{
public class Choice : IGenerate, IPluralize
{
private List<IGenerate> _items { get; set; }
public Choice(List<IGenerate> words)
{
_items = words;
}
public string Generate()
{
int i = RandomizerFactory.Random.GetNext(_items.Count);
string s = _items[i].Generate();
return s;
}
public string Pluralize()
{
bool canPluralize = false;
foreach (IGenerate item in _items)
{
if (item is IPluralize)
{
canPluralize = true;
break;
}
}
if (!canPluralize)
{
throw new NotImplementedException();
}
IGenerate chosenItem = null;
do
{
int i = RandomizerFactory.Random.GetNext(_items.Count);
chosenItem = _items[i];
} while (!(chosenItem is IPluralize));
string s = (chosenItem as IPluralize).Pluralize();
return s;
}
public static Choice operator +(Choice a, Choice b)
{
List<IGenerate> newlist = new List<IGenerate>(a._items.Concat(b._items));
return new Choice(newlist);
}
}
}