示例#1
0
        //----------------------------------------------------------------------------
        //              Get Path Value
        //----------------------------------------------------------------------------

        /// <summary>
        /// GetPathValue checks if a hex has been visited before. <para/>
        /// If it has, return the original PathValue <para/>
        /// Otherwise, construct a new PathValue
        ///
        /// </summary>
        public IPathValue GetPathValue(IHexagon hex)
        {
            if (PathValueDict.ContainsKey(hex))
            {
                return(PathValueDict[hex]);
            }
            else
            {
                Vector3    centre = (Destination.HexTransform.position + Start.HexTransform.position) / 2;
                IPathValue myPath = new PathValue(400000, HexMath.FindDistance(hex, Destination), centre, hex, null);
                PathValueDict.Add(hex, myPath);
                return(myPath);
            }
        }
示例#2
0
        //----------------------------------------------------------------------------
        //              Generate Path
        //----------------------------------------------------------------------------

        #region GeneratePath

        /// <summary>
        /// Generic A* pathfinding, hex distance as heuristic
        /// </summary>
        public MapPath GeneratePath(IHexagon hex_a, IHexagon hex_b)
        {
            SortedSet <IPathValue> openSet = new SortedSet <IPathValue>();

            PathValueDict = new Dictionary <IHexagon, IPathValue>();

            Start       = hex_a;
            Destination = hex_b;

            IPathValue firstPath = GetPathValue(hex_a);

            firstPath.SetFirstPathDistance();

            openSet.Add(firstPath);
            while (openSet.Count != 0)
            {
                IPathValue currentPath = openSet.Min;
                openSet.Remove(currentPath);

                IHexagon currentHex = currentPath.Hex;


                if (currentHex.MyHexMap.CoOrds == hex_b.MyHexMap.CoOrds)
                {
                    return(currentPath.ReconstructPath());
                }


                foreach (IHexagon neighbour in currentHex.MyHexMap.Neighbours)
                {
                    if (!neighbour.MyHexMap.IsOccupied())
                    {
                        IPathValue neighbourPath = GetPathValue(neighbour);
                        int        newGScore     = currentPath.Score_g + neighbour.MyHexMap.MovementCost;
                        if (newGScore < neighbourPath.Score_g)
                        {
                            if (openSet.Contains(neighbourPath))
                            {
                                openSet.Remove(neighbourPath);
                            }

                            neighbourPath.UpdateValues(newGScore, currentPath);
                            openSet.Add(neighbourPath);
                        }
                    }
                }
            }
            return(null);
        }
示例#3
0
        public void HighlightPath(IHexagon ihexagon)
        {
            MapPath path = MyMapPathfinding.GeneratePath(CurrentIHasTurn.MyHexContents.Location, ihexagon);

            path.PathStack.Pop();
            foreach (IHexagon hex in HexesInRange)
            {
                hex.Interaction.ChangeColor(Color.red);
            }

            MyMovement.LookAtHexHover(path.PathStack.Peek(), CurrentIHasTurn.MyHexContents.ContentTransform);

            while (path.PathStack.Count != 0)
            {
                IHexagon toHighlight = path.PathStack.Pop();
                toHighlight.Interaction.ChangeColor(Color.blue);
            }
        }
