Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp4
- {
- class Program
- {
- static int xCorPoint = 5;
- static int yCorPoint = 5;
- static int xCor = 10;
- static int yCor = 10;
- static int[,] playerCor = new int[xCor, yCor];
- static char playerModel = 'O';
- static int[,] mapSize = new int[40, 20];
- static char point = '?';
- static int[,] pointCor = new int[xCorPoint, yCorPoint];
- static int MyPoint = 0;
- static void Main()
- {
- start:
- PlayerGenerate();
- MapGenerate(mapSize);
- GeneratePoint();
- ViewPoint();
- while (true)
- {
- PlayerMove();
- PointDead();
- ViewPoint();
- if (MyPoint == 20)
- {
- Win();
- Console.Clear();
- MyPoint = 0;
- goto start;
- }
- }
- }
- static void PlayerGenerate()
- {
- Console.ResetColor();
- Console.SetCursorPosition(xCor, yCor);
- Console.WriteLine(playerModel);
- }
- static void MapGenerate(int[,] mapSize)
- {
- for (int x = 0; x <= mapSize.GetLength(0); x++)
- {
- for (int y = 0; y <= mapSize.GetLength(1); y++)
- {
- if (x == 0 || x == mapSize.GetLength(0))
- {
- Console.SetCursorPosition(x, y);
- Console.WriteLine("!");
- }
- else if (y == 0 || y == mapSize.GetLength(1))
- {
- Console.SetCursorPosition(x, y);
- Console.WriteLine("-");
- }
- }
- }
- }
- static void PlayerMove()
- {
- ConsoleKeyInfo key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.LeftArrow:
- if (xCor > 2 & xCor < mapSize.GetLength(0) -1)
- {
- PlayerClear();
- xCor--;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine(" ");
- }
- else
- {
- PlayerClear();
- xCor++;
- xCor++;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine("STOP!");
- }
- break;
- case ConsoleKey.RightArrow:
- if (xCor > 2 & xCor < mapSize.GetLength(0) - 2)
- {
- PlayerClear();
- xCor++;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine(" ");
- }
- else
- {
- PlayerClear();
- xCor--;
- xCor--;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine("STOP!");
- }
- break;
- case ConsoleKey.UpArrow:
- if (yCor > 2 & yCor < mapSize.GetLength(1) - 1)
- {
- PlayerClear();
- yCor--;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine(" ");
- }
- else
- {
- PlayerClear();
- yCor++;
- yCor++;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine("STOP!");
- }
- break;
- case ConsoleKey.DownArrow:
- if (yCor > 2 & yCor < mapSize.GetLength(1) - 1)
- {
- PlayerClear();
- yCor++;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine(" ");
- }
- else
- {
- PlayerClear();
- yCor--;
- yCor--;
- PlayerGenerate();
- Console.SetCursorPosition(41, 21);
- Console.WriteLine("STOP!");
- }
- break;
- }
- }
- static void PlayerClear()
- {
- Console.SetCursorPosition(xCor, yCor);
- Console.WriteLine(" ");
- }
- static void GeneratePoint()
- {
- Random x = new Random();
- Random y = new Random();
- xCorPoint = x.Next(4, 36);
- yCorPoint = y.Next(4, 16);
- Console.SetCursorPosition(xCorPoint, yCorPoint);
- Console.WriteLine(point);
- }
- static void PointDead()
- {
- if (xCor == xCorPoint && yCor == yCorPoint)
- {
- Console.SetCursorPosition(xCorPoint, yCorPoint);
- Console.WriteLine(" ");
- PlayerGenerate();
- GeneratePoint();
- MyPoint++;
- }
- }
- static void ViewPoint()
- {
- Console.SetCursorPosition(42, 6);
- Console.WriteLine("Используй стрелки");
- Console.SetCursorPosition(42, 8);
- Console.WriteLine("Наберите 20 очков!");
- Console.SetCursorPosition(42, 10);
- Console.WriteLine("Всего очков: " + MyPoint);
- }
- static void Win()
- {
- Console.Clear();
- Console.SetCursorPosition(10, 10);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Ты победил! МОЛОДЕЦ !");
- Console.SetCursorPosition(1, 12);
- Console.WriteLine("Нажмите любую кнопку \n чтобы начать сначала...");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement