Esempio n. 1
0
        public override Direction WayToMove()
        {
            if (Spot.GetType().Equals(typeof(StartPoint)))
            {
                return(Direction.Right);
            }

            if (Spot.GetType().Equals(typeof(Storage)))
            {
                if (Spot.FieldToLeft.GetType().Equals(typeof(EmptyField)))
                {
                    return(Direction.nulldirection);
                }

                if (Spot.FieldToLeft.IsEmpty())
                {
                    return(Direction.Left);
                }
            }

            if (Spot.GetType().Equals(typeof(Rail)))
            {
                if (Spot.FieldToLeft == null)
                {
                    return(Direction.Remove);
                }

                if (Spot.FieldToLeft.GetType().Equals(typeof(Storage)) && Spot.FieldToLeft.Content != null)
                {
                    return(Direction.nulldirection);
                }

                if (Spot.FieldAbove.GetType().Equals(typeof(Water)) || Spot.FieldAbove.GetType().Equals(typeof(Dock)))
                {
                    return(Direction.Left);
                }

                if (Spot.FieldAbove.GetType().Equals(typeof(Rail)) && Spot.FieldToLeft.FieldToLeft.FieldToLeft.GetType().Equals(typeof(Storage)))
                {
                    return(Direction.Left);
                }

                if (Spot.FieldAbove.GetType().Equals(typeof(Rail)) && Spot.FieldBelow.GetType().Equals(typeof(Switch)) &&
                    Spot.FieldToRight.GetType().Equals(typeof(EmptyField)) && Spot.FieldToRight.FieldToRight.GetType().Equals(typeof(EmptyField)))
                {
                    return(Direction.Up);
                }

                if (Spot.FieldToRight.GetType().Equals(typeof(Rail)))
                {
                    Field targetField = Spot.NeighbourInDirection(Direction.Right);
                    if (!targetField.IsEmpty())
                    {
                        return(Direction.nulldirection);
                    }
                    if (targetField.IsEmpty() && !targetField.GetType().Equals(typeof(EmptyField)))
                    {
                        return(Direction.Right);
                    }
                    else
                    {
                        return(Direction.nulldirection);
                    }
                }
                if (Spot.FieldAbove.GetType().Equals(typeof(Switch)))
                {
                    Field targetField = Spot.NeighbourInDirection(Direction.Up);

                    if (targetField.ToChar().Equals('\\'))
                    {
                        return(Direction.nulldirection);
                    }
                    ;
                    if (targetField.ToChar().Equals('/'))
                    {
                        return(Direction.Up);
                    }
                    else
                    {
                        return(Direction.nulldirection);
                    }
                }
                if (Spot.FieldBelow.GetType().Equals(typeof(Switch)))
                {
                    Field targetField = Spot.NeighbourInDirection(Direction.Down);

                    if (targetField.ToChar().Equals('\\'))
                    {
                        return(Direction.Down);
                    }
                    if (targetField.ToChar().Equals('/'))
                    {
                        return(Direction.nulldirection);
                    }
                    else
                    {
                        return(Direction.nulldirection);
                    }
                }
                if (Spot.FieldToRight.GetType().Equals(typeof(Switch)))
                {
                    Field targetField = Spot.NeighbourInDirection(Direction.Right);

                    if (targetField.ToChar().Equals('S'))
                    {
                        return(Direction.nulldirection);
                    }
                    else
                    {
                        return(Direction.Right);
                    }
                }

                if (Spot.FieldToRight.GetType().Equals(typeof(EmptyField)) && Spot.FieldBelow.GetType().Equals(typeof(EmptyField)) &&
                    !Spot.FieldToLeft.FieldToLeft.FieldToLeft.GetType().Equals(typeof(Storage)))
                {
                    return(Direction.Up);
                }

                if (Spot.FieldToRight.GetType().Equals(typeof(EmptyField)) && Spot.FieldToLeft.GetType().Equals(typeof(EmptyField)))
                {
                    return(Direction.Up);
                }

                if (Spot.FieldBelow.GetType().Equals(typeof(Rail)) && Spot.FieldAbove.GetType().Equals(typeof(EmptyField)))
                {
                    return(Direction.Down);
                }
            }

            if (Spot.GetType().Equals(typeof(Switch)))
            {
                Field targetField = Spot.NeighbourInDirection(Direction.Down);
                if (Spot.FieldToRight.GetType().Equals(typeof(Rail)))
                {
                    return(Direction.Right);
                }

                Switch field = (Switch)Spot;
                if (field.ToDirection().Equals(SwitchDirection.UP))
                {
                    return(Direction.Up);
                }
                if (field.ToDirection().Equals(SwitchDirection.DOWN))
                {
                    return(Direction.Down);
                }
            }
            return(Direction.nulldirection);
        }