示例#4
0
        //----------------------------------------------------------------------------
        //              Hexes in Range
        //----------------------------------------------------------------------------

        /// <summary>
        /// This is an almost direct copy of above, but it sets the heuristic distance to
        /// to the start location <para/>
        ///
        /// So in practice it is Dijkstra's out until range
        /// </summary>
        public HashSet <IHexagon> GetHexesInRange(IHexagon start, int range)
        {
            SortedSet <IPathValue> openSet      = new SortedSet <IPathValue>();
            HashSet <IHexagon>     hexesInRange = new HashSet <IHexagon>();

            PathValueDict = new Dictionary <IHexagon, IPathValue>();

            Destination = start;
            Start       = start;

            IPathValue firstPath = GetPathValue(start);

            firstPath.SetFirstPathDistance();

            openSet.Add(firstPath);
            while (openSet.Count != 0)
            {
                IPathValue currentPath = openSet.Min;
                openSet.Remove(currentPath);

                IHexagon currentHex = currentPath.Hex;
                hexesInRange.Add(currentHex);

                foreach (IHexagon neighbour in currentHex.MyHexMap.Neighbours)
                {
                    if (!neighbour.MyHexMap.IsOccupied())
                    {
                        IPathValue neighbourPath = GetPathValue(neighbour);
                        int        newGScore     = currentPath.Score_g + neighbour.MyHexMap.MovementCost;
                        if (newGScore < neighbourPath.Score_g && newGScore <= range)
                        {
                            if (openSet.Contains(neighbourPath))
                            {
                                openSet.Remove(neighbourPath);
                            }

                            neighbourPath.UpdateValues(newGScore, currentPath);
                            openSet.Add(neighbourPath);
                        }
                    }
                }
            }
            return(hexesInRange);
        }
        public void find_straight_distance()
        {
            GameObject    gameObject    = new GameObject();
            MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>();

            mapGeneration.HexagonPrefab = new GameObject();
            mapGeneration.MapRadius     = 10;

            mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>();
            mapGeneration.GenerateMap();
            mapGeneration.UpdateHexNeighbours();

            IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)];
            IHexagon end_hex   = mapGeneration.HexDict[new Vector3Int(0, -4, 4)];


            int distance = 4;

            Assert.AreEqual(distance, HexMath.FindDistance(start_hex, end_hex));
        }
示例#6
0
        }//GetCircleProperties

        internal static IHexagon GetHexagonePropertis()
        {
            IHexagon hexagone = Factory.GetInstanceIHexagone();
            Point    center   = new Point();

            /* get input from user center*/
            Console.Write("Enter co-ordinates center (x,y): ");
            string coOrdinate = Console.ReadLine();

            string[] coOrdinateValues = coOrdinate.Split(',');
            /* parsing check and setting null if parsing fails */
            int parseStorageX = 0, parseStorageY = 0;

            if (coOrdinateValues.Count() == 2 && InputValidator.IsInt(coOrdinateValues[0], ref parseStorageX) & InputValidator.IsInt(coOrdinateValues[1], ref parseStorageY))
            {
                center.X        = parseStorageX;
                center.Y        = parseStorageY;
                hexagone.center = center;
            }
            else
            {
                hexagone = null;
                return(hexagone);
            }

            /* user input for side length */
            Console.Write("Enter side length of hexagone: ");
            int storage;

            if (int.TryParse(Console.ReadLine(), out storage))
            {
                hexagone.side = storage;
            }
            else
            {
                hexagone = null;
                return(hexagone);
            }
            return(hexagone);
        }
示例#7
0
        public void path_value_id_is_less_than()
        {
            GameObject gameObject = new GameObject();
            IHexagon   hex1       = Substitute.For <IHexagon>();
            Vector3Int coords1    = new Vector3Int(0, -1, -1);

            hex1.MyHexMap.CoOrds.Returns(coords1);
            hex1.HexTransform.Returns(gameObject.transform);

            IHexagon   hex2    = Substitute.For <IHexagon>();
            Vector3Int coords2 = new Vector3Int(1, 0, -1);

            hex2.MyHexMap.CoOrds.Returns(coords2);
            hex2.HexTransform.Returns(gameObject.transform);

            Vector3   centre = new Vector3(0, 0, 0);
            PathValue path1  = new PathValue(4, 4, centre, hex1, null);
            PathValue path2  = new PathValue(4, 4, centre, hex2, null);


            Assert.AreEqual(path1.CompareTo(path2), -1);
        }
 public HexMap(IHexagon hexagon)
 {
     MyHexagon = hexagon;
 }
 public void IHexagonUnhovered(IHexagon hexagon)
 {
 }
示例#10
0
 public override void Register(HexagonControlMachine machine)
 {
     _Controlable     = machine;
     _AbstractHexagon = machine;
 }
示例#11
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            logger.Debug("Programm starts ");
            int userChoice;

            /* Menu for user */
            Console.Write("\n\n---------------MENU---------------\n1.Line\n2.Circle\n3.Rectangle\n4.Triangle\n5.Hexagone\n6.Exit\nEnter Choice: ");

            userChoice = int.Parse(Console.ReadLine());
            switch (userChoice)
            {
            case 1:    /* Line drawing */
                try
                {
                    ILine line = Factory.GetInstanceILine();
                    line = UserInput.GetLineCoordinate();

                    line.DrawLine();
                    logger.Info("line draw successful");
                }
                catch (Exception exception)
                {
                    logger.Error("in line Draw exception: " + exception.ToString());
                    Console.WriteLine("in line Draw exception: " + exception.ToString());
                    Console.ReadLine();
                }
                break;

            case 2:    /* Circle drawing */
                try
                {
                    ICircle circle = Factory.GetInstanceICircle();
                    circle = UserInput.GetCircleProperties();

                    circle.DrawCircle();

                    logger.Info("line draw successful");
                }
                catch (Exception exception)
                {
                    logger.Error("in circle Draw exception: " + exception.ToString());
                }

                break;

            case 3:    /* Rectangle drawing */
                try
                {
                    IRectangle rectangle = Factory.GetInstanceIRectangle();

                    rectangle = UserInput.GetRectangleDiagonal();

                    rectangle.DrawRectangle();

                    logger.Info("line draw successful");
                }
                catch (Exception exception)
                {
                    logger.Error("in rectangle Draw exception: " + exception.ToString());
                }
                break;

            case 4:
                try
                {
                    ITriangle triangle = Factory.GetInstanceITriangle();

                    triangle = UserInput.GetTrianglePoints();

                    triangle.DrawTriangle();

                    logger.Info("triangle draw successful");
                }
                catch (Exception exception)
                {
                    logger.Error("in triangle Draw exception: " + exception.ToString());
                }
                break;

            case 5:
                try
                {
                    IHexagon hexagone = Factory.GetInstanceIHexagone();

                    hexagone = UserInput.GetHexagonePropertis();

                    hexagone.DrawHexagon();

                    logger.Info("hexagone draw successful");
                }
                catch (Exception exception)
                {
                    logger.Error("in hexagone Draw exception: " + exception.ToString());
                }
                break;

            case 6:    /* Exit */
                Console.WriteLine("\nThank you come again!!!");
                break;

            default:
                Console.WriteLine("\nInvalid input");
                break;
            }
        }
示例#12
0
 private void _DeleteHex(IHexagon hex)
 {
     ((IHexagonRestricted)hex).MyHexKeep.DeleteHex();
 }
示例#13
0
 private bool _ShouldDeleteThisHex(IHexagon hex)
 {
     return(((IHexagonRestricted)hex).MyHexKeep.ShouldRemove);
 }
示例#14
0
 /// <summary>
 /// Turn the hexes light green. <para/>
 /// Which is the color they normally are when not hovered.
 /// </summary>
 public void MouseUnhover(IHexagon hexagon)
 {
     hexagon.Interaction.ChangeColor(ClickableColor);
 }
示例#15
0
        //----------------------------------------------------------------------------
        //                   Mouse Hovering
        //----------------------------------------------------------------------------

        #region Mouse Hovering

        /// <summary>
        /// Turn the hexes dark green when the mouse is over them
        /// </summary>
        public void MouseHover(IHexagon hexagon)
        {
            hexagon.Interaction.ChangeColor(HoverColor);
        }
示例#16
0
 public HexagonForm(IHexagon hexagon)
 {
     InitializeComponent();
     this.hexagon = hexagon;
     this.Paint  += new PaintEventHandler(this.HexagoneForm_Paint);
 }