Example #1
0
        private void CreateUnits()
        {
            if (Gamers != null && Gamers.Length == 2)
            {
                PawnFactory pawnFac = new PawnFactory();
                for (int i = 0; i < BoardConsts.INITIAL_PAWNS; i++)
                {
                    APawn dPawn = pawnFac.Create(ECultures.DALRIONS);
                    dPawn.Position = new Coord(1 + i, 7);
                    Gamers[0].AddPawn(dPawn);

                    APawn rPawn = pawnFac.Create(ECultures.RAHKARS);
                    rPawn.Position = new Coord(BoardConsts.MAX_LIN - 2 - i, BoardConsts.MAX_COL - 8);
                    Gamers[1].AddPawn(rPawn);
                }

                CulturalCenterFactory centFac = new CulturalCenterFactory();
                ABuilding             dCenter = centFac.Create(ECultures.DALRIONS, Boards);
                ABuilding             rCenter = centFac.Create(ECultures.RAHKARS, Boards);

                Gamers[0].SetCultCenter((CulturalCenter)dCenter);
                Gamers[1].SetCultCenter((CulturalCenter)rCenter);
            }
            else
            {
                throw new ArgumentException("Invalid player array!");
            }
        }
        public override bool Execute(bool isSimualtion = false)
        {
            bool valid = false;

            if (Validate())
            {
                APawn        allyPawn  = CurPlayer.GetPawnAt(AllyPos);
                Dijkstra     didi      = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.MovePoints);
                List <Coord> moveRange = didi.GetValidPaths(Command.MOVE);
                if (moveRange.Contains(Target))
                {
                    valid = true;
                    allyPawn.Erase(Boards);
                    allyPawn.Position = Target;
                    allyPawn.Place(Boards);
                    allyPawn.Adapt(Boards.TerrainAt(AllyPos), Boards.TerrainAt(Target));
                }
                else
                {
                    ErrorMsg = OUT_OF_RANGE;
                }
            }
            if (!ErrorMsg.Equals("") && !isSimualtion)
            {
                UserUtils.PrintError(ErrorMsg);
                Console.ReadLine();
            }

            return(valid);
        }
Example #3
0
 public void AddPawn(APawn pawn)
 {
     if (pawn != null && pawn.Culture == Culture)
     {
         Pawns.Add(pawn);
     }
 }
Example #4
0
    /**
     * Main function of this class
     *
     */
    public void Attack(APawn newTarget)
    {
        // The target should be passed to the function, but if the target is null, the closest one to the player is requested from the Swarmcontroller
        if (newTarget == null)
        {
            target = SwarmController.GetSwarmController().GetClosestEnemy(pawn);
        }
        else
        {
            target = newTarget;
        }

        // Setting the status of the pawn
        pawn.SetStatus(APawn.EStatus.ATTACKING);
        // If the pawn is an AI, the threat level of this AI is incrased
        if (pawn is PawnAI)
        {
            PawnAI ai = pawn as PawnAI;
            ai.AddThreat(1);
        }

        transform.LookAt(target.transform);

        // Animator values are set
        pawn.GetAnimator().SetInteger("cAttackIndex", currentAttackIndex);
        pawn.GetAnimator().SetInteger("cRange", GetRange());
        pawn.GetAnimator().SetTrigger("Attack");

        // In order to launch different animation, the animation index is modified here. If it exceed the max number of attack it goes back to zero
        currentAttackIndex++;
        if (currentAttackIndex > maxAttackIndex)
        {
            currentAttackIndex = 0;
        }
    }
Example #5
0
    /**
     * Loop through all the enemies and return the closest one to the player
     */
    public APawn GetClosestEnemy(APawn player)
    {
        APawn bestTarget = enemies[0];

        foreach (APawn pawn in enemies)
        {
            if (Vector3.Distance(pawn.transform.position, player.transform.position) < Vector3.Distance(bestTarget.transform.position, player.transform.position))
            {
                bestTarget = pawn;
            }
        }
        return(bestTarget);
    }
Example #6
0
    public Player(int id, APawn pawn = null, APlayerController playerController = null)
    {
        Id               = id;
        Pawn             = pawn;
        PlayerController = playerController;

        // set playerRefs
        if (Pawn != null)
        {
            Pawn.PlayerRef = this;
        }
        PlayerController.PlayerRef = this;
    }
Example #7
0
        public override Player Copy(Board board)
        {
            Player random    = new RandomPlayer(Culture, CurGame);
            Coord  tmpCursor = new Coord(0, 0);

            for (int i = 0; i < GetPawns().Count; i++)
            {
                APawn tmpPawn = GetPawns()[i].Copy(board);
                random.AddPawn(tmpPawn);
            }
            random.SetCultCenter(CultCenter.Copy(board));
            random.SetCursor(tmpCursor);
            return(random);
        }
Example #8
0
        public override Player Copy(Board board)
        {
            Player human     = new HumanPlayer(GetCulture());
            Coord  tmpCursor = new Coord(GetCursor().X, GetCursor().Y);

            for (int i = 0; i < GetPawns().Count; i++)
            {
                APawn tmpPawn = GetPawns()[i].Copy(board);
                human.AddPawn(tmpPawn);
            }
            human.SetCultCenter(CultCenter.Copy(board));
            human.SetCursor(tmpCursor);
            return(human);
        }
        public override Player Copy(Board board)
        {
            Player mcts      = new MonteCarloTreeSearch(GetCulture());
            Coord  tmpCursor = new Coord(GetCursor().X, GetCursor().Y);

            for (int i = 0; i < GetPawns().Count; i++)
            {
                APawn tmpPawn = GetPawns()[i].Copy(board);
                mcts.AddPawn(tmpPawn);
            }
            mcts.SetCultCenter(CultCenter.Copy(board));
            mcts.SetCursor(tmpCursor);
            return(mcts);
        }
Example #10
0
        protected override bool Validate()
        {
            bool valid = true;

            if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target))
            {
                ErrorMsg = INVALID_POS;
                valid    = false;
            }
            else if (Oponent == null)
            {
                ErrorMsg = NO_OPONENT;
                valid    = false;
            }
            else if (CurPlayer == null)
            {
                ErrorMsg = PLAYER;
                valid    = false;
            }
            else if (Boards == null)
            {
                ErrorMsg = NO_BOARDS;
                valid    = false;
            }
            else
            {
                APawn allyPawn = CurPlayer.GetPawnAt(AllyPos);
                if (allyPawn is ABasicPawn)
                {
                    ABasicPawn allyAttackerPawn = CurPlayer.GetPawnAt(AllyPos) as ABasicPawn;
                    if (allyPawn == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                    else if (Oponent.GetUnitAt(Target) == null)
                    {
                        ErrorMsg = NO_PAWN;
                        valid    = false;
                    }
                }
                else
                {
                    valid = false;
                }
            }
            return(valid);
        }
        public APawn GeneratePawn(Board boards)
        {
            PawnFactory factory = new PawnFactory();
            APawn       pawn    = factory.Create(Culture);
            Coord       pos     = PlacementPosition(boards);

            if (pos == null)
            {
                UserUtils.PrintError("Can not generate more pawns!");
                return(null);
            }
            else
            {
                pawn.Position = pos;
                return(pawn);
            }
        }
Example #12
0
 /// <summary>
 /// This method will execute every turn event for the player. For instance, a pawn respawn
 /// rate.
 /// </summary>
 /// <param name="boards">The board where events should be executed.</param>
 public void ExecuteTurnEvents(Board boards)
 {
     CultCenter.Regen();
     if (Turn % CultCenter.GetUnitsPerTurn() == 0 && Pawns.Count < 6)
     {
         APawn pawn = CultCenter.GeneratePawn(boards);
         if (pawn != null)
         {
             pawn.Place(boards);
             AddPawn(pawn);
         }
         else
         {
             UserUtils.PrintError("Can not create more pawns!");
             Console.ReadLine();
         }
     }
 }
Example #13
0
        private MoveCommand SetUpMove(Board boards)
        {
            MoveCommand move     = new MoveCommand();
            Coord       selPos   = boards.SelectUnit(Pawns);
            APawn       ally     = GetPawnAt(selPos);
            Coord       cursorCp = new Coord(Cursor.X, Cursor.Y);

            Cursor = selPos;
            if (ally != null)
            {
                Dijkstra     didi      = new Dijkstra(boards.GetBoard(), selPos, ally.MovePoints);
                List <Coord> moveRange = didi.GetValidPaths(Command.MOVE);
                Coord        target    = boards.SelectPosition(cursorCp, selPos, Command.MOVE, moveRange);

                // Set up command variables
                move.SetUp(this, selPos, target, boards);
            }
            return(move);
        }
Example #14
0
        public APawn Create(ECultures nature)
        {
            APawn pawn = null;

            switch (nature)
            {
            case ECultures.DALRIONS:
                return(new DalrionPawn());

            case ECultures.RAHKARS:
                return(new RahkarPawn());

            default:
                UserUtils.PrintError(nature + " isn't a valid culture!");
                Console.ReadLine();
                break;
            }
            return(pawn);
        }
Example #15
0
    /// <summary>
    /// Update Player information
    /// </summary>
    /// <param name="id">change the player Id</param>
    /// <param name="pawn">change the player Pawn</param>
    /// <param name="playerController">change the player PlayerController</param>
    public void UpdatePlayer(int?id, APawn pawn = null, APlayerController playerController = null)
    {
        if (id != null)
        {
            Id = (int)id;
        }

        if (pawn != null)
        {
            Pawn = (APawn)pawn;
        }

        if (playerController != null)
        {
            PlayerController = (APlayerController)playerController;
        }

        if (Pawn != null)
        {
            Pawn.PlayerRef = this;
        }

        PlayerController.PlayerRef = this;
    }
Example #16
0
 // Take possession of a pawn
 public override void Possess(APawn pawnAI)
 {
     pawn = pawnAI as PawnAI;
 }
Example #17
0
 protected virtual void Start()
 {
     pawn = GetComponent <APawn>();
 }
Example #18
0
 public override void Possess(APawn pawnPlayer)
 {
     pawn = pawnPlayer as PawnPlayer;
 }
Example #19
0
 // Set the pawn variable of the controller
 public abstract void Possess(APawn pawn);
Example #20
0
 public void SetTarget(APawn value)
 {
     target = value;
 }