Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Brave_new_world
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ',' ','#',' ','X',' ',' ',' ',' ',' ','#',' ',' ','X','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ','X',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ','#','#','#','#',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ','X','#',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ','#',' ','X',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ','X',' ',' ',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','X',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
- };
- int userPositionX = 6;
- int userPositionY = 6;
- int directionX = 0;
- int directionY = 0;
- char[] bag = new char[1];
- char user = '@';
- char treasure = 'X';
- char emptyTreasure = 'O';
- char wall = '#';
- bool isRun = true;
- while (isRun)
- {
- CreateBag(bag);
- DrawMap(map);
- Console.SetCursorPosition(userPositionY, userPositionX);
- Console.WriteLine(user);
- GetDirection(ref directionX, ref directionY);
- if (map[userPositionX + directionX, userPositionY + directionY] != wall)
- {
- Movement(ref userPositionY, ref userPositionX, directionY, directionX);
- }
- ExpansionBag(ref map, ref bag, ref userPositionX, ref userPositionY, treasure, emptyTreasure);
- Console.Clear();
- }
- }
- static void DrawMap(char[,] map)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void CreateBag(char[] bag)
- {
- Console.SetCursorPosition(0, 15);
- Console.Write("Сумка: ");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + " ");
- }
- }
- static void ExpansionBag(ref char[,] map, ref char[] bag, ref int userX, ref int userY, char treasure, char emptyTreasure)
- {
- if (map[userX, userY] == treasure)
- {
- map[userX, userY] = emptyTreasure;
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = treasure;
- bag = tempBag;
- }
- }
- static void Movement(ref int positionX, ref int positionY, int directionX, int directionY)
- {
- positionX += directionX;
- positionY += directionY;
- }
- static void GetDirection(ref int directionX, ref int directionY)
- {
- directionX = 0;
- directionY = 0;
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- directionX--;
- break;
- case ConsoleKey.DownArrow:
- directionX++;
- break;
- case ConsoleKey.LeftArrow:
- directionY--;
- break;
- case ConsoleKey.RightArrow:
- directionY++;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement