mattnguyen

Untitled

May 29th, 2023
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.BaristaContest
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             char[,] field = new char[n, n];
  13.  
  14.             int moleRow = -1;
  15.             int moleCol = -1;
  16.  
  17.             int points = 0;
  18.  
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 string row = Console.ReadLine();
  22.  
  23.                 for (int j = 0; j < n; j++)
  24.                 {
  25.                     field[i, j] = row[j];
  26.                     if (field[i, j] == 'M')
  27.                     {
  28.                         moleRow = i;
  29.                         moleCol = j;
  30.                         field[i, j] = '-';
  31.                     }
  32.                 }
  33.             }
  34.  
  35.             string command = Console.ReadLine();
  36.  
  37.             while (command != "End")
  38.             {
  39.                 if (points >= 25)
  40.                 {
  41.                     break;
  42.                 }
  43.  
  44.                 if ((command == "left" && moleCol == 0) ||
  45.                     (command == "right" && moleCol == field.GetLength(1) - 1) ||
  46.                     (command == "up" && moleRow == 0) ||
  47.                     (command == "down" && moleRow == field.GetLength(0) - 1))
  48.                 {
  49.                     Console.WriteLine("Don't try to escape the playing field!");
  50.                     continue;
  51.                 }
  52.  
  53.                 if (field[moleRow, moleCol] == 'S')
  54.                 {
  55.                     points -= 3;
  56.                     field[moleRow, moleCol] = '-';
  57.                     bool teleportation = false;
  58.  
  59.                     for (int i = 0; i < n; i++)
  60.                     {
  61.                         for (int j = 0; j < n; j++)
  62.                         {
  63.                             if (field[i, j] == 'S')
  64.                             {
  65.                                 teleportation = true;
  66.                                 moleRow = i;
  67.                                 moleCol = j;
  68.                                 field[moleRow, moleCol] = '-';
  69.                             }
  70.                         }
  71.                     }
  72.  
  73.                 }
  74.                 else if (char.IsDigit(field[moleRow, moleCol]))
  75.                 {
  76.                     field[moleRow, moleCol] = '-';
  77.                     points += int.Parse(field[moleRow, moleCol].ToString()); // pishe che input string not in a correct format
  78.                     field[moleRow, moleCol] = 'M';
  79.                 }
  80.                 else if (field[moleRow, moleCol] == '-')
  81.                 {
  82.                     field[moleRow, moleCol] = '-';
  83.                 }
  84.  
  85.                 switch (command)
  86.                 {
  87.                     case "left":
  88.                         moleCol--;
  89.                         break;
  90.                     case "right":
  91.                         moleCol++;
  92.                         break;
  93.                     case "up":
  94.                         moleRow--;
  95.                         break;
  96.                     case "down":
  97.                         moleRow++;
  98.                         break;
  99.  
  100.                 }
  101.             }
  102.  
  103.             field[moleRow, moleCol] = 'M';
  104.  
  105.             if (points < 25)
  106.             {
  107.                 Console.WriteLine("Too bad! The Mole lost this battle!");
  108.                 Console.WriteLine($"The Mole lost the game with a total of {points} points.");
  109.             }
  110.             else
  111.             {
  112.                 Console.WriteLine("Yay! The Mole survived another game!");
  113.                 Console.WriteLine($"The Mole managed to survive with a total of {points} points.");
  114.             }
  115.  
  116.             for (int i = 0; i < n; i++)
  117.             {
  118.                 for (int j = 0; j < n; j++)
  119.                 {
  120.                     Console.Write(field[i, j]);
  121.                 }
  122.                 Console.WriteLine();
  123.             }
  124.         }
  125.     }
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment