Garloon

4.4

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