Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Warheads
- {
- class Program
- {
- static int[,] circuit = new int[16, 16];
- static void Main()
- {
- ReadInput();
- ReadCommands();
- }
- private static void ReadCommands()
- {
- string status = "intact";
- while (status == "intact")
- {
- string command = Console.ReadLine();
- switch (command)
- {
- case "hover":
- {
- int line = int.Parse(Console.ReadLine());
- int col = int.Parse(Console.ReadLine());
- Console.WriteLine(CellStatus(line, col));
- break;
- }
- case "operate":
- {
- int line = int.Parse(Console.ReadLine());
- int col = int.Parse(Console.ReadLine());
- if (circuit[line, col] == 1)
- {
- Console.WriteLine("missed");
- Console.WriteLine(GetShapes("blue") + GetShapes("red"));
- Console.WriteLine("BOOM");
- status = "done";
- }
- else if (IsFigure(line, col))
- {
- RemoveFigure(line, col);
- }
- break;
- }
- case "cut":
- {
- string section = Console.ReadLine();
- int sectionFigures = GetShapes(section);
- if (sectionFigures > 0)
- {
- Console.WriteLine(sectionFigures);
- Console.WriteLine("BOOM");
- }
- else
- {
- string otherSection;
- if (section == "red")
- {
- otherSection = "blue";
- }
- else
- {
- otherSection = "red";
- }
- Console.WriteLine(GetShapes(otherSection));
- Console.WriteLine("disarmed");
- }
- status = "done";
- break;
- }
- default:
- break;
- }
- }
- }
- private static int GetShapes(string sector)
- {
- int startCol;
- int endCol;
- if (sector == "red")
- {
- startCol = 1;
- endCol = 7;
- }
- else
- {
- startCol = 8;
- endCol = 14;
- }
- int figureCount = 0;
- for (int i = 1; i < 15; i++)
- {
- for (int p = startCol; p <= endCol; p++)
- {
- if (IsFigure(i, p))
- {
- figureCount++;
- }
- }
- }
- return figureCount;
- }
- private static void RemoveFigure(int line, int col)
- {
- for (int i = line - 1; i <= line + 1; i++)
- {
- for (int p = col - 1; p <= col + 1; p++)
- {
- circuit[i, p] = 0;
- }
- }
- }
- private static string CellStatus(int line, int col)
- {
- if (circuit[line, col] == 1)
- {
- return "*";
- }
- else
- {
- return "-";
- }
- }
- private static bool IsFigure(int line, int col)
- {
- if (line == 0 || line == 15 || col == 0 || col == 15)
- {
- return false;
- }
- bool isFigure = circuit[line, col] == 0 &&
- circuit[line - 1, col] == 1 &&
- circuit[line - 1, col + 1] == 1 &&
- circuit[line, col + 1] == 1 &&
- circuit[line + 1, col + 1] == 1 &&
- circuit[line + 1, col] == 1 &&
- circuit[line + 1, col - 1] == 1 &&
- circuit[line, col - 1] == 1 &&
- circuit[line - 1, col - 1] == 1;
- return isFigure;
- }
- private static void ReadInput()
- {
- for (int line = 0; line < 16; line++)
- {
- char[] cells = Console.ReadLine().ToCharArray();
- for (int col = 0; col < 16; col++)
- {
- circuit[line, col] = int.Parse(cells[col].ToString());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement