Advertisement
dxoraxs

Untitled

Apr 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homework
  4. {
  5.     class Program
  6.     {
  7.         static void PrintMap(char[,] map)
  8.         {
  9.             for (int i = 0; i < map.GetLength(0); i++)
  10.             {
  11.                 for (int j = 0; j < map.GetLength(1); j++)
  12.                 {
  13.                     Console.Write(map[i, j]);
  14.                 }
  15.                 Console.WriteLine();
  16.             }
  17.         }
  18.         static void Main(string[] args)
  19.         {
  20.             Console.CursorVisible = false;
  21.             const string youLose = "YOU DIED";
  22.             int consoleWidth = Console.WindowWidth, consoleHeight = Console.WindowHeight;
  23.             int score = 0;
  24.             char[,] map =
  25.             {
  26.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
  27.                 {'#','@',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  28.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  29.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  30.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  31.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  32.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  33.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  34.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  35.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  36.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  37.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  38.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  39.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  40.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  41.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  42.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  43.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
  44.             };
  45.             int[,] coorX = { { 2, 2 }, { 4, 5 }, { 6, 8 }, { 8, 2 }, { 10, 2 }, { 12, 5 }, { 14, 2 },{ 2, 2 }, { 4, 5 }, { 6, 8 }, { 8, 2 }, { 10, 2 }, { 12, 5 }, { 14, 2 } };
  46.             int userY = 1, userX = 1;
  47.             Random rand = new Random();
  48.  
  49.             while (true)
  50.             {
  51.                 Console.SetCursorPosition(20,1);
  52.                 Console.Write("ะกั‡ะตั‚: "+ score);
  53.                 Console.SetCursorPosition(0, 0);
  54.                 for (int i = 0; i < coorX.GetLength(0); i++)
  55.                 {
  56.                     map[coorX[i, 0], coorX[i, 1]] = ' ';
  57.                     coorX[i, 0]++;
  58.                     if (coorX[i, 0] >= map.GetLength(0) - 1)
  59.                     {
  60.                         coorX[i, 0] = 1;
  61.                         coorX[i, 1] = rand.Next(1, 13);
  62.                     }
  63.                     map[coorX[i, 0], coorX[i, 1]] = 'X';
  64.                 }
  65.                 PrintMap(map);
  66.  
  67.                 ConsoleKeyInfo charKey = Console.ReadKey();
  68.  
  69.                 switch (charKey.Key)
  70.                 {
  71.                     case ConsoleKey.UpArrow:
  72.                         if (map[userX - 1, userY] != '#')
  73.                         {
  74.                             map[userX, userY] = ' ';
  75.                             userX--;
  76.                             map[userX, userY] = '@';
  77.                         }
  78.                         break;
  79.                     case ConsoleKey.DownArrow:
  80.                         if (map[userX + 1, userY] != '#')
  81.                         {
  82.                             map[userX, userY] = ' ';
  83.                             userX++;
  84.                             map[userX, userY] = '@';
  85.                         }
  86.                         break;
  87.                     case ConsoleKey.LeftArrow:
  88.                         if (map[userX, userY - 1] != '#')
  89.                         {
  90.                             map[userX, userY] = ' ';
  91.                             userY--;
  92.                             map[userX, userY] = '@';
  93.                         }
  94.                         break;
  95.                     case ConsoleKey.RightArrow:
  96.                         if (map[userX, userY + 1] != '#')
  97.                         {
  98.                             map[userX, userY] = ' ';
  99.                             userY++;
  100.                             map[userX, userY] = '@';
  101.                         }
  102.                         break;
  103.                 }
  104.                 score++;
  105.                 if (map[userX, userY] == 'X' || map[userX - 1, userY] == 'X')
  106.                 {
  107.                     score = 0;
  108.                     Console.Clear();
  109.                     Console.SetCursorPosition(consoleWidth / 2 - youLose.Length / 2, consoleHeight / 2);
  110.                     Console.WriteLine(youLose);
  111.                     Console.ReadKey();
  112.                     Console.Clear();
  113.                 }
  114.             }
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement