public void Update(string gameMapStr)
{
var gameMapValues = new Queue<string>(gameMapStr.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries));
ushort x = 0, y = 0;
while (y < Height) {
ushort counter, owner;
if (!ushort.TryParse(gameMapValues.Dequeue(), out counter))
throw new ApplicationException("Could not get some counter from stdin");
if (!ushort.TryParse(gameMapValues.Dequeue(), out owner))
throw new ApplicationException("Could not get some owner from stdin");
while (counter > 0) {
_sites[x, y] = new Site {Owner = owner};
x++;
if (x == Width) {
x = 0;
y++;
}
counter--;
}
}
var strengthValues = gameMapValues; // Referencing same queue, but using a name that is more clear
for (x = 0; x < Width; x++) {
for (y = 0; y < Height; y++) {
ushort strength;
if (!ushort.TryParse(strengthValues.Dequeue(), out strength))
throw new ApplicationException("Could not get some strength value from stdin");
_sites[x, y].Strength = strength;
}
}
}