Example #1
0
        internal static (bool startMovement, PointI hexToMoveTo) CheckForUnitMovementFromMouseInitiation(Stack stack, object args)
        {
            var(cellGrid, mouseLocation, camera) = (ValueTuple <CellGrid, Point, Camera>)args;

            if (!camera.GetViewport.Contains(mouseLocation))
            {
                return(false, new PointI(0, 0));
            }

            var screenPixelToWorldHex = camera.ScreenPixelToWorldHex(mouseLocation);
            var hexToMoveTo           = new PointI(screenPixelToWorldHex.Col, screenPixelToWorldHex.Row);

            if (hexToMoveTo.Equals(stack.LocationHex))
            {
                return(false, new PointI(0, 0));
            }
            var cellToMoveTo = cellGrid.GetCell(hexToMoveTo);

            if (cellToMoveTo.SeenState == SeenState.NeverSeen)
            {
                return(false, new PointI(0, 0));
            }

            var costToMoveIntoResult = MovementCosts.GetCostToMoveInto(cellToMoveTo, stack.MovementTypes, stack.MovementPoints);

            return(costToMoveIntoResult.CanMoveInto ? (true, hexToMoveTo) : (false, new PointI(0, 0)));
        }
Example #2
0
        internal static (bool startMovement, PointI hexToMoveTo) CheckForUnitMovementFromKeyboardInitiation(Stack stack, object args)
        {
            var key = (Keys)args;

            var direction = key switch
            {
                Keys.NumPad1 => Direction.SouthWest,
                Keys.NumPad2 => Direction.South,
                Keys.NumPad3 => Direction.SouthEast,
                Keys.NumPad4 => Direction.West,
                Keys.NumPad6 => Direction.East,
                Keys.NumPad7 => Direction.NorthWest,
                Keys.NumPad8 => Direction.North,
                Keys.NumPad9 => Direction.NorthEast,
                _ => throw new ArgumentOutOfRangeException()
            };

            var neighbor    = HexLibrary.GetNeighbor(new HexOffsetCoordinates(stack.LocationHex.X, stack.LocationHex.Y), direction);
            var hexToMoveTo = new PointI(neighbor.Col, neighbor.Row);

            if (stack.LocationHex == hexToMoveTo)
            {
                return(false, new PointI(0, 0));
            }

            var costToMoveIntoResult = MovementCosts.GetCostToMoveInto(hexToMoveTo, stack.MovementTypes, stack.MovementPoints);

            return(costToMoveIntoResult.CanMoveInto ? (true, hexToMoveTo) : (false, new PointI(0, 0)));
        }
        internal static List <PointI> DetermineMovementPath(HexLibrary hexLibrary, Stack stack, PointI from, PointI to, CellGrid cellGrid)
        {
            if (from.Equals(to))
            {
                return(new List <PointI>());
            }

            _hexLibrary = hexLibrary;
            AStarSearch <PointI, Cost> mapSolver = new MapSolver();

            mapSolver.GetAllNeighbors = GetAllNeighbors;
            mapSolver.GetDistance     = GetDistance;
            var openList   = new PriorityQueue <AStarSearch <PointI, Cost> .Node>();
            var closedList = new Dictionary <PointI, Cost>();

            mapSolver.Solve(GetCostToMoveIntoFunc, new PointI(cellGrid.NumberOfColumns, cellGrid.NumberOfRows), from, to, openList, closedList);

            var path = mapSolver.Solution;

            return(path);

            GetCostToMoveIntoResult GetCostToMoveIntoFunc(PointI point)
            {
                return(MovementCosts.GetCostToMoveInto(point, stack.MovementTypes, stack.MovementPoints));
            }
        }