Esempio n. 2
0
        public override Direction WayToMove()
        {
            if (Spot.GetType().Equals(typeof(Start)))
            {
                return(Direction.Right);
            }

            if (Spot.GetType().Equals(typeof(Warehouse)))
            {
                if (Spot.TileToLeft.GetType().Equals(typeof(EmptyTile)))
                {
                    return(Direction.Still);
                }

                if (Spot.TileToLeft.IsEmpty())
                {
                    return(Direction.Left);
                }
            }

            if (Spot.GetType().Equals(typeof(Track)))
            {
                if (Spot.TileToLeft == null)
                {
                    return(Direction.Remove);
                }

                if (Spot.TileToLeft.GetType().Equals(typeof(Warehouse)) && Spot.TileToLeft.Content != null)
                {
                    return(Direction.Still);
                }

                if (Spot.TileAbove.GetType().Equals(typeof(Water)) || Spot.TileAbove.GetType().Equals(typeof(Dock)))
                {
                    return(Direction.Left);
                }

                if (Spot.TileAbove.GetType().Equals(typeof(Track)) && Spot.TileToLeft.TileToLeft.TileToLeft.GetType().Equals(typeof(Warehouse)))
                {
                    return(Direction.Left);
                }

                if (Spot.TileAbove.GetType().Equals(typeof(Track)) && Spot.TileBelow.GetType().Equals(typeof(Switch)) &&
                    Spot.TileToRight.GetType().Equals(typeof(EmptyTile)) && Spot.TileToRight.TileToRight.GetType().Equals(typeof(EmptyTile)))
                {
                    return(Direction.Up);
                }

                if (Spot.TileToRight.GetType().Equals(typeof(Track)))
                {
                    Tile targetTile = Spot.NeighbourInDirection(Direction.Right);
                    if (!targetTile.IsEmpty())
                    {
                        return(Direction.Still);
                    }
                    if (targetTile.IsEmpty() && !targetTile.GetType().Equals(typeof(EmptyTile)))
                    {
                        return(Direction.Right);
                    }
                    else
                    {
                        return(Direction.Still);
                    }
                }
                if (Spot.TileAbove.GetType().Equals(typeof(Switch)))
                {
                    Tile targetTile = Spot.NeighbourInDirection(Direction.Up);

                    if (targetTile.ToChar().Equals('\\'))
                    {
                        return(Direction.Still);
                    }
                    ;
                    if (targetTile.ToChar().Equals('/'))
                    {
                        return(Direction.Up);
                    }
                    else
                    {
                        return(Direction.Still);
                    }
                }
                if (Spot.TileBelow.GetType().Equals(typeof(Switch)))
                {
                    Tile targetTile = Spot.NeighbourInDirection(Direction.Down);

                    if (targetTile.ToChar().Equals('\\'))
                    {
                        return(Direction.Down);
                    }
                    if (targetTile.ToChar().Equals('/'))
                    {
                        return(Direction.Still);
                    }
                    else
                    {
                        return(Direction.Still);
                    }
                }
                if (Spot.TileToRight.GetType().Equals(typeof(Switch)))
                {
                    Tile targetTile = Spot.NeighbourInDirection(Direction.Right);

                    if (targetTile.ToChar().Equals('S'))
                    {
                        return(Direction.Still);
                    }
                    else
                    {
                        return(Direction.Right);
                    }
                }

                if (Spot.TileToRight.GetType().Equals(typeof(EmptyTile)) && Spot.TileBelow.GetType().Equals(typeof(EmptyTile)) &&
                    !Spot.TileToLeft.TileToLeft.TileToLeft.GetType().Equals(typeof(Warehouse)))
                {
                    return(Direction.Up);
                }

                if (Spot.TileToRight.GetType().Equals(typeof(EmptyTile)) && Spot.TileToLeft.GetType().Equals(typeof(EmptyTile)))
                {
                    return(Direction.Up);
                }

                if (Spot.TileBelow.GetType().Equals(typeof(Track)) && Spot.TileAbove.GetType().Equals(typeof(EmptyTile)))
                {
                    return(Direction.Down);
                }
            }

            if (Spot.GetType().Equals(typeof(Switch)))
            {
                Tile targetTile = Spot.NeighbourInDirection(Direction.Down);
                if (Spot.TileToRight.GetType().Equals(typeof(Track)))
                {
                    return(Direction.Right);
                }

                Switch Tile = (Switch)Spot;
                if (Tile.ToDirection().Equals(SwitchDirection.UP))
                {
                    return(Direction.Up);
                }
                if (Tile.ToDirection().Equals(SwitchDirection.DOWN))
                {
                    return(Direction.Down);
                }
            }
            return(Direction.Still);
        }