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 ConsoleApp5
- {
- /*TODO
- * Rewrite the array of blocks and positions as a dictionary?
- *
- *
- * */
- class Block
- {
- public enum BlockType
- {
- Dirt,
- Ground
- }
- BlockType blockType;
- bool IsWalkable = false;
- char Icon = ' ';
- Pos Position;
- public Block(BlockType _blocktype, bool _isWalkable, char _icon, Pos _pos)
- {
- blockType = _blocktype;
- IsWalkable = _isWalkable;
- Icon = _icon;
- Position = _pos;
- }
- public String GetBlockType
- {
- get { return blockType.ToString(); }
- }
- public Pos Pos
- {
- get { return Position; }
- }
- public Char BlockIcon
- {
- get { return Icon; }
- }
- }
- class Program
- {
- int MapSize = 10;
- char dirt = '#';
- char ground = '.';
- Pos[] pos;
- List<Block> blocks;
- static void Main(string[] args)
- {
- Program p = new Program();
- p.BeginGenerating();
- }
- void BeginGenerating()
- {
- Console.Write("Enter the wanted size of the map in a number (3-29) : ");
- MapSize = Convert.ToInt32(Console.ReadLine());
- if (MapSize > 29)
- MapSize = 29;
- if (MapSize < 3)
- MapSize = 3;
- Console.Clear();
- Console.Write("Enter a map seed : ");
- int seed = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- Random rand = new Random(seed);
- pos = new Pos[MapSize];
- blocks = new List<Block>();
- for (int x = 0; x < MapSize*2; x++)
- {
- for (int y = 0; y < MapSize; y++)
- {
- Console.SetCursorPosition(GetPosition(x), GetPosition(y));
- pos[y] = new Pos(GetPosition(x), GetPosition(y));
- Block tempBlock;
- if (((y > 0 && y < MapSize - 1) && (x > 0 && x < MapSize * 2 - 1)))
- {
- tempBlock = new Block(Block.BlockType.Ground, true, ground, pos[y]);
- blocks.Add(tempBlock);
- }
- else
- {
- tempBlock = new Block(Block.BlockType.Dirt, false, dirt, pos[y]);
- blocks.Add(tempBlock);
- }
- Console.Write(tempBlock.BlockIcon);
- }
- }
- /*for (int x = 0; x < MapSize * 2; x++)
- {
- for (int y = 0; y < MapSize; y++)
- {
- if ((!(y > 0 && y < MapSize - 1) && !(x > 0 && x < MapSize * 2 - 1)))
- {
- int rndNum = rand.Next(1, 100);
- if(rndNum < 25)
- {
- }
- }
- }
- }*/
- Console.WriteLine();
- int repeat = 0;
- for(int i = 0; i < blocks.Count;i++)
- {
- if(repeat >= 8)
- {
- repeat = 0;
- Console.WriteLine();
- }
- Console.Write(blocks[i].GetBlockType + "[" + blocks[i].Pos.PosX + "," + blocks[i].Pos.PosY + "] ");
- repeat++;
- }
- Console.ReadLine();
- }
- int GetPosition(int num)
- {
- int position = (Console.WindowWidth / 2) + num;
- return num;
- }
- }
- struct Pos
- {
- int x;
- int y;
- public Pos(int _x, int _y)
- {
- x = _x;
- y = _y;
- }
- public int PosX
- {
- get { return x; }
- }
- public int PosY
- {
- get { return y; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement