Пример #1
0
    public void Pursuit()
    {
        int               currentSpaceOnPursuitPath = 0;
        SpaceModel        target = playerPursuing.GetSpace();
        PlayerModel       playerScan;
        List <SpaceModel> targetPath = new List <SpaceModel>();

        targetPath.AddRange(AStarPathfinding.GetPathToDestination(pirateModel.GetSpace(), target));

        // Oisín Notes: Add a for loop here, and checks for if the player is in range?
        for (int i = 0; i < (pirateModel.GetMaxMovement()); i++)
        {
            {
                playerScan = GetPlayerPursuit();
                if (playerScan != null)
                {
                    i = (pirateModel.GetMaxMovement());
                }
                else
                {
                    int nextSpace = currentSpaceOnPursuitPath + 1;
                    if (nextSpace == targetPath.Count)
                    {
                        nextSpace = 0;
                    }
                    while (targetPath[nextSpace].GetMovementCost() > 99)
                    {
                        i += targetPath[nextSpace].GetNormalMovementCost() - 1;
                        nextSpace++;
                        if (nextSpace == targetPath.Count)
                        {
                            nextSpace = 0;
                        }
                    }
                    i += targetPath[nextSpace].GetMovementCost() - 1;
                    if (i <= (pirateModel.GetMaxMovement()))
                    {
                        currentSpaceOnPursuitPath = nextSpace;
                        pirateModel.UpdatePirateLocation(targetPath[currentSpaceOnPursuitPath]);
                    }
                }
            }
            Dispatcher.InvokeAsync(() =>
            {
                pirateModel.GetController().MoveShip(targetPath, pirateModel, playerScan);
            });
        }
    }
Пример #2
0
    //private MapModel map;

    public PatrolAI(PirateModel.PirateType pirateType, MapModel map, ModelLink modelLink, List <SpaceModel> patrolPoints, GameController gameController) : base(pirateType, map, modelLink, gameController)
    {
        // Oisín Notes: This constructor takes in a list of patrol points, which we can use to set up the patrol

        patrolPath = new List <SpaceModel>();
        // Oisín Notes: Should be using a for loop, but for now assume that the patrol points have three points.

        //var thread = new Thread(() =>
        //{
        // path between point 0 and 1
        patrolPath.AddRange(AStarPathfinding.GetPathToDestination(patrolPoints[0], patrolPoints[1]));
        // path between point 1 and 2
        patrolPath.AddRange(AStarPathfinding.GetPathToDestination(patrolPoints[1], patrolPoints[2]));
        // path between point 2 and 0
        patrolPath.AddRange(AStarPathfinding.GetPathToDestination(patrolPoints[2], patrolPoints[0]));

        // patrolPath should now be one continuous line of spaces. If AStar has bugs, it might break around the edges

        // What space of the path we're on.
        currentSpaceOnPath = 0;
        base.SpawnPirate(patrolPath[0]);
        //});
        //thread.Start();
    }
Пример #3
0
    public override void EndTurn(int turnNumber)
    {
        if (turnNumber % 10 == 0)
        {
            base.SpawnPirate(map.GetRandomSpace());
        }

        if (pirateModel != null)
        {
            pirateModel.ResetShotCounter();
            int currentSpaceOnPath = -1;
            //Defines the path to the player
            target = player.GetSpace();
            List <SpaceModel> targetPath = AStarPathfinding.GetPathToDestination(pirateModel.GetSpace(), target);
            List <SpaceModel> turnPath   = new List <SpaceModel>();

            PlayerModel playerScan = base.GetPlayerChasing();

            // Oisín Notes: Add a for loop here, and checks for if the player is in range?
            for (int i = 0; i < (base.pirateModel.GetMaxMovement()); i++)
            {
                if (playerScan != null)
                {
                    break;
                }
                else
                {
                    int nextSpace = currentSpaceOnPath + 1;
                    if (nextSpace == targetPath.Count - 1)
                    {
                        break;
                    }
                    bool breakOutofLoop = false;
                    while (targetPath[nextSpace].GetMovementCost() > 99)
                    {
                        i += targetPath[nextSpace].GetNormalMovementCost() - 1;
                        nextSpace++;
                        breakOutofLoop |= nextSpace == targetPath.Count - 1;
                    }
                    if (breakOutofLoop)
                    {
                        break;
                    }
                    i += targetPath[nextSpace].GetMovementCost() - 1;
                    if (i <= (base.pirateModel.GetMaxMovement()))
                    {
                        currentSpaceOnPath = nextSpace;
                        pirateModel.UpdatePirateLocation(targetPath[currentSpaceOnPath]);
                        turnPath.Add(targetPath[currentSpaceOnPath]);
                        playerScan = base.GetPlayerChasing();
                    }
                }
            }
            Dispatcher.InvokeAsync(() =>
            {
                pirateModel.GetController().MoveShip(turnPath, pirateModel, playerScan);
                //foreach (SpaceModel space in turnPath)
                //{
                //    space.GetMovementEffects(pirateModel);
                //}
            });
        }
        else
        {
            gameController.RemovePirateMoving();
        }
    }