Exemplo n.º 1
0
        private void createFirstNode()
        {
            environment.node   firstNode = new environment.node(0, 0);
            environment.region hex       = new environment.region();
            hex.vertices = new PointF[6];

            for (int i = 0; i < 6; i++)
            {
                hex.vertices[i] = new PointF(0 + sideLength * (float)Math.Cos(i * (Math.PI / 3) - ((2 * Math.PI) / 3)), 0 + sideLength * (float)Math.Sin(i * (Math.PI / 3) - ((2 * Math.PI) / 3)));
            }

            firstNode.regions.Add(hex);
            nodeList.Add(firstNode);

            txtbx_nodeCondition.Text = nodeList[selectedNode].condition.ToString();

            displayItems = new List <PointF[]>();
            foreach (environment.node n in nodeList)
            {
                //PointF[] loc = { n.Location };
                //displayItems.Add(loc);
                foreach (environment.region r in n.regions)
                {
                    displayItems.Add(r.vertices);
                }
            }

            updateDisplay();
        }
Exemplo n.º 2
0
        private void genAdjNode_click(object sender, EventArgs e)
        {
            Point newNodeSidePair = new Point(selectedNode, selectedSide);

            nodeAndSideSelect.Add(newNodeSidePair);

            float distBtwnTwoHex = (float)(Math.Sqrt(3) * sideLength);


            environment.node nextNode = new environment.node((float)(nodeList[selectedNode].Location.X + distBtwnTwoHex * Math.Cos(-1 * (Math.PI / 2) + (selectedSide * (Math.PI / 3)))), (float)(nodeList[selectedNode].Location.Y + distBtwnTwoHex * Math.Sin(-1 * (Math.PI / 2) + (selectedSide * (Math.PI / 3)))));

            foreach (environment.node n in nodeList)
            {
                if (Math.Sqrt((Math.Pow(nextNode.Location.X - n.Location.X, 2)) + (Math.Pow(nextNode.Location.Y - n.Location.Y, 2))) < sideLength)
                {
                    return;
                }
            }

            environment.region hex = new environment.region();
            hex.vertices = new PointF[6];

            for (int i = 0; i < 6; i++)
            {
                hex.vertices[i] = new PointF(nextNode.Location.X + sideLength * (float)Math.Cos(i * (Math.PI / 3) - ((2 * Math.PI) / 3)), nextNode.Location.Y + sideLength * (float)Math.Sin(i * (Math.PI / 3) - ((2 * Math.PI) / 3)));
            }

            foreach (environment.node n in nodeList)
            {
                foreach (environment.region r in n.regions)
                {
                    foreach (PointF r_p in r.vertices)
                    {
                        for (int i = 0; i < 6; i++)
                        {
                            if ((hex.vertices[i].X - r_p.X) < (.1) * sideLength && hex.vertices[i].X - r_p.X > -(.1) * sideLength && (hex.vertices[i].Y - r_p.Y) < (.1) * sideLength && (hex.vertices[i].Y - r_p.Y) > -(.1) * sideLength)
                            {
                                hex.vertices[i].X = r_p.X;
                                hex.vertices[i].Y = r_p.Y;
                            }
                        }
                    }
                }
            }

            nextNode.regions.Add(hex);
            nodeList.Add(nextNode);
            selectedNode = nodeList.Count - 1;

            displayItems = new List <PointF[]>();
            foreach (environment.node n in nodeList)
            {
                //PointF[] loc = { n.Location };
                //displayItems.Add(loc);
                foreach (environment.region r in n.regions)
                {
                    displayItems.Add(r.vertices);
                }
            }

            updateDisplay();
        }