示例#1
0
        private static Message ChaseTarget(Tile target, Tile chaser, TileSet statics)
        {
            var movementVector = chaser.Location.NormalizedVector(target.Location);

            var bestMove = new[]{
                chaser.Location + new Point(0, movementVector.Y), //vertical
                chaser.Location + new Point(movementVector.X, 0)} //horizontal
                    .OrderBy(m => m.Distance(target.Location)) // order on distance from player
                    .FirstOrDefault(m => !statics.CollisionDetection(chaser, m).Collision); //pick first where there is no collision

            return bestMove != default(Point)
                ? chaser.BuildMoveMessage(bestMove)
                : null;
        }
示例#2
0
        public void SetupBehaviours(TileSet mobiles, TileSet statics, List<Func<Message, Message>> gameMessageReactor)
        {
            var player = mobiles.WithName(GameConstants.PLAYER);
            var chaseBehaviour = MonsterAi.ChasePlayer(player, statics);

            //Setup player behaviour
            player.OnCollision.Add(collision => EatenByMonster(player, collision));
            player.OnCollision.Add(collision => CrushedByBoulder(player, collision));
            player.OnCollision.Add(collision => FellInHole(player, collision));

            //Setup strong monster behaviour
            mobiles.WithType(GameConstants.STRONG_MONSTER).AddUpdateBehaviour(chaseBehaviour);
            mobiles.WithType(GameConstants.STRONG_MONSTER).AddCollisionRules(
                strongMonster => collision => CrushedByBoulder(strongMonster, collision));
            mobiles.WithType(GameConstants.STRONG_MONSTER).AddCollisionRules(
                strongMonster => collision => FellInHole(strongMonster, collision));

            //Setup weak monster behaviour
            mobiles.WithType(GameConstants.WEAK_MONSTER).AddUpdateBehaviour(chaseBehaviour);
            mobiles.WithType(GameConstants.WEAK_MONSTER).AddCollisionRules(
                weakMonster => collision => CrushedByBoulder(weakMonster, collision));
            mobiles.WithType(GameConstants.WEAK_MONSTER).AddCollisionRules(
                weakMonster => collision => FellInHole(weakMonster, collision));
            mobiles.WithType(GameConstants.WEAK_MONSTER).AddCollisionRules(
                weakMonster => collision => EatenByMonster(weakMonster, collision));

            mobiles.WithType(GameConstants.PORTAL).AddCollisionRules(portal => collision => portal.BuildLevelCompleteMessage());

            gameMessageReactor.Add(message =>
                (Deaded(message, GameConstants.WEAK_MONSTER) || Deaded(message, GameConstants.PLAYER) || Deaded(message, GameConstants.STRONG_MONSTER))
                    ? statics[mobiles.WithName(message.Name).Location].BuildSplatMessage() : null);

            gameMessageReactor.Add(message =>
                Deaded(message, GameConstants.HOLE)
                    ? statics[mobiles.WithName(message.Name).Location].BuildCrashMessage() : null);

            //Setup boulder behaviour
            mobiles.WithType(GameConstants.BOULDER).AddCollisionRules(boulder => collision => Pushed(boulder,collision));
            mobiles.WithType(GameConstants.BOULDER).AddCollisionRules(boulder => collision => FellInHole(boulder,collision));

            //Setup hole behaviour
            mobiles.WithType(GameConstants.HOLE).AddCollisionRules(boulder => collision => CrushedByBoulder(boulder,collision));
        }
示例#3
0
 public MessageHandler(TileSet mobiles)
 {
     _mobiles = mobiles;
 }
示例#4
0
 public static Tile WithName(this TileSet tileSet, string name)
 {
     return(tileSet.Tiles.FirstOrDefault(m => m.Name == name));
 }
示例#5
0
 public static IEnumerable <Tile> GetActiveTiles(this TileSet tileSet)
 {
     return(tileSet.Tiles.Where(m => m.IsActive));
 }
示例#6
0
 public static IEnumerable <Tile> WithType(this TileSet tileSet, string type)
 {
     return(tileSet.Tiles.Where(m => m.Type == type));
 }
 public MessageHandler(TileSet mobiles, TileSet statics)
 {
     _mobiles = mobiles;
     _statics = statics;
 }