Advertisement
Guest User

Untitled

a guest
May 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp3
  8. {
  9.     class MainClass
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.  
  14.             int userY = 4;
  15.             int userX = 5;
  16.             Console.CursorVisible = false;
  17.             bool play = true;
  18.             char[,] map =
  19.                 { { '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
  20.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ','#' },
  23.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  24.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  25.               { '#',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  26.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  27.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ','#' },
  28.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  29.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ','#' },
  30.               { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  31.               { '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }};
  32.             while (play)
  33.             {
  34.                 Map(map);
  35.                 Console.SetCursorPosition(userY, userX);
  36.                 Console.Write('@');
  37.                 ConsoleKeyInfo charKey = Console.ReadKey(true);
  38.  
  39.                 switch (charKey.Key)
  40.                 {
  41.                     case ConsoleKey.LeftArrow:
  42.                         if (map[userX, userY - 1] != '#')
  43.                             userY--;
  44.                         break;
  45.                     case ConsoleKey.RightArrow:
  46.                         if (map[userX, userY + 1] != '#')
  47.                             userY++;
  48.                         break;
  49.                     case ConsoleKey.UpArrow:
  50.                         if (map[userX - 1, userY] != '#')
  51.                             userX--;
  52.                         break;
  53.                     case ConsoleKey.DownArrow:
  54.                         if (map[userX + 1, userY] != '#')
  55.                             userX++;
  56.                         break;
  57.                 }
  58.                 if (map[userX, userY] == 'O')
  59.                 {
  60.                     play = false;
  61.                     break;
  62.                 }
  63.  
  64.             }
  65.             Console.Clear();
  66.             Console.WriteLine("Ты провалился в яму!");
  67.             Console.ReadKey();
  68.  
  69.         }
  70.  
  71.         public static void Map(char[,] map)
  72.         {
  73.             Console.SetCursorPosition(0, 0);
  74.             for (int x = 0; x < map.GetLength(0); x++)
  75.             {
  76.                 for (int y = 0; y < map.GetLength(1); y++)
  77.                 {
  78.                     Console.Write(map[x, y]);
  79.                 }
  80.                 Console.WriteLine();
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement