Skip to content

Commit c94da17

Browse files
committed
Added ISimulationManager and Implementation, Made CellList public on CellOverseer, Added new Methods to IUserActionManager and implemented them correctly
1 parent d2933a9 commit c94da17

6 files changed

Lines changed: 95 additions & 1 deletion

File tree

CellSimulator/CellSimulator.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
<Compile Include="Enums\UserActionEnum.cs" />
4949
<Compile Include="Input\ConsoleInputManager.cs" />
5050
<Compile Include="Interfaces\ICell.cs" />
51+
<Compile Include="Interfaces\ISimulationManager.cs" />
5152
<Compile Include="Interfaces\IUserActionManager.cs" />
5253
<Compile Include="Interfaces\ICellPrinter.cs" />
5354
<Compile Include="Interfaces\ICellOverseer.cs" />
5455
<Compile Include="Interfaces\ISaveLoadManager.cs" />
5556
<Compile Include="Logic\SaveLoadManager.cs" />
57+
<Compile Include="Logic\SimulationManager.cs" />
5658
<Compile Include="Models\Cell.cs" />
5759
<Compile Include="Logic\CellOverseer.cs" />
5860
<Compile Include="Output\ConsoleCellPrinter.cs" />

CellSimulator/Input/ConsoleInputManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ namespace CellSimulator.Input
1010
{
1111
public class ConsoleInputManager : IUserActionManager
1212
{
13+
public int GetStartingCellCount()
14+
{
15+
Console.Write("Enter Starting Cell Count: ");
16+
if (int.TryParse(Console.ReadLine(), out int result))
17+
{
18+
return result;
19+
}
20+
else
21+
{
22+
return -1;
23+
}
24+
}
25+
1326
public UserActionEnum GetUserAction()
1427
{
1528
Console.Write("Enter Action: ");
@@ -21,7 +34,12 @@ public UserActionEnum GetUserAction()
2134
{
2235
return UserActionEnum.INVALID;
2336
}
37+
}
2438

39+
public string GetUserFileName()
40+
{
41+
Console.Write("Enter FileName: ");
42+
return Console.ReadLine();
2543
}
2644
}
2745
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CellSimulator.Interfaces
8+
{
9+
public interface ISimulationManager
10+
{
11+
void StartSimulation();
12+
}
13+
}

CellSimulator/Interfaces/IUserActionManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ namespace CellSimulator.Interfaces
1010
public interface IUserActionManager
1111
{
1212
UserActionEnum GetUserAction();
13+
int GetStartingCellCount();
14+
string GetUserFileName();
1315
}
1416
}

CellSimulator/Logic/CellOverseer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace CellSimulator.Logic
1010
{
1111
public class CellOverseer : ICellOverseer
1212
{
13-
public List<ICell> CellList { get; private set; } = new List<ICell>();
13+
public List<ICell> CellList { get; set; } = new List<ICell>();
1414
private int internalIdCounter = 0;
1515

1616
private Random rand = new Random();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)