Exemplo n.º 1
0
        public void SetMap(BoardMap boardMap)
        {
            int W = this.Width;
            int H = this.Height;

            int nTileW = boardMap.Tiles.GetLength(0);
            int nTileH = boardMap.Tiles.GetLength(1);

            int rectSizeX = W / nTileW;
            int rectSizeY = H / nTileH;

            Rectangle[] allRectangles = new Rectangle[nTileW * nTileH];

            Bitmap bitmap = new Bitmap(W, H);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                for (var i = 0; i < nTileW; ++i)
                {
                    for (var j = 0; j < nTileH; ++j)
                    {
                        int posX = rectSizeX * i;
                        int posY = rectSizeY * j;

                        Rectangle          rectangle = new Rectangle(posX, posY, rectSizeX, rectSizeY);
                        BoardMap.ETileType tileType  = boardMap.Tiles[i, j];
                        if (Globals.UISettings.TilesDebugBrushColors.ContainsKey(tileType))
                        {
                            Brush currentBrush = new SolidBrush(Globals.UISettings.TilesDebugBrushColors[tileType]);
                            graphics.FillRectangle(currentBrush, rectangle);
                        }
                    }
                }
            }

            this.Image = bitmap;
        }
Exemplo n.º 2
0
 public void SetMap(BoardMap boardMap)
 {
     MapVisualizer.SetMap(boardMap);
 }
Exemplo n.º 3
0
        private void GenerateMap()
        {
            BoardMap generatedMap = CardsGeneratorManager.GetInstance().GenerateMap();

            _form.SetMap(generatedMap);
        }
        public BoardMap GenerateMap()
        {
            BoardMap boardMap = new BoardMap(_settings.MapSizeX, _settings.MapSizeY);

            int currentAttempt = 0;

            bool generationOk;

            do
            {
                generationOk = true;

                // Create a map that will contains the validity of each direction
                Dictionary <BoardMap.EDirection, bool> validDirection = new Dictionary <BoardMap.EDirection, bool>();

                //Clear map
                boardMap.Clear();

                //Choose random starting point on the edges
                BoardPoint startPoint = boardMap.GetRandomEdgePosition();
                boardMap.SetTile(startPoint, BoardMap.ETileType.StartPoint);


                // Generate roads
                BoardPoint currentPos = startPoint;
                for (var i = 0; i < _settings.RoadsTilesToPlace; ++i)
                {
                    //Calculate possible directions
                    int possibleDirections = 0;
                    for (var dirI = 0; dirI < (uint)BoardMap.EDirection.COUNT; ++dirI)
                    {
                        BoardMap.EDirection direction = (BoardMap.EDirection)dirI;
                        bool validDir = validDirection[direction] = boardMap.IsClearDirection(currentPos, direction);
                        if (validDir)
                        {
                            ++possibleDirections;
                        }
                    }

                    if (possibleDirections > 0)
                    {
                        BoardMap.EDirection randomValidDirection = GetRandomValidDirection(validDirection, possibleDirections);

                        // Set this position neighbors unusable
                        boardMap.setNeighborsUnusableIfEmpty(currentPos);

                        // Update current position
                        currentPos = boardMap.GetNextTilePosition(currentPos, randomValidDirection);

                        // assign road to selected tiles
                        boardMap.SetTile(currentPos, BoardMap.ETileType.Road);
                    }
                    else
                    {
                        generationOk = false;
                        Console.Error.WriteLine("Generation Failed");
                        break; //impossible to continue
                    }
                }

                ++currentAttempt;
            } while (!generationOk && currentAttempt < _settings.MaxGenerationAttempts);


            return(boardMap);
        }