Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace Miner_Advanced_14Octobr2018
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- char[,] field = new char[size, size];
- var directions = Console.ReadLine();
- Queue<string> commands = new Queue<string>(directions.Split(" ", StringSplitOptions.RemoveEmptyEntries));
- int countCoals = 0;
- int collectedCoals = 0;
- int minerRow = 0;
- int minerCol = 0;
- for (int row = 0; row < field.GetLength(0); row++)
- {
- var currentRow = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries);
- for (int col = 0; col < field.GetLength(1); col++)
- {
- field[row, col] = char.Parse(currentRow[col]);
- if (field[row, col] == 's')
- {
- minerRow = row;
- minerCol = col;
- }
- else if (field[row,col] == 'c')
- {
- countCoals++;
- }
- }
- }
- while (true)
- {
- if (!commands.Any())
- {
- break;
- }
- if (countCoals == collectedCoals)
- {
- break;
- }
- var com = commands.Peek();
- if (com == "up")
- {
- if (minerRow - 1 >= 0)
- {
- minerRow--;
- char symbol = field[minerRow, minerCol];
- if (symbol == 'e')
- {
- Console.WriteLine($"Game over! ({minerRow}, {minerCol})");
- break;
- }
- else if (symbol == 'c')
- {
- collectedCoals++;
- field[minerRow + 1, minerCol] = '*';
- field[minerRow, minerCol] = 's';
- }
- else if (symbol == '*')
- {
- commands.Dequeue();
- continue;
- }
- commands.Dequeue();
- }
- else
- {
- commands.Dequeue();
- }
- }
- else if (com == "down")
- {
- if (minerRow + 1 < size)
- {
- minerRow++;
- char symbol = field[minerRow, minerCol];
- if (symbol == 'e')
- {
- Console.WriteLine($"Game over! ({minerRow}, {minerCol})");
- break;
- }
- else if (symbol == 'c')
- {
- collectedCoals++;
- field[minerRow - 1, minerCol] = '*';
- field[minerRow, minerCol] = 's';
- }
- else if (symbol == '*')
- {
- commands.Dequeue();
- continue;
- }
- commands.Dequeue();
- }
- else
- {
- commands.Dequeue();
- }
- }
- else if (com == "left")
- {
- if (minerCol - 1 >= 0)
- {
- minerCol--;
- char symbol = field[minerRow, minerCol];
- if (symbol == 'e')
- {
- Console.WriteLine($"Game over! ({minerRow}, {minerCol})");
- break;
- }
- else if (symbol == 'c')
- {
- collectedCoals++;
- field[minerRow, minerCol + 1] = '*';
- field[minerRow, minerCol] = 's';
- }
- else if (symbol =='*')
- {
- commands.Dequeue();
- continue;
- }
- commands.Dequeue();
- }
- else
- {
- commands.Dequeue();
- }
- }
- else if (com == "right")
- {
- if (minerCol + 1 < size)
- {
- minerCol++;
- char symbol = field[minerRow, minerCol];
- if (symbol == 'e')
- {
- Console.WriteLine($"Game over! ({minerRow}, {minerCol})");
- break;
- }
- else if (symbol == 'c')
- {
- collectedCoals++;
- field[minerRow, minerCol - 1] = '*';
- field[minerRow, minerCol] = 's';
- }
- else if (symbol == '*')
- {
- commands.Dequeue();
- continue;
- }
- commands.Dequeue();
- }
- else
- {
- commands.Dequeue();
- }
- }
- }
- if (commands.Count == 0 && collectedCoals != countCoals)
- {
- Console.WriteLine($"{countCoals - collectedCoals} coals left. ({minerRow}, {minerCol})");
- }
- else if (collectedCoals == countCoals)
- {
- Console.WriteLine($"You collected all coals! ({minerRow}, {minerCol})");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement