Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace IMJunior
- {
- class Program
- {
- static void Main()
- {
- Player player = new Player(3, 3);
- Map map = new Map();
- map.fillingMap();
- map.renderingMap(player);
- }
- }
- class Map
- {
- char[,] mapping = new char[12, 15];
- char[] bag = new char[0];
- public void fillingMap()
- {
- for (int i = 0; i < mapping.GetLength(0); i++)
- {
- for (int y = 0; y < mapping.GetLength(1) - 1; y++)
- {
- if (i == 0 || i == mapping.GetLength(0) - 1)
- mapping[i, y] = '#';
- else
- mapping[i, y] = ' ';
- }
- mapping[i, 0] = '#';
- mapping[i, mapping.GetLength(1) - 1] = '#';
- }
- Random random = new Random();
- for (byte i = 0; i < 3;)
- {
- byte xx = (byte)random.Next(0, 12);
- byte yy = (byte)random.Next(0, 15);
- if (mapping[xx, yy] != '#' && xx != 3 && yy != 3)
- {
- mapping[xx, yy] = 'X';
- Thread.Sleep(100);
- i++;
- }
- }
- }
- public void renderingMap(Player player)
- {
- Console.CursorVisible = false;
- bool flag = true;
- while (flag)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < mapping.GetLength(0); i++)
- {
- for (int y = 0; y < mapping.GetLength(1); y++)
- Console.Write(mapping[i, y]);
- Console.WriteLine();
- }
- Console.SetCursorPosition(0, 15);
- Console.Write("Сумка: ");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + " ");
- }
- Console.SetCursorPosition(player.UserY, player.UserX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (mapping[player.UserX - 1, player.UserY] != '#')
- player.UserX--;
- break;
- case ConsoleKey.DownArrow:
- if (mapping[player.UserX + 1, player.UserY] != '#')
- player.UserX++;
- break;
- case ConsoleKey.LeftArrow:
- if (mapping[player.UserX, player.UserY - 1] != '#')
- player.UserY--;
- break;
- case ConsoleKey.RightArrow:
- if (mapping[player.UserX, player.UserY + 1] != '#')
- player.UserY++;
- break;
- }
- if (mapping[player.UserX, player.UserY] == 'X')
- {
- mapping[player.UserX, player.UserY] = 'o';
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = 'X';
- bag = tempBag;
- }
- if (bag.Length == 3)
- {
- flag = false;
- Console.Clear();
- }
- }
- }
- }
- class Player
- {
- int userX;
- public int UserX
- {
- get { return userX; }
- set { userX = value; }
- }
- int userY;
- public int UserY
- {
- get { return userY; }
- set { userY = value; }
- }
- public Player(int userx,int usery)
- {
- userX = userx;
- userY = usery;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement