Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp20
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n,n];
- int minerRow = -1;
- int minerCol = -1;
- int coalCount = 0;
- int collectedCoal = 0;
- int endRow = -1;
- int endCol = -1;
- bool progHasEnded = false;
- string[] directions = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
- //ПРОБЛЕМ!
- //colVals ReadLine-a чете и празните места и не взима цялата матрица
- //////////////////////////////////////////////////////
- for (int row = 0; row < n; row++)
- {
- char[] colVals = Console.ReadLine().ToCharArray();
- for (int col = 0; col < n; col++)
- {
- matrix[row, col] = colVals[col];
- ///////////////////////////////////////////////////////
- if (colVals[col] == 's')
- {
- minerRow = row;
- minerCol = col;
- }
- if (colVals[col] == 'c')
- {
- coalCount++;
- }
- if (colVals[col] == 'e')
- {
- endRow = row;
- endCol = col;
- }
- }
- }
- //Цикъл за изписване на матрицата при проверки
- //for (int row = 0; row < n; row++)
- //{
- // for (int col = 0; col < n; col++)
- // {
- // Console.Write(matrix[row, col]);
- // }
- // Console.WriteLine();
- //}
- foreach (string direction in directions)
- {
- int currMnRow = minerRow;
- int currMnCol = minerCol;
- switch (direction)
- {
- case "up":
- if (!(currMnRow - 1 < 0))
- {
- currMnRow--;
- }
- break;
- case "down":
- if (!(currMnRow + 1 >= n))
- {
- currMnRow++;
- }
- break;
- case "left":
- if (!(currMnCol - 1 < 0))
- {
- currMnCol--;
- }
- break;
- case "right":
- if (!(currMnCol + 1 >= n))
- {
- currMnCol++;
- }
- break;
- }
- if (matrix[currMnRow, currMnCol] == 'c')
- {
- matrix[minerRow, minerCol] = '*';
- matrix[currMnRow, currMnCol] = 's';
- coalCount--;
- collectedCoal++;
- minerRow = currMnRow;
- minerCol = currMnCol;
- if (coalCount == 0)
- {
- Console.WriteLine($"You collected all coals! ({minerRow}, {minerCol})");
- progHasEnded = true;
- break;
- }
- }
- else if (matrix[currMnRow, currMnCol] == 'e')
- {
- matrix[minerRow, minerCol] = '*';
- minerRow = currMnRow;
- minerCol = currMnCol;
- Console.WriteLine($"Game over! ({endRow}, {endCol})");
- progHasEnded = true;
- break;
- }
- }
- if (!progHasEnded)
- {
- Console.WriteLine($"{coalCount - collectedCoal} coals left. ({minerRow}, {minerCol})");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement