예제 #1
0
파일: DrawBack.cs 프로젝트: allenm84/mg-feh
        public override IEnumerable <IMove> ValidMovesFor(MapCellLocation location, HeroState owner, HeroState target, MapState map)
        {
            // can the target move to the cell we're on?
            if (map.CanMoveTo(target, location, out MapCellState currentCell))
            {
                yield break;
            }

            // if the target can move to my position, I need to be able to move
            // in the same direction to the next cell
            var(dr, dc)    = MapCellLocation.Diff(location, target.Location);
            (int r, int c) = location;
            if (map.CanMoveTo(owner, (r + dr, c + dc), out MapCellState desiredCell))
            {
                var moveTargetBack = new MoveHeroTo(target, 1, currentCell, map);
                var moveMeBack     = new MoveHeroTo(owner, 1, desiredCell, map);
                yield return(new AggregateMove(moveMeBack, moveTargetBack));
            }
        }
예제 #2
0
파일: Swap.cs 프로젝트: allenm84/mg-feh
        public override IEnumerable <IMove> ValidMovesFor(MapCellLocation location, HeroState owner, HeroState target, MapState map)
        {
            // can the owner move to the target's position?
            if (!map.CanMoveTo(owner, target.Location, out MapCellState targetCell))
            {
                yield break;
            }

            // can the target move to the owner's position?
            if (!map.CanMoveTo(target, location, out MapCellState ownerCell))
            {
                yield break;
            }

            // the swap can be done!
            var moveOwnerToTarget = new MoveHeroTo(owner, 1, targetCell, map);
            var moveTargetToOwner = new MoveHeroTo(target, 1, ownerCell, map);

            yield return(new AggregateMove(moveOwnerToTarget, moveTargetToOwner));
        }