Advertisement
Guest User

Untitled

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