Beispiel #1
0
    /// <summary>
    /// Resolve war conflicts between each cities.
    /// </summary>
    /// <param name="age">The current achieving age.</param>
    public void ResolveConflicts(int age)
    {
        const int    WEST = 0, EAST = 1;
        List <int[]> victoryMatrix = this.GameManager.CaculateWarResults();

        for (int i = 0; i < victoryMatrix.Count; i++)
        {
            EvaluateResult(victoryMatrix[i][WEST], "WEST", this.GameManager.Players[i]);
            EvaluateResult(victoryMatrix[i][EAST], "EAST", this.GameManager.Players[i]);
        }

        PlayerBoardController.RefreshWarPoints();

        // Update war victory points, defeat points and defeat tokens.
        void EvaluateResult(int result, string side, Player p)
        {
            if (result > 0)
            {
                p.VictoryWarPoints += GameConsts.WAR_VICTORY_POINTS[age - 1];
            }
            else if (result < 0)
            {
                p.VictoryWarPoints += GameConsts.WAR_DEFEAT_POINTS;
                if (side.Contains("WEST"))
                {
                    p.WestDefeatWarTokens += 1;
                }
                else
                {
                    p.EastDefeatWarTokens += 1;
                }
            }
        }
    }
    /// <summary>
    /// Deactivate the trade panel and apply linked actions whether there was a deal or not (actions are applied only to the current location).
    /// </summary>
    /// <param name="tradePanel">The related trade panel.</param>
    /// <param name="deal">If a deal was concluded or not.</param>
    /// <param name="resLabels">All resource labels from trade panel.</param>
    public static void CloseTradePanel(GameObject tradePanel, bool deal, List <Text> resLabels)
    {
        if (deal)
        {
            Dictionary <ResourceType, int> resWanted = PlayerBoardController.GetAllResourcesToTrade(resLabels);
            Player.City.BuyResources(resWanted, CurrentTrade);
            PlayerBoardController.RefreshCoinAmount();
            tradePanel.SetActive(false);

            TradeBoard boardToUpdate;
            if (CurrentTrade == CityManager.TradeLocation.WEST)
            {
                boardToUpdate = LeftTradeBoard;
                LeftTradeBoard.CleanBoard();
            }
            else
            {
                boardToUpdate = RightTradeBoard;
                RightTradeBoard.CleanBoard();
            }
            foreach (KeyValuePair <ResourceType, int> resource in resWanted)
            {
                for (int i = 0; i < resource.Value; i++)
                {
                    boardToUpdate.AddResource(resource.Key);
                }
            }
        }
        else
        {
            tradePanel.SetActive(false);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Move the card on the discard pile and gets its counterparty in coins.
    /// </summary>
    /// <param name="card">The card to put on the discard pile.</param>
    /// <returns>The new card location.</returns>
    private Transform Discard(GameObject card)
    {
        Playable playable = card.GetComponent <Playable>();

        Player.City.Discard(playable.id);
        PlayerBoardController.RefreshCoinAmount();
        GameManager.DiscardPile.Add(playable);
        PlayerBoardController.DiscardCard(card);

        return(DiscardPile);
    }
Beispiel #4
0
    /// <summary>
    /// Put the card under the wonder board and flip it.
    /// </summary>
    /// <param name="card">The card to move under the board.</param>
    /// <returns>The new card location.</returns>
    private Transform WonderBuild(GameObject card)
    {
        if (Player.WonderManager.IsWonderBuilt())
        {
            return(null);
        }

        Playable playable        = card.GetComponent <Playable>();
        int      actionToPerform = Player.WonderManager.TryBuildWonder(playable.id);

        if (actionToPerform >= 0)
        {
            switch (actionToPerform)
            {
            case 1: PlayerBoardController.RefreshCoinAmount();
                break;

            case 2: List <Card> guildsToCopy = this.GameController.GetNeighboursBuildings(this.Player, new Card.CardType[] { Card.CardType.GUILD });
                PlayerBoardController.ExploreCards(guildsToCopy);
                break;

            case 3: PlayerBoardController.ExploreCards(GameManager.DiscardPile);
                break;
            }

            Transform childLayout    = this.DropZone.parent.GetChild(0);
            Image     cardAppearance = card.GetComponent <Image>();
            string    cardBackPath   = CARD_BACK_1;
            switch (GameManager.Age)
            {
            case 1:
                cardBackPath = CARD_BACK_1;
                break;

            case 2:
                cardBackPath = CARD_BACK_2;
                break;

            case 3:
                cardBackPath = CARD_BACK_3;
                break;
            }
            Sprite cardBack = Resources.Load <Sprite>(cardBackPath);
            cardAppearance.sprite = cardBack;
            return(childLayout);
        }
        else
        {
            Debug.Log("Wonder build impossible: build conditions are not met.");
            return(null);
        }
    }
Beispiel #5
0
    /// <summary>
    /// Distribute cards to start a new age.
    /// </summary>
    /// <param name="age">The age to be started.</param>
    /// <param name="AILevel">The AI level of cleverness.</param>
    public void StartAge(int age, int AILevel = 0)
    {
        if (age > 3)
        {
            this.RefreshAIBoards();
            this.CleanLastMove();
            PlayerBoardController.DisplayScoreBoard(this.GameManager.Players);
        }
        else
        {
            GameManager.Age = age;
            this.GameManager.DistributeCards();
            this.GameManager.ResetFreeBuildCount();
            PlayerBoardController.RefreshHand();
            PlayerBoardController.RefreshDiscardPiles(age);

            if (age == 1)
            {
                this.GameManager.LoadWonders();
                Player humanPlayer = this.GameManager.GetHumanPlayer();
                Wonder humanWonder = humanPlayer.WonderManager.Wonder;
                PlayerBoardController.RefreshWonderBoard(humanWonder.ID, humanWonder.Steps.Count);

                this.GameManager.LoadAI(AILevel);
                this.LeftPlayer  = PlayerBoardController.GetLeftAIBoard();
                this.RightPlayer = PlayerBoardController.GetRightAIBoard();
                Player[] distantPlayers = this.GameManager.GetDistantPlayers();
                if (distantPlayers.Length > 0)
                {
                    this.DistantPlayers = PlayerBoardController.SetExtraPlayers(distantPlayers);
                }

                foreach (Player p in this.GameManager.Players)
                {
                    if (p == this.GameManager.GetLeftPlayer(humanPlayer))
                    {
                        this.LeftPlayer.InitializeAIBoard(p);
                    }
                    else if (p == this.GameManager.GetRightPlayer(humanPlayer))
                    {
                        this.RightPlayer.InitializeAIBoard(p);
                    }
                    else if (!p.IsHuman)
                    {
                        this.DistantPlayers.Reverse().Where(dp => dp.Player == null).First().InitializeAIBoard(p);
                    }
                }
                this.RefreshAIBoards();
            }
        }
    }
Beispiel #6
0
    /// <summary>
    /// Initialize class attributes.
    /// </summary>
    private void Awake()
    {
        this.GameController        = new GameController(this.NumberOfPlayers);
        this.PlayerBoardController = new PlayerBoardController();

        if (this.NumberOfPlayers > 3)
        {
            this.ExtraPlayers.SetActive(true);
        }
        else
        {
            this.ExtraPlayers.SetActive(false);
        }
    }
Beispiel #7
0
 /// <summary>
 /// Get playable id and send it to player UI controller.
 /// </summary>
 public void OnPointerClick(PointerEventData eventData)
 {
     if (this.Clickable)
     {
         Playable card = this.GetComponent <Playable>();
         if (PlayerBoardController.SelectCardToBuild(card.id))
         {
             Transform newParent = GameObject.Find("build_zones").transform.GetChild((int)card.buildType);
             if (card.buildType == Card.CardType.RESOURCE)
             {
                 ShiftLayout layout = newParent.GetComponent <ShiftLayout>();
                 newParent = layout.Shift(this.gameObject);
             }
             this.ParentToReturnTo = newParent;
             this.ZoomOnComponent(false);
             this.StopDraggable();
         }
     }
 }
Beispiel #8
0
    /// <summary>
    /// Sort the card according to its type and define its new location accordingly.
    /// </summary>
    /// <param name="card">The card to sort.</param>
    /// <returns>The new card location.</returns>
    private Transform RegularBuild(GameObject card)
    {
        Playable playable = card.GetComponent <Playable>();
        Card     building = Player.Hand.Select(o => o).Where(o => o.ID == playable.id).First();

        if (Player.City.Build(building, false))
        {
            PlayerBoardController.RefreshCoinAmount();
            Transform newParent = GameObject.Find("build_zones").transform.GetChild((int)playable.buildType);

            if (playable.buildType == Card.CardType.RESOURCE)
            {
                ShiftLayout layout = newParent.GetComponent <ShiftLayout>();
                newParent = layout.Shift(card);
            }
            return(newParent);
        }
        else
        {
            Debug.Log("Build impossible: build conditions are not met.");
            return(null);
        }
    }
Beispiel #9
0
    /// <summary>
    /// Rotate hands & discard last card if applicable.
    /// </summary>
    private void EndTurn()
    {
        if (this.Player.Hand.Count < 1)
        {
            PlayerBoardController.DiscardLastCard();
        }
        else
        if (this.Player.Hand.Count == 1 && !this.Player.WonderManager.HasExtraBuildBonus())
        {
            PlayerBoardController.DiscardLastCard();
        }

        GameManager.Instance().EndTurn(this.GameController);
        PlayerBoardController.RefreshHand();
        PlayerBoardController.CleanTradeBoards();

        if (this.Player.Hand.Count == 0)
        {
            this.GameController.ResolveConflicts(GameManager.Age);
            this.GameController.RefreshAIBoards();
            GameManager.Age++;
            this.GameController.StartAge(GameManager.Age);
        }
    }