Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FifthProject
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int level = 1;
- char[,] map1 =
- {
- {'#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#' }
- };
- char[,] map2 =
- {
- {'#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ','!',' ',' ',' ','!','!','#' },
- {'#','!',' ','!',' ','!','$','!','!','#' },
- {'#','!',' ','!',' ','!','!','!','!','#' },
- {'#','!',' ','!',' ',' ',' ',' ','!','#' },
- {'#','!',' ','!','!','!','!',' ','!','#' },
- {'#','!',' ','!',' ',' ',' ',' ','!','#' },
- {'#','!',' ','!',' ','!','!','!','!','#' },
- {'#',' ',' ','!',' ',' ','$','!','!','#' },
- {'#',' ','!','!','!','!',' ','!','!','#' },
- {'#',' ','!','!','!','!',' ','!','!','#' },
- {'#',' ',' ',' ',' ',' ',' ','!','!','#' },
- {'#','#','#','#','#','#','#','#','#','#' }
- };
- char[,] map3 =
- {
- {'#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!','$','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#' }
- };
- char[] bag = new char[0];
- while (true)
- {
- int userX = 1, userY = 1;
- if (level == 1)
- {
- while (true)
- {
- DrawMap(map1);
- Console.SetCursorPosition(0, 20);
- Console.WriteLine("Собранные сокровища:");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + ", ");
- }
- Console.SetCursorPosition(userY, userX);
- Console.Write('X');
- PlayerControl(map1, ref userY, ref userX);
- bag = Bag(map1, userX, userY, bag);
- if (bag.Length == 2)
- {
- level = Finish(level);
- break;
- }
- }
- }
- else if (level == 2)
- {
- while (true)
- {
- DrawMap(map2);
- Console.SetCursorPosition(0, 23);
- Console.WriteLine("Не касайтесь шипов!\n");
- Console.WriteLine("Собранные сокровища:");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + ", ");
- }
- Console.SetCursorPosition(userY, userX);
- Console.Write('X');
- PlayerControl(map2, ref userY, ref userX);
- bag = Bag(map2, userX, userY, bag);
- if (map2[userX, userY] == '!')
- {
- Spikes(ref userX, ref userY);
- continue;
- }
- if (bag.Length == 4)
- {
- level = Finish(level);
- break;
- }
- }
- }
- else if (level == 3)
- {
- while (true)
- {
- DrawMap(map3);
- Console.SetCursorPosition(0, 23);
- Console.WriteLine("Что бы перепрыгнуть пропасть - встаньте у края и нажмите Space\n");
- Console.WriteLine("Собранные сокровища:");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.Write(bag[i] + ", ");
- }
- Console.SetCursorPosition(userY, userX);
- Console.Write('X');
- PlayerControl(map3, ref userY, ref userX);
- bag = Bag(map3, userX, userY, bag);
- if (map3[userX, userY] == '!')
- {
- Spikes(ref userX, ref userY);
- continue;
- }
- if (bag.Length == 5)
- {
- level = Finish(level);
- break;
- }
- }
- }
- if (level == 4)
- {
- Console.WriteLine("Спасибо за то, что играли в демо-версию");
- Console.ReadKey();
- break;
- }
- }
- }
- 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 PlayerControl(char[,] map, ref int userY, ref int userX)
- {
- ConsoleKeyInfo consoleKey = Console.ReadKey();
- switch (consoleKey.Key)
- {
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '#')
- {
- userY--;
- }
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '#' && map[userX, userY + 1] != '|')
- {
- userY++;
- }
- break;
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '#')
- {
- userX--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '#')
- {
- userX++;
- }
- break;
- case ConsoleKey.Spacebar:
- if (map[userX, userY + 1] == '|')
- {
- userY += 3;
- }
- break;
- }
- }
- static char[] Bag(char[,] map, int userX, int userY, char[] bag)
- {
- if (map[userX, userY] == '$')
- {
- 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] = '$';
- bag = tempBag;
- }
- return bag;
- }
- static int Finish (int level)
- {
- Console.Clear();
- level++;
- return level;
- }
- static void Spikes(ref int userX, ref int userY)
- {
- Console.Clear();
- Console.WriteLine("Вы проиграли, не касайтесь шипов!");
- Console.ReadKey();
- userX = 1;
- userY = 1;
- Console.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement