Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.BaristaContest
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[,] field = new char[n, n];
- int moleRow = -1;
- int moleCol = -1;
- int points = 0;
- for (int i = 0; i < n; i++)
- {
- string row = Console.ReadLine();
- for (int j = 0; j < n; j++)
- {
- field[i, j] = row[j];
- if (field[i, j] == 'M')
- {
- moleRow = i;
- moleCol = j;
- field[i, j] = '-';
- }
- }
- }
- string command = Console.ReadLine();
- while (command != "End")
- {
- if (points >= 25)
- {
- break;
- }
- if ((command == "left" && moleCol == 0) ||
- (command == "right" && moleCol == field.GetLength(1) - 1) ||
- (command == "up" && moleRow == 0) ||
- (command == "down" && moleRow == field.GetLength(0) - 1))
- {
- Console.WriteLine("Don't try to escape the playing field!");
- continue;
- }
- if (field[moleRow, moleCol] == 'S')
- {
- points -= 3;
- field[moleRow, moleCol] = '-';
- bool teleportation = false;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (field[i, j] == 'S')
- {
- teleportation = true;
- moleRow = i;
- moleCol = j;
- field[moleRow, moleCol] = '-';
- }
- }
- }
- }
- else if (char.IsDigit(field[moleRow, moleCol]))
- {
- field[moleRow, moleCol] = '-';
- points += int.Parse(field[moleRow, moleCol].ToString()); // pishe che input string not in a correct format
- field[moleRow, moleCol] = 'M';
- }
- else if (field[moleRow, moleCol] == '-')
- {
- field[moleRow, moleCol] = '-';
- }
- switch (command)
- {
- case "left":
- moleCol--;
- break;
- case "right":
- moleCol++;
- break;
- case "up":
- moleRow--;
- break;
- case "down":
- moleRow++;
- break;
- }
- }
- field[moleRow, moleCol] = 'M';
- if (points < 25)
- {
- Console.WriteLine("Too bad! The Mole lost this battle!");
- Console.WriteLine($"The Mole lost the game with a total of {points} points.");
- }
- else
- {
- Console.WriteLine("Yay! The Mole survived another game!");
- Console.WriteLine($"The Mole managed to survive with a total of {points} points.");
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(field[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment