コード例 #1
0
        public void ExecuteAiBehaviour()
        {
            var adjacentTileDictionary = CharacterProcessor.GetValidTileMoves(Position);

            var playerPosition = GameState.PacmanCharacter.Position;

            var xDiff = playerPosition.XPos - Position.XPos;
            var yDiff = playerPosition.YPos - Position.YPos;



            if (xDiff > 0 && adjacentTileDictionary.ContainsKey(Direction.South))
            {
                Direction = Direction.South;
            }
            else if (xDiff < 0 && adjacentTileDictionary.ContainsKey(Direction.North))
            {
                Direction = Direction.North;
            }
            else if (yDiff > 0 && adjacentTileDictionary.ContainsKey(Direction.East))
            {
                Direction = Direction.East;
            }
            else if (yDiff < 0 && adjacentTileDictionary.ContainsKey(Direction.West))
            {
                Direction = Direction.West;
            }
        }
コード例 #2
0
        public void ExecuteAiBehaviour()
        {
            var validAdjacentTileMoveDictionary = CharacterProcessor.GetValidTileMoves(Position);

            var random = new Random();

            if (!validAdjacentTileMoveDictionary.ContainsKey(Direction) || validAdjacentTileMoveDictionary.Count > 2)
            {
                Direction = validAdjacentTileMoveDictionary.ElementAt(random.Next(0, validAdjacentTileMoveDictionary.Count)).Key;
            }
        }