Пример #1
0
        static List <Direction> GetAvailableTrollDirections(Troll troll)
        {
            var directions = new List <Direction>();

            if (CheckTrollCouldMeetPlayer(troll, Direction.Up))
            {
                directions.Add(Direction.Up);
                return(directions);
            }
            if (CheckTrollCouldMeetPlayer(troll, Direction.Right))
            {
                directions.Add(Direction.Right);
                return(directions);
            }
            if (CheckTrollCouldMeetPlayer(troll, Direction.Down))
            {
                directions.Add(Direction.Down);
                return(directions);
            }
            if (CheckTrollCouldMeetPlayer(troll, Direction.Left))
            {
                directions.Add(Direction.Left);
                return(directions);
            }

            if (CheckTrollMoveTile(Direction.Up, troll) == Maze.GroundChar)
            {
                directions.Add(Direction.Up);
            }
            if (CheckTrollMoveTile(Direction.Right, troll) == Maze.GroundChar)
            {
                directions.Add(Direction.Right);
            }
            if (CheckTrollMoveTile(Direction.Down, troll) == Maze.GroundChar)
            {
                directions.Add(Direction.Down);
            }
            if (CheckTrollMoveTile(Direction.Left, troll) == Maze.GroundChar)
            {
                directions.Add(Direction.Left);
            }

            return(directions);
        }
Пример #2
0
 static bool CheckTrollCouldMeetPlayer(Troll troll, Direction direction)
 {
     return(Player.AllCharacters.Any(x => x == CheckTrollMoveTile(direction, troll)));
 }
Пример #3
0
        static Direction TrollFindDirectionToPlayer(Troll troll)
        {
            int trollViewingRange = 10;
            int trollViewingWidth = 3;

            //Check up
            for (int i = 1; i < trollViewingRange; i++)
            {
                int x = troll.Location.X;
                int y = troll.Location.Y - i;
                //If there is a player at (x,y)
                if (y < 0)
                {
                    break;
                }
                if (MazeDefault.Map[x, y] == Maze.WallChar)
                {
                    break;
                }
                if (Player.AllCharacters.Any(pChar => pChar == MazeDefault.MapAtTurnStart[x, y]))
                {
                    troll.LastSeenPlayerDirection = Direction.Up;
                    return(Direction.Up);
                }
            }
            //Check down
            for (int i = 1; i < trollViewingRange; i++)
            {
                int x = troll.Location.X;
                int y = troll.Location.Y + i;
                //If there is a player at (x,y)
                if (y > MazeDefault.Map.GetLength(1) - 1)
                {
                    break;
                }
                if (MazeDefault.Map[x, y] == Maze.WallChar)
                {
                    break;
                }
                if (Player.AllCharacters.Any(pChar => pChar == MazeDefault.MapAtTurnStart[x, y]))
                {
                    troll.LastSeenPlayerDirection = Direction.Down;
                    return(Direction.Down);
                }
            }
            //Check left
            for (int i = 1; i < trollViewingRange; i++)
            {
                int x = troll.Location.X - i;
                int y = troll.Location.Y;

                if (x < 0)
                {
                    continue;
                }
                if (MazeDefault.Map[x, y] == Maze.WallChar)
                {
                    break;
                }
                //If there is a player at (x,y)
                if (Player.AllCharacters.Any(pChar => pChar == MazeDefault.MapAtTurnStart[x, y]))
                {
                    troll.LastSeenPlayerDirection = Direction.Left;
                    return(Direction.Left);
                }
            }

            //Check right
            for (int i = 1; i < trollViewingRange; i++)
            {
                int x = troll.Location.X + i;
                int y = troll.Location.Y;

                if (x > MazeDefault.Map.GetLength(0) - 1)
                {
                    break;
                }
                if (MazeDefault.Map[x, y] == Maze.WallChar)
                {
                    break;
                }
                //If there is a player at (x,y)
                if (Player.AllCharacters.Any(pChar => pChar == MazeDefault.MapAtTurnStart[x, y]))
                {
                    troll.LastSeenPlayerDirection = Direction.Right;
                    return(Direction.Right);
                }
            }

            return(Direction.NoDirection);
        }
Пример #4
0
 public Troll(Troll troll)
 {
     Location = troll.Location;
 }