Exemple #1
0
        /// <summary>
        /// <see cref="Intention"/>が<see cref="Intentions.Move"/>または<see cref="Intentions.Remove"/>の時に次に行く座標を返します
        /// マップの領域等は考慮しません
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        public Point GetNextPoint(Point current)
        {
            if (Intention != Intentions.Stay)
            {
                current = current.Move(Direction);
            }

            return(current);
        }
Exemple #2
0
        /// <summary>
        /// 指定した点を中心として移動した方向がフィールド内であるかを判定します
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        protected bool IsInField(Point point, Direction direction)
        {
            var p = point.Move(direction);

            if (p.X < 0 || p.Y < 0 || p.X >= Field.Width || p.Y >= Field.Height)
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 現在位置を含まず<paramref name="wayPoints"/>を経由して移動するルートを計算します
        /// </summary>
        /// <param name="wayPoints">経由する位置</param>
        public List <(Point, Direction)> Way(params Point[] wayPoints)
        {
            List <(Point, Direction)> move = new List <(Point, Direction)>();

            Point last = this;

            foreach (var p in wayPoints)
            {
                var delta = p - last;
                int moveX = Math.Abs(delta.X), moveY = Math.Abs(delta.Y);
                int count = Math.Max(moveX, moveY);

                for (int i = 0; count > i; i++)
                {
                    Direction direction = Direction.None;

                    if (moveX-- > 0)
                    {
                        if (delta.X > 0)
                        {
                            direction |= Direction.Right;
                        }
                        else if (delta.X < 0)
                        {
                            direction |= Direction.Left;
                        }
                    }

                    if (moveY-- > 0)
                    {
                        if (delta.Y > 0)
                        {
                            direction |= Direction.Down;
                        }
                        else if (delta.Y < 0)
                        {
                            direction |= Direction.Up;
                        }
                    }

                    last = last.Move(direction);
                    move.Add((last, direction));
                }
            }

            return(move);
        }