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 easyMap_ver01
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int manX = 0;
- int manY = 0;
- int manDirectionX = 0;
- int manDirectionY = 0;
- int emptyCellsNumber = 0;
- bool isPlaying = true;
- ReadMap(out char[,] defaultMap);
- DrawMap(defaultMap, ref manX, ref manY, ref emptyCellsNumber);
- while (isPlaying)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo key = Console.ReadKey(true);
- ChangeDirection(key, ref manDirectionX, ref manDirectionY);
- if (defaultMap[manX + manDirectionX, manY + manDirectionY] != '#')
- {
- MoveMan(ref manX, ref manY, manDirectionX, manDirectionY);
- }
- }
- }
- }
- static void ReadMap(out char[,] defaultMap)
- {
- defaultMap = new char[27, 37]
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#','#',' ','#','#'},
- {'#',' ',' ',' ','#',' ',' ','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ','♂',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ','#','#','#','#','#','#',' ',' ','#','#','#','#','#',' ','#',' ',' ','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#','#',' ',' ','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#','#',' ','#','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
- {'#',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},//30
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
- };
- }
- static void DrawMap(char[,] defaultMap, ref int manX, ref int manY, ref int emptyCellsNumber)
- {
- for (int i = 0; i < defaultMap.GetLength(0); i++)
- {
- for (int j = 0; j < defaultMap.GetLength(1); j++)
- {
- Console.Write(defaultMap[i, j]);
- if (defaultMap[i, j] == '♂')
- {
- manX = i;
- manY = j;
- }
- if (defaultMap[i, j] == ' ')
- {
- emptyCellsNumber++;
- }
- }
- Console.WriteLine();
- }
- SpreadCards(defaultMap, emptyCellsNumber);
- }
- static void SpreadCards(char[,] defaultMap, int emptyCellsNumber)
- {
- int heart = 3;
- int diamond = 4;
- int club = 5;
- int spade = 6;
- int cardCell;
- Random rand = new Random();
- int[][] emptyCellsArray = new int[emptyCellsNumber][];
- int index = 0;
- for (int i = 0; i < defaultMap.GetLength(0); i++)
- {
- for (int j = 0; j < defaultMap.GetLength(1); j++)
- {
- if (defaultMap[i, j] == ' ')
- {
- emptyCellsArray[index] = new int[2] { i, j };
- index++;
- }
- }
- }
- for (int cardSuit = heart; cardSuit < spade + 1; cardSuit++)
- {
- for (int i = 0; i < 5; i++)
- {
- cardCell = rand.Next(0, emptyCellsNumber + 1);
- Console.SetCursorPosition(emptyCellsArray[cardCell][1], emptyCellsArray[cardCell][0]);
- Console.Write((char)cardSuit);
- }
- }
- }
- static void MoveMan(ref int manX, ref int manY, int manDirectionX, int manDirectionY)
- {
- char man = (char)11;
- Console.SetCursorPosition(manY, manX);
- Console.Write(' ');
- manX += manDirectionX;
- manY += manDirectionY;
- Console.SetCursorPosition(manY, manX);
- Console.Write(man);
- }
- static void ChangeDirection(ConsoleKeyInfo key, ref int upDown, ref int leftRight)
- {
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- upDown = -1; leftRight = 0;
- break;
- case ConsoleKey.DownArrow:
- upDown = 1; leftRight = 0;
- break;
- case ConsoleKey.LeftArrow:
- upDown = 0; leftRight = -1;
- break;
- case ConsoleKey.RightArrow:
- upDown = 0; leftRight = 1;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement