Advertisement
dxoraxs

Untitled

Apr 12th, 2019
115
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.  
  3. namespace homework
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.             const string youLose = "YOU DIED";
  11.             int consoleWidth = Console.WindowWidth, consoleHeight = Console.WindowHeight;
  12.             char[,] map =
  13.             {
  14.                 {'#','#','#','#','#','#','#','#','#','#','#','#' },
  15.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  16.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  17.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  18.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  19.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  20.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  23.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  24.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  25.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  26.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  27.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  28.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  29.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  30.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  31.                 {'#','#','#','#','#','#','#','#','#','#','#','#' }
  32.             };
  33.             int[,] coorX = { {2 , 2},{4, 5}, { 6, 8 }, { 8,2 }, { 10, 2 }, { 12, 5 },{ 14, 2 } };
  34.             int userY = 1, userX = 1;
  35.             Random rand = new Random();
  36.  
  37.             while (true)
  38.             {
  39.                 Console.SetCursorPosition(0, 0);
  40.                 for (int i = 0; i < coorX.GetLength(0); i++)
  41.                 {
  42.                     map[coorX[i, 0], coorX[i, 1]] = ' ';
  43.                     coorX[i, 0]++;
  44.                     if (coorX[i, 0] >= map.GetLength(0) - 1)
  45.                     {
  46.                         coorX[i, 0] = 1;
  47.                         coorX[i, 1] = rand.Next(1, 10);
  48.                     }
  49.                     map[coorX[i, 0], coorX[i, 1]] = 'X';
  50.                 }
  51.                 for (int i = 0; i < map.GetLength(0); i++)
  52.                 {
  53.                     for (int j = 0; j < map.GetLength(1); j++)
  54.                     {
  55.                         Console.Write(map[i, j]);
  56.                     }
  57.                     Console.WriteLine();
  58.                 }
  59.  
  60.                 Console.SetCursorPosition(userY, userX);
  61.                 Console.Write('@');
  62.                 ConsoleKeyInfo charKey = Console.ReadKey();
  63.  
  64.                 switch (charKey.Key)
  65.                 {
  66.                     case ConsoleKey.UpArrow:
  67.                         if (map[userX - 1, userY] != '#')
  68.                             userX--;
  69.                         break;
  70.                     case ConsoleKey.DownArrow:
  71.                         if (map[userX + 1, userY] != '#')
  72.                             userX++;
  73.                         break;
  74.                     case ConsoleKey.LeftArrow:
  75.                         if (map[userX, userY - 1] != '#')
  76.                             userY--;
  77.                         break;
  78.                     case ConsoleKey.RightArrow:
  79.                         if (map[userX, userY + 1] != '#')
  80.                             userY++;
  81.                         break;
  82.                 }
  83.  
  84.                 if (map[userX, userY] == 'X' || map[userX, userY+1] == 'X'|| map[userX, userY-1] == 'X')
  85.                 {
  86.                     Console.Clear();
  87.                     Console.SetCursorPosition(consoleWidth / 2 - youLose.Length / 2, consoleHeight / 2);
  88.                     Console.WriteLine(youLose);
  89.                     Console.ReadKey();
  90.                 }
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement