public void BeginAct() { if (IsDialogueActivated) { return; } Actions.Clear(); for (var x = 0; x < CurrentLevel.Width; x++) { for (var y = 0; y < CurrentLevel.Height; y++) { var creatures = CurrentLevel.GetCreatures(x, y).ToArray(); if (creatures == null) { continue; } for (int i = 0; i < creatures.Length; i++) { if (creatures[i] == null) { continue; } var command = creatures[i].Act(CurrentLevel, x, y); if (x + command.DeltaX < 0 || x + command.DeltaX >= CurrentLevel.Width || y + command.DeltaY < 0 || y + command.DeltaY >= CurrentLevel.Height) { throw new Exception($"The object {creatures[i].GetType()} falls out of the game field"); } Actions.Add( new CreatureAction { Command = command, Creature = creatures[i], Location = new Point(x, y), TargetLogicalLocation = new Point(x + command.DeltaX, y + command.DeltaY) }); creatures = CurrentLevel.GetCreatures(x, y).ToArray(); } } } }