Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TargetPractice
- {
- using System;
- using System.Linq;
- public class TargetPractice
- {
- public static void Main()
- {
- int[] matrixDimentions = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int numberOfRows = matrixDimentions[0];
- int numberOfColumns = matrixDimentions[1];
- char[,] matrix = new char[numberOfRows, numberOfColumns];
- string snake = Console.ReadLine();
- int[] shotsImpactRowColumnRadius = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int impactRow = shotsImpactRowColumnRadius[0];
- int impactColumn = shotsImpactRowColumnRadius[1];
- int impactRadius = shotsImpactRowColumnRadius[2];
- FillMatrix(numberOfRows, numberOfColumns, snake, matrix);
- FireAShot(matrix, impactRow, impactColumn, impactRadius);
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- RunGravity(matrix, col);
- }
- PrintMatrix(matrix);
- }
- private static void RunGravity(char[,] matrix, int col)
- {
- while (true)
- {
- bool hasFallen = false;
- for (int row = 1; row < matrix.GetLength(0); row++)
- {
- char topChar = matrix[row - 1, col];
- char currentChar = matrix[row, col];
- if (currentChar == ' ' && topChar != ' ')
- {
- matrix[row, col] = topChar;
- matrix[row - 1, col] = ' ';
- hasFallen = true;
- }
- }
- if (!hasFallen)
- {
- break;
- }
- }
- }
- private static void FireAShot(char[,] matrix, int impactRow, int impactColumn, int impactRadius)
- {
- //(x - center_x)^2 + (y - center_y)^2 <= radius^2
- //x - columns, y-rows
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int column = 0; column < matrix.GetLength(1); column++)
- {
- if ((column - impactColumn) * (column - impactColumn)
- + (row - impactRow) * (row - impactRow)
- <= impactRadius * impactRadius)
- {
- matrix[row, column] = ' ';
- }
- }
- }
- }
- private static void PrintMatrix(char[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int column = 0; column < matrix.GetLength(1); column++)
- {
- Console.Write(matrix[row, column]);
- }
- Console.WriteLine();
- }
- }
- private static void FillMatrix(int numberOfRows, int numberOfColumns, string snake, char[,] matrix)
- {
- bool isMovingLeft = true;
- int currentIndex = 0;
- for (int row = numberOfRows - 1; row >= 0; row--)
- {
- if (isMovingLeft)
- {
- for (int col = numberOfColumns - 1; col >= 0; col--)
- {
- if (currentIndex >= snake.Length)
- {
- currentIndex = 0;
- }
- matrix[row, col] = snake[currentIndex];
- currentIndex++;
- }
- }
- else
- {
- for (int col = 0; col < numberOfColumns; col++)
- {
- if (currentIndex >= snake.Length)
- {
- currentIndex = 0;
- }
- matrix[row, col] = snake[currentIndex];
- currentIndex++;
- }
- }
- isMovingLeft = !isMovingLeft;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment