using System.Collections.Generic;
public static class SlotMachineBuilder
public static SlotHandle.SlotMachine BuildDefaultSlotMachine()
var defaultValues = new List<string> { "Cherry", "Rasberry", "Grape" };
var wheels = new List<SlotHandle.SlotWheel> { new SlotHandle.SlotWheel { Values = defaultValues, CurrentValue = null }, new SlotHandle.SlotWheel { Values = defaultValues, CurrentValue = null }, new SlotHandle.SlotWheel { Values = defaultValues, CurrentValue = null } };
var random = new RandomProvider();
var slotHandle = new SlotHandle(random);
var slotMachine = new SlotHandle.SlotMachine(wheels: wheels, slotHandle: slotHandle);
public static void Main()
Console.WriteLine("Welcome to an object oriented Slot Machine!");
var slotMachine = SlotMachineBuilder.BuildDefaultSlotMachine();
Console.Write("Spin? (y|n):");
var spinAnwswer = Console.ReadLine();
if (spinAnwswer.ToLower().StartsWith("y"))
var result = slotMachine.SlotHandle.Pull(slotMachine.Wheels);
foreach (var w in slotMachine.Wheels)
Console.WriteLine(w.CurrentValue);
Console.WriteLine(result.IsWinner ? "You won!!!!!!!!!" : "Sorry, you lost.");
Console.Write("Continue?: (y|n):");
if (!Console.ReadLine().ToLower().StartsWith("y"))
static void SuspenceDots(int quantity, int speedMillisends = 50)
for (int i = 1; i <= quantity; i++)
Thread.Sleep(speedMillisends);
public class HandlePullResult
public bool IsWinner { get; set; }
public interface IRandomProvider
int Random(int inclusiveMin, int inclusiveMax);
public class RandomProvider : IRandomProvider
private readonly Random random;
this.random = new Random();
public int Random(int inclusiveMin, int inclusiveMax)
var result = this.random.Next(minValue: inclusiveMin, maxValue: inclusiveMax + 1);
private readonly IRandomProvider randomProvider;
public SlotHandle(IRandomProvider randomProvider)
if (randomProvider == null)
throw new ArgumentNullException(nameof(randomProvider));
this.randomProvider = randomProvider;
public HandlePullResult Pull(List<SlotWheel> wheels)
var result = new HandlePullResult { IsWinner = false };
foreach (var wheel in wheels)
wheel.CurrentValue = this.SelectRandom(wheel.Values);
result.IsWinner = wheels.Select(w => w.CurrentValue).Distinct().Count() == 1;
public string SelectRandom(List<string> values)
throw new ArgumentNullException(nameof(values));
var maxIndex = values.Count - 1;
var randomIndex = this.randomProvider.Random(inclusiveMin: 0, inclusiveMax: maxIndex);
var result = values[randomIndex];
public SlotMachine(List<SlotWheel> wheels, SlotHandle slotHandle)
throw new ArgumentNullException(nameof(wheels));
throw new ArgumentNullException(nameof(slotHandle));
throw new Exception($"There must me a minmum of 3 values per Slot Wheel. {wheels.Count} were given.");
this.SlotHandle = slotHandle;
public List<SlotWheel> Wheels { get; private set; }
public SlotHandle SlotHandle { get; private set; }
public string CurrentValue { get; set; }
public List<string> Values { get; set; }