Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace GameWithMap
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int userX = 13, userY = 1;
- char userSymb = '@';
- char[] bag = new char[0];
- char[,] map =
- {
- {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
- {'*',' ','$','*',' ',' ',' ','$','*',' ','$',' ',' ','*',' ','*',' ','*', },
- {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','$','*', },
- {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','*','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
- {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
- };
- while (true)
- {
- {
- DrawBag(bag);
- DrawMap(map);
- DrawUser(userY, userX, userSymb);
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '*')
- {
- userX--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '*')
- {
- userX++;
- }
- break;
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '*')
- {
- userY--;
- }
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '*')
- {
- userY++;
- }
- break;
- }
- if (map[userX, userY] == '$')
- {
- map[userX, userY] = '^';
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = '$';
- bag = tempBag;
- }
- Console.Clear();
- }
- }
- static void DrawMap(char[,] map1)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map1.GetLength(0); i++)
- {
- for (int j = 0; j < map1.GetLength(1); j++)
- {
- Console.Write(map1[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- static void DrawBag(char[] bag)
- {
- Console.SetCursorPosition(0, 18);
- Console.Write("Bag:");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + " ");
- }
- }
- static void DrawUser(int userY, int userX, char userSymb)
- {
- Console.SetCursorPosition(userY, userX);
- Console.Write(userSymb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement