Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.70 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp4
  3. {
  4.     class Program
  5.     {
  6.         static int xCorPoint = 5;
  7.         static int yCorPoint = 5;
  8.         static int xCor = 10;
  9.         static int yCor = 10;
  10.         static int[,] playerCor = new int[xCor, yCor];
  11.         static char playerModel = 'O';
  12.         static int[,] mapSize = new int[40, 20];
  13.         static char point = '?';
  14.         static int[,] pointCor = new int[xCorPoint, yCorPoint];
  15.         static int MyPoint = 0;
  16.  
  17.         static void Main()
  18.         {
  19.             start:
  20.             PlayerGenerate();
  21.             MapGenerate(mapSize);
  22.             GeneratePoint();
  23.             ViewPoint();
  24.  
  25.             while (true)
  26.             {
  27.             PlayerMove();
  28.             PointDead();
  29.             ViewPoint();
  30.                 if (MyPoint == 20)
  31.                 {
  32.                     Win();
  33.                     Console.Clear();
  34.                     MyPoint = 0;
  35.                     goto start;
  36.                 }
  37.             }
  38.         }
  39.         static void PlayerGenerate()
  40.         {
  41.             Console.ResetColor();
  42.             Console.SetCursorPosition(xCor, yCor);
  43.             Console.WriteLine(playerModel);
  44.         }
  45.  
  46.         static void MapGenerate(int[,] mapSize)
  47.         {
  48.             for (int x = 0; x <= mapSize.GetLength(0); x++)
  49.             {
  50.                 for (int y = 0; y <= mapSize.GetLength(1); y++)
  51.                 {
  52.                     if (x == 0 || x == mapSize.GetLength(0))
  53.                     {
  54.                         Console.SetCursorPosition(x, y);
  55.                         Console.WriteLine("!");
  56.                     }
  57.                     else if (y == 0 || y == mapSize.GetLength(1))
  58.                     {
  59.                         Console.SetCursorPosition(x, y);
  60.                         Console.WriteLine("-");
  61.                     }
  62.                 }
  63.             }
  64.  
  65.         }
  66.         static void PlayerMove()
  67.         {
  68.             ConsoleKeyInfo key = Console.ReadKey(true);
  69.             switch (key.Key)
  70.             {
  71.  
  72.                 case ConsoleKey.LeftArrow:
  73.                     if (xCor > 2 & xCor < mapSize.GetLength(0) -1)
  74.                     {
  75.                         PlayerClear();
  76.                         xCor--;
  77.                         PlayerGenerate();
  78.                         Console.SetCursorPosition(41, 21);
  79.                         Console.WriteLine("                   ");
  80.                     }
  81.                     else
  82.                     {
  83.                         PlayerClear();
  84.                         xCor++;
  85.                         xCor++;
  86.                         PlayerGenerate();
  87.                         Console.SetCursorPosition(41, 21);
  88.                         Console.WriteLine("STOP!");
  89.                     }
  90.                     break;
  91.                 case ConsoleKey.RightArrow:
  92.                     if (xCor > 2 & xCor < mapSize.GetLength(0) - 2)
  93.                     {
  94.                         PlayerClear();
  95.                         xCor++;
  96.                         PlayerGenerate();
  97.                         Console.SetCursorPosition(41, 21);
  98.                         Console.WriteLine("                   ");
  99.                     }
  100.                     else
  101.                     {
  102.                         PlayerClear();
  103.                         xCor--;
  104.                         xCor--;
  105.                         PlayerGenerate();
  106.                         Console.SetCursorPosition(41, 21);
  107.                         Console.WriteLine("STOP!");
  108.                     }
  109.                     break;
  110.                 case ConsoleKey.UpArrow:
  111.                     if (yCor > 2 & yCor < mapSize.GetLength(1) - 1)
  112.                     {
  113.                         PlayerClear();
  114.                         yCor--;
  115.                         PlayerGenerate();
  116.                         Console.SetCursorPosition(41, 21);
  117.                         Console.WriteLine("                   ");
  118.                     }
  119.                     else
  120.                     {
  121.                         PlayerClear();
  122.                         yCor++;
  123.                         yCor++;
  124.                         PlayerGenerate();
  125.                         Console.SetCursorPosition(41, 21);
  126.                         Console.WriteLine("STOP!");
  127.                     }
  128.                     break;
  129.                 case ConsoleKey.DownArrow:
  130.                     if (yCor > 2 & yCor < mapSize.GetLength(1) - 1)
  131.                     {
  132.                         PlayerClear();
  133.                         yCor++;
  134.                         PlayerGenerate();
  135.                         Console.SetCursorPosition(41, 21);
  136.                         Console.WriteLine("                   ");
  137.                     }
  138.                     else
  139.                     {
  140.                         PlayerClear();
  141.                         yCor--;
  142.                         yCor--;
  143.                         PlayerGenerate();
  144.                         Console.SetCursorPosition(41, 21);
  145.                         Console.WriteLine("STOP!");
  146.                     }
  147.                     break;
  148.             }
  149.         }
  150.         static void PlayerClear()
  151.         {
  152.             Console.SetCursorPosition(xCor, yCor);
  153.             Console.WriteLine(" ");
  154.         }
  155.         static void GeneratePoint()
  156.         {
  157.             Random x = new Random();
  158.             Random y = new Random();
  159.             xCorPoint =  x.Next(4, 36);
  160.             yCorPoint =  y.Next(4, 16);
  161.             Console.SetCursorPosition(xCorPoint, yCorPoint);
  162.             Console.WriteLine(point);
  163.            
  164.         }
  165.         static void PointDead()
  166.         {
  167.             if (xCor == xCorPoint && yCor == yCorPoint)
  168.             {
  169.                 Console.SetCursorPosition(xCorPoint, yCorPoint);
  170.                 Console.WriteLine(" ");
  171.                 PlayerGenerate();
  172.                 GeneratePoint();
  173.                 MyPoint++;
  174.             }
  175.         }
  176.         static void ViewPoint()
  177.         {
  178.             Console.SetCursorPosition(42, 6);
  179.             Console.WriteLine("Используй стрелки");
  180.             Console.SetCursorPosition(42, 8);
  181.             Console.WriteLine("Наберите 20 очков!");
  182.             Console.SetCursorPosition(42, 10);
  183.             Console.WriteLine("Всего очков: " + MyPoint);
  184.         }
  185.         static void Win()
  186.         {
  187.                 Console.Clear();
  188.                 Console.SetCursorPosition(10, 10);
  189.                 Console.ForegroundColor = ConsoleColor.Green;
  190.                 Console.WriteLine("Ты победил! МОЛОДЕЦ !");
  191.                 Console.SetCursorPosition(1, 12);
  192.                 Console.WriteLine("Нажмите любую кнопку \n чтобы начать сначала...");
  193.             Console.ReadKey();
  194.         }
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement