-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.cs
70 lines (63 loc) · 2.26 KB
/
Runner.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace Gustav
{
using System;
using System.IO;
using Gustav.MainLogic;
using Gustav.Properties;
using Gustav.Storage;
internal class Runner
{
private readonly CombatParametersStorage storage;
private readonly RateDeterminationLogic rateDeterminationLogic;
private readonly EnemyDataStorage enemyDataStorage;
private readonly ModeSelector modeSelector;
private readonly XmlSerialization serialization;
public Runner(CombatParametersStorage storage, RateDeterminationLogic rateDeterminationLogic, EnemyDataStorage enemyDataStorage, ModeSelector modeSelector, XmlSerialization serialization)
{
this.storage = storage;
this.rateDeterminationLogic = rateDeterminationLogic;
this.enemyDataStorage = enemyDataStorage;
this.modeSelector = modeSelector;
this.serialization = serialization;
}
public void Run(Loyalist loyalist)
{
Init(loyalist);
while (loyalist.Energy > 0)
{
Rates rate = null;
try
{
rate = rateDeterminationLogic.DetermineRates();
}
catch (Exception)
{
break;
}
loyalist.VelocityRate = rate.Velocity;
loyalist.TurnRate = rate.BodyTurn;
loyalist.GunRotationRate = rate.TurretTurn;
loyalist.RadarRotationRate = rate.RadarTurn;
if (rate.BulletPower > 0)
{
loyalist.SetFire(rate.BulletPower);
}
if (storage.CombatEnded)
{
break;
}
loyalist.Execute();
}
}
private void Init(Loyalist loyalist)
{
loyalist.GunColor = Settings.Default.GunColor;
loyalist.RadarColor = Settings.Default.RadarColor;
loyalist.BodyColor = Settings.Default.BodyColor;
loyalist.BulletColor = Settings.Default.BulletColor;
storage.Robot = loyalist;
enemyDataStorage.Clear();
modeSelector.SelectMode(CombatMode.Scan);
}
}
}