private static void MoveIvo(Ivo ivo, int[,] matrix) { while (ivo.Row >= 0) { if (ivo.Row < matrix.GetLength(0) && ivo.Col >= 0 && ivo.Col < matrix.GetLength(1)) { ivo.CollectPoints(matrix[ivo.Row, ivo.Col]); } ivo.UpdateCoordinates(ivo.Row - 1, ivo.Col + 1); } }
private static void UpdateCoordinates(string command, Ivo ivo, Evil evil) { var ivoCoordinates = command .Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); ivo.UpdateCoordinates(ivoCoordinates[0], ivoCoordinates[1]); command = Console.ReadLine(); var evilCoordinates = command .Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); evil.UpdateCoordinates(evilCoordinates[0], evilCoordinates[1]); }
static void Main(string[] args) { short[] sizes = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(short.Parse).ToArray(); int[,] matrix = InitializeMatrix(sizes); Ivo ivo = new Ivo(); Evil evil = new Evil(); string command; while ((command = Console.ReadLine()) != "Let the Force be with you") { UpdateCoordinates(command, ivo, evil); MoveEvil(evil, matrix); MoveIvo(ivo, matrix); } Console.WriteLine(ivo.Score); }