Esempio n. 1
0
    public List <MapPoint> FindPath(MapPoint start, MapPoint finish)
    {
        lenMatrix[start.Row, start.Column] = 0;

        CalcLen(start);

        if (GetPointValue(finish) == int.MaxValue)
        {
            return(null);
        }

        var path     = new List <MapPoint>();
        var minPoint = new MapPoint(finish);

        path.Add(finish);

        while (!start.Equals(minPoint))
        {
            var p = FindMinLenAround(minPoint);

            //Debug.Assert(!p.Equals(minPoint));

            path.Add(p);
            minPoint = p;
        }

        path.Reverse();
        path.RemoveAt(0);

        return(path);
    }
Esempio n. 2
0
        public void TestEquality()
        {
            // set up
            double latitude  = 47.6764385;
            double longitude = 11.8710533;

            // run
            var mapPoint1 = new MapPoint(latitude, longitude);
            var mapPoint2 = new MapPoint(latitude, longitude);
            var mapPoint3 = new MapPoint(latitude, -longitude);
            var mapPoint4 = new MapPoint(0.0, 0.0);

            // check
            Assert.IsTrue(mapPoint1.Equals(mapPoint2), "map points 1 and 2 must be equal");
            Assert.IsTrue(mapPoint1.Equals((object)mapPoint2), "map points 1 and 2 must be equal");
            Assert.IsFalse(mapPoint1.Equals(mapPoint3), "map points 1 and 3 must not be equal");
            Assert.IsFalse(mapPoint1.Equals(mapPoint4), "map point must not be equal to invalid map point");

            MapPoint noPoint = null;

            Assert.IsFalse(mapPoint1.Equals(noPoint), "map point must not be equal to null");

            object noObject = null;

            Assert.IsFalse(mapPoint1.Equals(noObject), "map point must not be equal to null");
            Assert.IsFalse(mapPoint1.Equals("text"), "map point must not be equal to different type");
        }
Esempio n. 3
0
    string GetStrDirection(MapPoint mapPoint)
    {
        if (mapPoint.Equals(GetUpPoint()))
        {
            return(Directions.UP);
        }

        if (mapPoint.Equals(GetDownPoint()))
        {
            return(Directions.DOWN);
        }

        if (mapPoint.Equals(GetLeftPoint()))
        {
            return(Directions.LEFT);
        }

        if (mapPoint.Equals(GetRightPoint()))
        {
            return(Directions.RIGHT);
        }

        throw new ArgumentOutOfRangeException(mapPoint.ToString());
    }
        /// <summary>
        /// Обработка волны в конкретной клетке
        /// </summary>
        /// <param name="Point">Клетка</param>
        /// <param name="WaveValue">Значение волны</param>
        private void Wave(MapPoint Point, UInt16 WaveValue)
        {
            if (endflag)
            {
                return;
            }

            if (Waves[Point.X - Area.Area.Position.X,
                      Point.Y - Area.Area.Position.Y] != UInt16.MaxValue)
            {
                return;
            }

            if (Point.Equals(To.Point))
            {
                endflag = true;
                return;
            }

            Waves[Point.X - Area.Area.Position.X, Point.Y - Area.Area.Position.Y] = WaveValue;

            MapCellState left  = GetMapCell(Point, -1, 0);
            MapCellState right = GetMapCell(Point, +1, 0);
            MapCellState up    = GetMapCell(Point, 0, -1);
            MapCellState down  = GetMapCell(Point, 0, +1);

            if ((left != null) && Area.CheckCellInArea(left) && (left.Place.Passability > 0))
            {
                Wave(left.Point, WaveValue++);
            }

            if ((right != null) && Area.CheckCellInArea(right) && (right.Place.Passability > 0))
            {
                Wave(right.Point, WaveValue++);
            }

            if ((up != null) && Area.CheckCellInArea(up) && (up.Place.Passability > 0))
            {
                Wave(up.Point, WaveValue++);
            }

            if ((down != null) && Area.CheckCellInArea(down) && (down.Place.Passability > 0))
            {
                Wave(down.Point, WaveValue++);
            }
        }
Esempio n. 5
0
    void DoTurn(MapPoint p, bool stepBack = true)
    {
        if (stepBack && !IsControlRoomIsReached)
        {
            Debug("StepStack Len: " + StepsStack.Count);
            StepsStack.Push(p);
            VisitedPoints.Add(p);
        }

        var dir = GetStrDirection(p);

        Console.WriteLine(dir);
        KirkPosition = p;

        if (KirkPosition.Equals(ControlRoomPosition))
        {
            IsControlRoomIsReached = true;
        }
    }
