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 ConsoleApp53
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- char[] bag1 = new char[0];
- char[] bag2 = new char[0];
- char[] bag3 = new char[0];
- char[] bag4 = new char[0];
- int width = Console.WindowWidth;
- int userX = 3, userY = 3;
- char[,] map = new char[20, 40];
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 40; j++)
- {
- map[i, j] = ' ';
- }
- }
- for (int i = 0; i < 40; i++)
- {
- map[0, i] = '#';
- map[19, i] = '#';
- }
- for (int i = 0; i < 20; i++)
- {
- map[i, 0] = '#';
- map[i, 39] = '#';
- }
- Random rnd1 = new Random();
- //случайное гавно на карте
- Random rnd2 = new Random();
- // шанс появления гавно
- for (int i = 1; i < 19; i++)
- {
- for (int j = 1; j < 39; j++)
- {
- int gavno = rnd1.Next(100);
- int chancegavna = rnd2.Next(100);
- if (chancegavna < 15 && i!=3 && j!=3) //15% шанс что случится гавно
- { // i=3 и j=3 это координаты
- switch (rnd2.Next(5))//выбор из 5 гавна
- {
- case 0:
- map[i, j] = '&';
- break;
- case 1:
- map[i, j] = '%';
- break;
- case 2:
- map[i, j] = '#';
- break;
- case 3:
- map[i, j] = '*';
- break;
- case 4:
- map[i, j] = 'o';
- break;
- }
- }
- }
- }
- //Расскоментить для проверки убийства вокруг героя окружения из #
- //map[userY - 1, userX] = '#';
- //map[userY + 1, userX] = '#';
- //map[userY, userX - 1] = '#';
- //map[userY, userX + 1] = '#';
- Random rnd3 = new Random();
- if(map[userY-1, userX]=='#' && map[userY + 1, userX] == '#' && map[userY, userX-1] == '#' && map[userY, userX+1] == '#')
- {
- switch (rnd3.Next(4))
- {
- case 0:
- map[userY - 1, userX] = ' ';
- break;
- case 1:
- map[userY + 1, userX] = ' ';
- break;
- case 2:
- map[userY, userX + 1] = ' ';
- break;
- case 3:
- map[userY, userX - 1] = ' ';
- break;
- }
- }
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 40; j++)
- {
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- while (true)
- {
- //%
- bagdraw(ref bag1,1);
- //*
- bagdraw(ref bag2,2);
- //o
- bagdraw(ref bag3,3);
- //&
- bagdraw(ref bag4,4);
- 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(userX, userY);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.LeftArrow:
- if (map[userY, userX - 1] != '#')
- {
- userX--;
- }
- break;
- case ConsoleKey.RightArrow:
- if (map[userY, userX + 1] != '#')
- {
- userX++;
- }
- break;
- case ConsoleKey.UpArrow:
- if (map[userY - 1, userX] != '#')
- {
- userY--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (map[userY + 1, userX] != '#')
- {
- userY++;
- }
- break;
- }
- if (map[userY, userX] == '%')
- {
- bagfill(ref bag1, '%', ref map, ref userY, ref userX);
- }
- if (map[userY, userX] == '*')
- {
- bagfill(ref bag2, '*', ref map, ref userY, ref userX);
- }
- if (map[userY, userX] == 'o')
- {
- bagfill(ref bag3, 'o', ref map, ref userY, ref userX);
- }
- if (map[userY, userX] == '&')
- {
- bagfill(ref bag4, '&', ref map, ref userY, ref userX);
- }
- }
- }
- static void bagdraw(ref char[] bag, int a)
- {
- Console.SetCursorPosition(0, 20+a);
- Console.Write("Сумка: ");
- for (int i = 0; i < bag.Length; i++)
- Console.Write(bag[i] + " | ");
- }
- static void bagfill(ref char[] bag,char ch,ref char[,] map,ref int userY, ref int userX )
- {
- map[userY, userX] = ' ';
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = ch;
- bag = tempBag;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement