-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cs
More file actions
110 lines (95 loc) · 3.58 KB
/
Game.cs
File metadata and controls
110 lines (95 loc) · 3.58 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
public class Game
{
public Field Field { get; } = new Field();
public List<Site> Sites { get; } = new List<Site>();
public Queen Queen {get;} = new Queen(Owner.Friendly, 0, 0, 100);
public bool IsTurn1 = true;
private int _numSites;
public Game()
{
SetupGame(out _numSites);
ReadGameLoop();
}
public void ResetField()
{
Field.Units.Clear();
}
public void ReadGameLoop()
{
var inputs = Console.ReadLine()!.Split(' ');
Queen.Gold = int.Parse(inputs[0]);
Queen.TouchedSite = int.Parse(inputs[1]); // -1 if none
for (int i = 0; i < _numSites; i++)
{
ReadSite();
}
int numUnits = int.Parse(Console.ReadLine()!);
for (int i = 0; i < numUnits; i++)
{
ReadUnit();
}
}
private void ReadUnit()
{
string[] inputs = Console.ReadLine()!.Split(' ');
int x = int.Parse(inputs[0]);
int y = int.Parse(inputs[1]);
int owner = int.Parse(inputs[2]); // 0 = Friendly, 1 = Enemy
int unitType = int.Parse(inputs[3]); // -1 = QUEEN, 0 = KNIGHT, 1 = ARCHER, 2 = Giant
int health = int.Parse(inputs[4]);
AddUnitsToField(owner, unitType, health, x, y);
}
private void ReadSite()
{
string[] inputs = Console.ReadLine()!.Split(' ');
int siteId = int.Parse(inputs[0]);
int gold = int.Parse(inputs[1]); // used in future leagues
int maxMineSize = int.Parse(inputs[2]); // used in future leagues
int structureType = int.Parse(inputs[3]); // -1 = No structure, 1 = TOWER, 2 = Barracks
int owner = int.Parse(inputs[4]); // -1 = No structure, 0 = Friendly, 1 = Enemy
int param1 = int.Parse(inputs[5]);//When barracks, the number of turns before a new set of creeps can be trained (if 0, then training may be started this turn)
int param2 = int.Parse(inputs[6]);//When barracks: the creep type: 0 for KNIGHT, 1 for ARCHER
Site site = GetSite(siteId);
site.UpdateSite(gold, maxMineSize, owner.ToOwner(), structureType, param1, param2);
}
private void AddUnitsToField(int owner, int unitType, int health, int x, int y)
{
if(unitType == UnitType.KNIGHT.ToInt())
{
Field.Units.Add(new Knight(owner.ToOwner(), x, y, health));
}
else if(unitType == UnitType.ARCHER.ToInt())
{
Field.Units.Add(new Archer(owner.ToOwner(), x, y, health));
}
else if (unitType == UnitType.GIANT.ToInt())
{
Field.Units.Add(new Giant(owner.ToOwner(), x, y, health));
}
else if(owner == Owner.Friendly.ToInt() && unitType == UnitType.QUEEN.ToInt())
{
Queen.UpdateQueen(x, y, health);
Field.Units.Add(Queen);
}
else if (owner == Owner.Enemy.ToInt() && unitType == UnitType.QUEEN.ToInt())
{
Field.Units.Add(new Queen(owner.ToOwner(), x, y, health));
}
}
private void SetupGame(out int numSites)
{
numSites = int.Parse(Console.ReadLine()!);
for (int i = 0; i < numSites; i++)
{
var inputs = Console.ReadLine()!.Split(' ');
int siteId = int.Parse(inputs[0]);
int x = int.Parse(inputs[1]);
int y = int.Parse(inputs[2]);
int radius = int.Parse(inputs[3]);
var site = new Site(siteId, x, y, radius);
Sites.Add(site);
Field.AddFieldItem(site, x, y);
}
}
private Site GetSite(int siteId) => Sites.First(s => s.SiteId == siteId);
}