Esempio n. 6
0
        private async Task Tap(GestureSample gesture)
        {
            // try to get a card under the tap first
            var selectedCardIndex = handOfCards.GetCardIndexAtPosition(gesture.Position);

            if (selectedCardIndex != -1)
            {
                // SELECT CARD
                if (CanSelectCardFromSelectedCharacter)
                {
                    selectedCard = selectedCharacter.CurrentHand.ElementAt(selectedCardIndex);
                }
                return;
            }

            var worldPoint      = camera.ScreenToWorld(gesture.Position);
            var mapPoint        = MapPoint.GetFromScreenPosition(worldPoint);
            var targetCharacter = data.Characters.SingleOrDefault(character => character.IsAtPoint(mapPoint));
            var targetEntity    = entities.Drawables.SingleOrDefault(entity => entity.IsAtPoint(mapPoint));

            if (selectedCharacter == null)
            {
                // SELECT CHARACTER
                // we don't have a character selected, so select whatever we have under the tap
                selectedCharacter = targetCharacter;
                SelectedCharacterChange?.Invoke(selectedCharacter);
            }
            else if (selectedCard != null && targetCharacter != null && selectedCard.IsWithinRangeDistance(mapPoint) && mapPoint.IsWithinMap && (lockedInCharacter == selectedCard.OwnerCharacter || lockedInCharacter == null) && targetingPoint == null && IsMyTurn)
            {
                // TRYING TO TARGET A CARD
                targetingPoint = mapPoint;
            }
            else if (targetingPoint?.Equals(mapPoint) == true && IsMyTurn)
            {
                // ACTUALLY PLAY SELECTED CARD
                var playStatus = selectedCharacter.PlayCard(selectedCard, targetCharacter, data.RoundNumber);
                if (!playStatus.PlayCancelled)
                {
                    if (targetCharacter.GetBaseAbilityScore(AbilityScore.Health) < 1)
                    {
                        data.Characters.Remove(targetCharacter);
                        await CheckForWin();
                    }

                    AddNewGameLogEntry(new GameLogEntry
                    {
                        SourceCharacterColour = selectedCharacter.Colour,
                        SourceCharacterSide   = data.Sides[selectedCharacter.OwnerPlayerId],
                        TargetCharacterColour = targetCharacter.Colour,
                        TargetCharacterSide   = data.Sides[targetCharacter.OwnerPlayerId],
                        CardId = selectedCard.Id
                    });

                    lockedInCharacter = selectedCard.OwnerCharacter;
                    selectedCard      = null;
                    targetingPoint    = null;
                }

                var statusText = GetStatusTextForPlay(playStatus);
                if (statusText != null)
                {
                    statusPanel.Show(statusText);
                }
            }
            else if (selectedCard != null)
            {
                // DESELECTED CARD
                // we have a character selected and a card selected but the card isn't in range of the desired target, or there is no target
                selectedCard   = null;
                targetingPoint = null;
            }
            else if (selectedCharacter.IsWithinMoveDistanceOf(mapPoint) && mapPoint.IsWithinMap && mapPoint.IsInAvailableMovement && CanMoveSelectedCharacter && targetEntity == null && movingPoint == null)
            {
                // TRYING TO MOVE
                // we have a character selected, it's my character, it is within move distance of the tap and it has moves remaining
                movingPoint = mapPoint;
            }
            else if (movingPoint?.Equals(mapPoint) == true)
            {
                // ACTUALLY MOVING
                selectedCharacter.Move(mapPoint);
                lockedInCharacter = selectedCharacter;
                movingPoint       = null;
                AddNewGameLogEntry(new GameLogEntry
                {
                    SourceCharacterColour = selectedCharacter.Colour,
                    SourceCharacterSide   = data.Sides[selectedCharacter.OwnerPlayerId],
                    MovedTo = mapPoint
                });
            }
            else
            {
                // DESELECT CHARACTER AND CARD
                // we have a character selected, but didn't tap anything else useful so unselect it
                selectedCharacter = null;
                selectedCard      = null;
                movingPoint       = null;
                targetingPoint    = null;
                handOfCards.ClearCardPositions();
            }
        }
Esempio n. 7
0
    public override bool Equals(object obj)
    {
        MapRect p = obj as MapRect;

        return(p1.Equals(p.p1) && p2.Equals(p.p2));
    }
        /// <summary>
        /// Построить путь из одной клетки в другую
        /// </summary>
        /// <param name="From">Откуда</param>
        /// <param name="To">Куда</param>
        /// <returns>Путь</returns>
        public MapPoint[] CalcPath(MapPoint From, MapPoint To)
        {
            if (!Area.CheckCellInArea(From))
            {
                throw new ArgumentOutOfRangeException("From", "From cannot be out of Area");
            }
            if (!Area.CheckCellInArea(To))
            {
                throw new ArgumentOutOfRangeException("To", "To cannot be out of Area");
            }

            lock (locker)
            {
                UInt16 level = From.Level;

                // пересчитываем волны
                Waves = new UInt16[Height, Width];
                for (int i = 0; i < Height; i++)
                {
                    for (int j = 0; j < Width; j++)
                    {
                        Waves[i, j] = UInt16.MaxValue;
                    }
                }
                endflag = false;
                Wave(From, 0);

                MapPoint        current = To;
                List <MapPoint> path    = new List <MapPoint>();

                while (!current.Equals(From))
                {
                    int X = current.X - Area.Area.Position.X;
                    int Y = current.Y - Area.Area.Position.Y;
                    if (X + 1 < Width && Waves[X, Y] > Waves[X + 1, Y])
                    {
                        current = new MapPoint(current, 1, 0);
                    }
                    else
                    if (Y + 1 < Height && Waves[X, Y] > Waves[X, Y + 1])
                    {
                        current = new MapPoint(current, 0, 1);
                    }
                    else
                    if (Y - 1 >= 0 && Waves[X, Y] > Waves[X, Y - 1])
                    {
                        current = new MapPoint(current, 0, -1);
                    }
                    else
                    if (X - 1 >= 0 && Waves[X, Y] > Waves[X - 1, Y])
                    {
                        current = new MapPoint(current, -1, 0);
                    }

                    path.Add(current);
                }

                path.Reverse();
                return(path.ToArray());
            }
        }