Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Readline
- {
- class Program
- {
- static void Bravenewworld()
- {
- Console.CursorVisible = false;
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ','#',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ','#','X','#',' ',' ','#',' ','#',' ',' ','#',' ','#' },
- {'#',' ',' ',' ','#',' ','X','#',' ','#',' ',' ','#',' ','#' },
- {'#',' ','#',' ',' ',' ',' ','#',' ','#',' ',' ','#',' ','#' },
- {'#',' ','#',' ','#',' ',' ','#',' ','#',' ',' ','#',' ','#' },
- {'#',' ','#','#','#','#','#','#',' ','#',' ',' ','#',' ','#' },
- {'#',' ','X',' ',' ',' ',' ',' ',' ','#','X',' ','#',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#',' ','#' },
- {'#',' ',' ',' ',' ','#','#','#',' ',' ',' ',' ',' ',' ','#' },
- {'#','X','#','#',' ',' ',' ',' ',' ','#','#','#',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
- };
- char[] bag = new char[0];
- bool gameopen = true;
- int userX = 1, userY = 1;
- int shetchik = 0;
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(0); j++)
- {
- if (map[i, j] == 'X')
- {
- shetchik += 1;
- }
- }
- }
- while (gameopen == true)
- {
- 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();
- }
- Console.SetCursorPosition(0, 15);
- Console.Write("Сумка: ");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + " ");
- }
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- 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] == 'X')
- {
- map[userX, 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 == shetchik)
- {
- gameopen = false;
- }
- }
- Console.SetCursorPosition(0, 20);
- Console.WriteLine("Игра окончена! Вы собрали все сокровища!\n");
- }
- static void Main(string[] args)
- {
- Bravenewworld();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment