Ejemplo n.º 1
0
    public void auctionControlFlow()
    {
        AuctionHandler auction = State.getAuctionHandler();

        Debug.Log("Begin Auction Control Flow");
        App    app         = UnityEngine.Object.FindObjectOfType <App>();
        int    playerIndex = app.GetHumanIndex();
        Nation humanPlayer = State.getNations()[playerIndex];

        // int start = currentBidPosition;
        //for (int i = start; i < biddingOrder.Count; i++)
        //{
        while (true)
        {
            Debug.Log("Top of while loop");
            Nation currentPlayer = State.getNations()[auction.getBiddingOrder()[auction.CurrentBidPosition]];
            State.setCurrentPlayer(auction.getBiddingOrder()[auction.CurrentBidPosition]);

            Debug.Log("Current Position is: " + auction.CurrentBidPosition);
            Debug.Log("Current Bidder is: " + currentPlayer.getName());
            Debug.Log("Curret Bidder Index is: " + currentPlayer.getIndex());
            //Debug.Log("Current player - " + currentPlayer.nationName);
            Debug.Log("Current player passed already? :" + auction.getIfPlayerPass(currentPlayer.getIndex()));
            if (humanPlayer.getIndex() == currentPlayer.getIndex() && !auction.getIfPlayerPass(humanPlayer.getIndex()))
            //  if (humanPlayer.getIndex() == currentPlayer.getIndex())
            {
                Debug.Log("Current is human");
                return;
            }
            if (humanPlayer.getIndex() == currentPlayer.getIndex() && auction.getIfPlayerPass(humanPlayer.getIndex()))
            {
                auction.incrementBiddingPosition();
                return;
            }

            else if (currentPlayer.getIndex() == auction.getHighestBidderSoFar())
            {
                Debug.Log("Returned to highest bidder (auction presumably over) " + auction.CurrentBidPosition);
                return;
            }
            else
            {
                Debug.Log("AI bid");
                auction.newBid(currentPlayer);
            }
            auction.incrementBiddingPosition();
        }
    }
Ejemplo n.º 2
0
    private void updateAuctionPanel()
    {
        Debug.Log("Update Auction Panel ___________________________");
        App            app         = UnityEngine.Object.FindObjectOfType <App>();
        int            playerIndex = app.GetHumanIndex();
        Nation         player      = State.getNations()[playerIndex];
        AuctionHandler auction     = State.getAuctionHandler();
        Nation         item        = State.getNations()[auction.getIndexOfCurrentItem()];

        // Debug.Log(playerIndex);
        //TextMeshProUGUI currentPlayerBid = currentBidAmount.GetComponent<TextMeshProUGUI>();
        currentBidAmount.text = auction.getPlayerBid(playerIndex).ToString();
        if (auction.getPlayerBid(playerIndex) > 0 && !auction.getIfPlayerPass(playerIndex))
        {
            decreaseBid.interactable = true;
        }
        else
        {
            decreaseBid.interactable = false;
        }

        if (player.ColonialPoints <= State.CurrentColonyAuctionBid || player.RecognizingTheseClaims.Contains(item.getIndex()) ||
            auction.getIfPlayerPass(playerIndex) || player.landForces.Strength < 2)
        {
            increaseBid.interactable = false;
        }
        else
        {
            increaseBid.interactable = true;
        }

        biddingTable.ClearRows();
        for (int i = 0; i < auction.getBiddingOrder().Count; i++)
        {
            int    currNationIndex = auction.getBiddingOrder()[i];
            Nation currNat         = State.getNations()[currNationIndex];

            TableRow newRow = Instantiate <TableRow>(biddingRow);
            newRow.gameObject.SetActive(true);
            newRow.preferredHeight = 30;
            newRow.name            = currNat.getIndex().ToString();
            biddingTable.AddRow(newRow);
            biddingConnector.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (biddingTable.transform as RectTransform).rect.height);

            int currNatIndex = currNat.getIndex();
            //   Debug.Log("Current Nation: " + currNatIndex);
            int currentNatBid = auction.getPlayerBid(currNatIndex);

            newRow.Cells[0].GetComponentInChildren <Text>().text = currentNatBid.ToString();
            newRow.Cells[1].GetComponentInChildren <Text>().text = currNat.getNationName().ToString();
            // Transform res = newRow.Cells[2].transform.GetChild(0);

            UIObject3D flagImage = newRow.Cells[2].GetComponentInChildren <UIObject3D>();
            // flagImage.sprite = Resources.Load("Flags/" + currNat.getNationName().ToString(), typeof(Sprite)) as Sprite;
            GameObject flagPrefab = Instantiate(Resources.Load <GameObject>("Flags/Prefabs/" + currNat.getNationName()));
            flagImage.ObjectPrefab   = flagPrefab.transform;
            flagImage.RenderScale    = 0;
            flagImage.LightIntensity = 1;
            Transform statusTransform = newRow.Cells[3].transform.GetChild(0);
            Image     statusImage     = statusTransform.GetComponent <Image>();
            if (auction.getIfPlayerPass(currNatIndex) == true)
            {
                statusImage.sprite = Resources.Load("Sprites/GUI/Dark_Red_x", typeof(Sprite)) as Sprite;
            }
            else
            {
                statusImage.sprite = Resources.Load("Sprites/GUI/AuctionHammer", typeof(Sprite)) as Sprite;
            }
        }
        if (auction.getPlayerBid(playerIndex) > State.CurrentColonyAuctionBid)
        {
            bid.interactable = true;
        }
        else
        {
            bid.interactable = false;
        }
        TextMeshProUGUI passButtonText = pass.GetComponentInChildren <TextMeshProUGUI>();

        if (auction.getIfPlayerPass(playerIndex) || auction.getHighestBidderSoFar() == playerIndex)
        {
            passButtonText.SetText("Continue");
        }
        else
        {
            passButtonText.SetText("Pass");
        }
    }
Ejemplo n.º 3
0
    public void nextAuctionPhase()
    {
        Debug.Log("Begin new auction phase");
        //   waitASec(0.8f);

        AuctionHandler auction     = State.getAuctionHandler();
        App            app         = UnityEngine.Object.FindObjectOfType <App>();
        int            humanIndex  = app.GetHumanIndex();
        Nation         humanPlayer = State.getNations()[humanIndex];

        updateAuctionPanel();
        if (auction.checkIfAuctionIsOver())
        {
            Debug.Log("Auction Should be Over now");
            continueToNextTurn();
            AuctionPanel.SetActive(false);
            auction.concludeAuction();
            prepareWinnerPanel();
            AuctionWinnerPanel.SetActive(true);
            terrainUpdater.ColourContries();
        }
        else
        {
            Debug.Log("Auction Will Continue");
            //If all players have bid and auction is not over - go back to the first bidder
            //  Debug.Log(auction.CurrentBidPosition);
            //  if(auction.CurrentBidPosition == State.getMajorNations().Count)
            //  {
            //      Debug.Log("Return to first remaining bidder");
            //      auction.CurrentBidPosition = 0;
            //  }
            // Go to auction control flow - it will have each AI player bid or pass until reaching the Human controlled player
            auctionControlFlow();
            updateAuctionPanel();
            // If human has passed
            Debug.Log("Human has passed?: " + humanPlayer.getIndex());
            if (auction.getIfPlayerPass(humanPlayer.getIndex()))
            {   // Check if all players have now passed
                Debug.Log("Human Player has passed");

                /*  if (auction.checkIfAuctionIsOver())
                 * {
                 *
                 *    Debug.Log("Auction Should be Over now");
                 *    continueToNextTurn();
                 *    AuctionPanel.SetActive(false);
                 *    auction.concludeAuction();
                 *    prepareWinnerPanel();
                 *    AuctionWinnerPanel.SetActive(true);
                 *    terrainUpdater.ColourContries();
                 * } */
                // NextPhaseAfterPlayerPasses(1.5f);
                // else
                // {
                Debug.Log("Bidding continues without human");
                auctionControlFlow();
                // }
            }
            Debug.Log(auction.CurrentBidPosition);
            int indexOfCurrentBidder = auction.getBiddingOrder()[auction.CurrentBidPosition];
            if (indexOfCurrentBidder != humanIndex)
            {
                auctionControlFlow();
            }
            // nextAuctionPhase();
            Debug.Log("Should be player's turn now?");
            //If player has not passed, control will now be handed to the player
        }
    }