Advertisement
Vadim_Rogulev

Untitled

Apr 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 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 Brave_new_world
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.CursorVisible = false;
  14.  
  15.             char[,] map =
  16.             {
  17.                 {'#','#','#','#','#','#','#','#','#','#','#','#' },
  18.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  19.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  20.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  23.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  24.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  25.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  26.                 {'#','#','#','#','#','#','#','#','#','#','#','#' }
  27.             };
  28.  
  29.             int userY = 1, userX = 1;
  30.             char[] bag = new char[0];
  31.  
  32.  
  33.             while (true)
  34.             {
  35.                
  36.                 Console.SetCursorPosition(0, 0);
  37.                 for (int i = 0; i < map.GetLength(0); i++)
  38.                 {
  39.                     for (int j = 0; j < map.GetLength(1); j++)
  40.                     {
  41.                         Console.Write(map[i, j]);
  42.                     }
  43.                     Console.WriteLine();
  44.                 }
  45.  
  46.                 Console.SetCursorPosition(userY, userX);
  47.                 Console.Write('@');
  48.                 ConsoleKeyInfo charKey = Console.ReadKey();
  49.  
  50.                 switch (charKey.Key)
  51.                 {
  52.                     case ConsoleKey.UpArrow:
  53.                         if (map[userX - 1, userY] != '#')
  54.                             userX--;
  55.                         break;
  56.                     case ConsoleKey.DownArrow:
  57.                         if (map[userX + 1, userY] != '#')
  58.                             userX++;
  59.                         break;
  60.                     case ConsoleKey.LeftArrow:
  61.                         if (map[userX, userY - 1] != '#')
  62.                             userY--;
  63.                         break;
  64.                     case ConsoleKey.RightArrow:
  65.                         if (map[userX, userY + 1] != '#')
  66.                             userY++;
  67.                         break;
  68.                     case ConsoleKey.Enter:
  69.                         map[userX, userY] = '#';
  70.                         break;
  71.                     case ConsoleKey.Backspace:
  72.                         map[userX + 1, userY] = ' ';
  73.                         map[userX - 1, userY] = ' ';
  74.                         map[userX, userY + 1] = ' ';
  75.                         map[userX, userY - 1] = ' ';
  76.                         break;
  77.                 }
  78.  
  79.                
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement