/// <summary>
        /// Create a new instance of the <see cref="ControlSquareGrid"/> class.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="squareSize"></param>
        public ControlSquareGrid(Map map, float squareSize)
        {
            int nodeCountX = map.Width;
            int nodeCountY = map.Height;

            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            // Setup the position of the control nodes.
            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; ++x)
            {
                for (int y = 0; y < nodeCountY; ++y)
                {
                    Vector3 position = new Vector3(-mapWidth / 2f + x * squareSize + squareSize / 2f, 0,
                        -mapHeight / 2f + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(position, map.GetValueAtLocation(x, y) == 1, squareSize);
                }
            }

            // Setup the control squares given each of the four control nodes.
            grid = new ControlSquare[nodeCountX - 1, nodeCountY - 1];

            for (int x = 0; x < nodeCountX - 1; ++x)
            {
                for (int y = 0; y < nodeCountY - 1; ++y)
                {
                    grid[x, y] = new ControlSquare(controlNodes[x, y + 1], controlNodes[x + 1, y + 1],
                        controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Build the map.
        /// </summary>
        private void BuildMap()
        {
            // Create the map.
            map = new Map(width, height);

            map.Randomize(fillPercentage);

            for (int i = 0; i < 5; ++i)
            {
                map.Smooth();
            }

            map.AddBorder();

            // Create the control grid from the map.
            grid = new ControlSquareGrid(map, 1);
        }
Exemplo n.º 3
0
 private void ChangeLevel(Map newMap)
 {
     scenePainter.ChangeLevel(newMap);
     timer.Start();
     scaledViewPanel.Invalidate();
 }
Exemplo n.º 4
0
 private void UpdateLinksColors(Map level, List<LinkLabel> linkLabels)
 {
     foreach (var linkLabel in linkLabels)
         linkLabel.LinkColor = linkLabel.Tag == level ? Color.LimeGreen : Color.White;
 }