|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using CellSimulator.Interfaces; |
| 7 | +using CellSimulator.Input; |
| 8 | +using CellSimulator.Enums; |
| 9 | + |
| 10 | +namespace CellSimulator.Logic |
| 11 | +{ |
| 12 | + public class SimulationManager : ISimulationManager |
| 13 | + { |
| 14 | + private readonly CellOverseer Overseer = new CellOverseer(); |
| 15 | + private readonly SaveLoadManager SaveLoadmanager = new SaveLoadManager(); |
| 16 | + private readonly ConsoleInputManager InputManager = new ConsoleInputManager(); |
| 17 | + |
| 18 | + public void StartSimulation() |
| 19 | + { |
| 20 | + SetInitialPopulation(); |
| 21 | + while (true) |
| 22 | + { |
| 23 | + switch (InputManager.GetUserAction()) |
| 24 | + { |
| 25 | + case UserActionEnum.LOAD: |
| 26 | + Overseer.CellList = (List<ICell>)SaveLoadmanager.LoadFromFile(InputManager.GetUserFileName()); |
| 27 | + break; |
| 28 | + case UserActionEnum.SAVE: |
| 29 | + SaveLoadmanager.SaveToFile(InputManager.GetUserFileName(), Overseer.CellList); |
| 30 | + break; |
| 31 | + case UserActionEnum.SWITCHSHOWINFO: |
| 32 | + break; |
| 33 | + case UserActionEnum.INVALID: |
| 34 | + Overseer.SimulateNext(); |
| 35 | + break; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + private void SetInitialPopulation() |
| 41 | + { |
| 42 | + int cellCount = GetStartingCellCount(); |
| 43 | + for(int i = 0; i < cellCount; ++i) |
| 44 | + { |
| 45 | + Overseer.AddCell(); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private int GetStartingCellCount() |
| 50 | + { |
| 51 | + int cellCount = -1; |
| 52 | + while (cellCount <= 0) |
| 53 | + { |
| 54 | + cellCount = InputManager.GetStartingCellCount(); |
| 55 | + } |
| 56 | + return cellCount; |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments