private static MatrixField CreateMatrix(int[] dimestions) { int x = dimestions[0]; int y = dimestions[1]; MatrixField matrix = new MatrixField(x, y); return(matrix); }
private static bool ValidCell(int x, int y, MatrixField matrix) { if (x >= 0 && x < matrix.GetLengthX() && y >= 0 && y < matrix.GetLengthY()) { return(true); } return(false); }
private static void InitializeMatrix(MatrixField matrix) { int value = 0; for (int i = 0; i < matrix.GetLengthX(); i++) { for (int j = 0; j < matrix.GetLengthY(); j++) { matrix[i, j] = value++; } } }
static void Main() { int[] dimestions = ReadInput(Console.ReadLine()); MatrixField matrix = CreateMatrix(dimestions); InitializeMatrix(matrix); long sum = 0; string command = string.Empty; while ((command = Console.ReadLine()) != "Let the Force be with you") { int[] ivoS = ReadInput(command); Ivo ivo = CreateIvo(ivoS); int[] evilArgs = ReadInput(Console.ReadLine()); Evil evil = CreateEvil(evilArgs); while (evil.X >= 0 && evil.Y >= 0) { if (ValidCell(evil.X, evil.Y, matrix)) { matrix[evil.X, evil.Y] = 0; } evil.X--; evil.Y--; } while (ivo.X >= 0 && ivo.Y < matrix.GetLengthY()) { if (ValidCell(ivo.X, ivo.Y, matrix)) { sum += matrix[ivo.X, ivo.Y]; } ivo.X--; ivo.Y++; } } Console.WriteLine(sum); }