示例#1
0
        public override bool Link(BaseLevel level, out BaseTrack[] results)
        {
            if (_direction != Direction.None)
            {
                results = null;
                return false;
            }

            results = level.GetTracksFacing(_position, Direction.East);

            bool valid = (results.Length != 0);
            if (valid)
                _next = results[0];

            return valid;
        }
示例#2
0
        public override bool Link(BaseLevel level, out BaseTrack[] results)
        {
            if (_direction != Direction.None)
            {
                results = null;
                return false;
            }

            results = targets = level.GetTracksFacing(_position,
                Direction.North,
                Direction.South);

            bool valid = (targets.Length == 2);
            if (!valid)
                throw new LevelLoadException("This type of switch must have exactly two targets.");

            return valid;
        }
示例#3
0
        private void LinkTrack(BaseTrack current, ref List<BaseTrack> visited)
        {
            if (visited.Contains(current))
                return;

            BaseTrack[] results;
            if(current.Link(this, out results))
            {
                foreach (BaseTrack result in results)
                    LinkTrack(result, ref visited);
            }

            visited.Add(current);
        }
示例#4
0
        private void Move()
        {
            if (_disposed)
                return;
            else if(firstTick && !IgnoreTick)
            {
                firstTick = false;
                return;
            }

            var cur = Current;
            var next = Current?.Next;

            if (cur == null)
            {
                _disposed = true;
                return;
            }
            else if(next != null && !next.CanEnter(this))
            {
                // Quick n' dirty
                if (next is SwitchTrack)
                    return;

                if (!next.Collides() && cur.Collides())
                    throw new GameOverException();
                else if (next.Collides())
                    throw new GameOverException();
            }
            else if (next != null && next.CanEnter(this))
            {
                _current.OnLeave();

                _current = next;
                _current.OnEnter(this);
            }
        }