Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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++;
                }
            }
        }
Esempio n. 3
0
        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);
        }