Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSharpLight_HomeWork22_Brave_new_world
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int userX = 1;
- int userY = 1;
- int userDX = 0;
- int userDY = 0;
- char[,] map;
- char[] bag = new char[0];
- map = SetMap1();
- while(true)
- {
- while(true)
- {
- Console.SetCursorPosition(0, 0);
- DrawMap(map);
- Console.SetCursorPosition(0, 20);
- DrawBag(bag);
- Console.SetCursorPosition(userX, userY);
- Console.Write('X');
- MovePlayer(map, ref userY, ref userX);
- if (map[userY, userX] == '$')
- {
- map[userY, userX] = 'o';
- bag = AddMoney(bag);
- }
- if (map[userY, userX] == '!')
- {
- TouchBlow(ref userY, ref userX);
- continue;
- }
- if (bag.Length == 2)
- {
- map = SetMap2();
- continue;
- }
- else if (bag.Length == 4)
- {
- map = SetMap3();
- continue;
- }
- else if (bag.Length == 5)
- {
- break;
- }
- }
- if (bag.Length == 5)
- break;
- }
- Console.Clear();
- Console.WriteLine("Поздравляю, вы прошли игру!");
- Console.ReadKey();
- }
- static void DrawMap(char[,] map)
- {
- 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.WriteLine();
- Console.WriteLine("Двигайся на стрелочки. Не косайся шипов(!). Перепгнуть пропасть - space.");
- }
- static void DrawBag(char[] bag)
- {
- Console.WriteLine("Собранные сокровища: ");
- for(int i = 0; i < bag.Length; i++)
- {
- Console.WriteLine(bag[i] + ", ");
- }
- }
- static void MovePlayer(char[,] map, ref int userX, ref int userY)
- {
- int DX = 0;
- int DY = 0;
- ConsoleKeyInfo consoleKey = Console.ReadKey();
- switch (consoleKey.Key)
- {
- case ConsoleKey.UpArrow:
- DX = -1;
- break;
- case ConsoleKey.DownArrow:
- DX = 1;
- break;
- case ConsoleKey.LeftArrow:
- DY = -1;
- break;
- case ConsoleKey.RightArrow:
- DY = 1;
- break;
- case ConsoleKey.Spacebar:
- DY = 3;
- break;
- }
- if(map[userX + DX, userY + DY] != '#' && map[userX + DX, userY + DY] != '|')
- {
- userX += DX;
- userY += DY;
- }
- }
- static char[] AddMoney(char[] bag)
- {
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = '$';
- return tempBag;
- }
- static void TouchBlow(ref int userX, ref int userY)
- {
- Console.Clear();
- Console.WriteLine("Вы проиграли, не касайтесь шипов!");
- Console.ReadKey();
- userX = 1;
- userY = 1;
- Console.Clear();
- }
- static char[,] SetMap1()
- {
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#' }
- };
- return map;
- }
- static char[,] SetMap2()
- {
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#' },
- {'#','$',' ','!',' ',' ',' ','!','!','#' },
- {'#','!',' ','!',' ','!','$','!','!','#' },
- {'#','!',' ','!',' ','!','!','!','!','#' },
- {'#','!',' ','!',' ',' ',' ',' ','!','#' },
- {'#','!',' ','!','!','!','!',' ','!','#' },
- {'#','!',' ','!',' ',' ',' ',' ','!','#' },
- {'#','!',' ','!',' ','!','!','!','!','#' },
- {'#',' ',' ','!',' ',' ',' ','!','!','#' },
- {'#',' ','!','!','!','!',' ','!','!','#' },
- {'#',' ','!','!','!','!',' ','!','!','#' },
- {'#',' ',' ',' ',' ',' ',' ','!','!','#' },
- {'#','#','#','#','#','#','#','#','#','#' }
- };
- return map;
- }
- static char[,] SetMap3()
- {
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!','$','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#' }
- };
- return map;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement