From 597527721342c1254724afaccbef37e6a1257525 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 15 Dec 2020 13:15:50 +0000 Subject: [PATCH] Nearly finished auction --- Assets/Scenes/monopoly.unity | 5 ++-- Assets/Scripts/monopoly/Auction.cs | 38 ++++++++++++++++++++---- Assets/Scripts/monopoly/ButtonHandler.cs | 3 ++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Assets/Scenes/monopoly.unity b/Assets/Scenes/monopoly.unity index 9245147..9bbc795 100644 --- a/Assets/Scenes/monopoly.unity +++ b/Assets/Scenes/monopoly.unity @@ -4172,6 +4172,7 @@ MonoBehaviour: tradeButton: {fileID: 839394544} tradeCompletedButton: {fileID: 1476609748} AuctionUI: {fileID: 1651024356} + auctionButtonGameObject: {fileID: 597381241} auctionButton: {fileID: 597381243} auctionCompleteButton: {fileID: 321526181} --- !u!114 &310476700 @@ -22496,7 +22497,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: -0.3999939, y: 0.23999023} + m_AnchoredPosition: {x: -0.4000244, y: 0.23999023} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0, y: 1} --- !u!114 &1417539915 @@ -25762,7 +25763,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1651024357 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/monopoly/Auction.cs b/Assets/Scripts/monopoly/Auction.cs index 9940a57..0628a87 100644 --- a/Assets/Scripts/monopoly/Auction.cs +++ b/Assets/Scripts/monopoly/Auction.cs @@ -46,9 +46,9 @@ public class Auction : MonoBehaviour highestBidValue = 0; //This is the starting value for the highest bid. //Assigning players to the queue - List auctionPlayerQueue = main.board.players; //This gets a temporary list of all of the players in the game. - currentAuctionPlayer = 0; //This sets the auction queue to 0. - int currentPlayer = main.board.currentPlayer - 1; //This gets the current player from the board. + auctionPlayerQueue = main.board.players; //This gets a temporary list of all of the players in the game. + currentAuctionPlayer = main.board.currentPlayer; //This sets the auction queue to the current player. + int currentPlayer = main.board.currentPlayer; //This gets the current player from the board. int playerPosition = main.board.players[currentPlayer].position; //This gets the position of the player that started the auction. @@ -82,7 +82,7 @@ public class Auction : MonoBehaviour private void UpdateCurrentBidders() { - currentBidders.text = $"Current Bidder: {auctionPlayerQueue[currentAuctionPlayer]}\n" + + currentBidders.text = $"Current Bidder: {auctionPlayerQueue[currentAuctionPlayer].name}\n" + $"Bidders Left: {auctionPlayerQueue.Count}"; } @@ -91,7 +91,7 @@ public class Auction : MonoBehaviour { //Incrementing to the next player - if (currentAuctionPlayer >= auctionPlayerQueue.Count) + if (currentAuctionPlayer >= auctionPlayerQueue.Count - 1) { currentAuctionPlayer = 0; } @@ -187,6 +187,31 @@ public class Auction : MonoBehaviour NextPlayer(); } + private void QuitAuction() + { + auctionPlayerQueue.RemoveAt(currentAuctionPlayer); //This removes the specified player. + + if (currentAuctionPlayer <= auctionPlayerQueue.Count - 1) //This moves the player back a bit for the queue + { + currentAuctionPlayer--; + } + + if (auctionPlayerQueue.Count == 1) //This checks if there is only one player left. + { + WinAuction(); //This gives the player the property. + return; //Ends the function. + } + + NextPlayer(); //Moves on to the next player to bid. + } + + private void WinAuction() + { + int winningPlayer = auctionPlayerQueue[0].playerNumber; //This stores the winning player's number on the board. + + + } + void Awake() { main = FindObjectOfType
(); //This gets the data from the main file. @@ -201,5 +226,8 @@ public class Auction : MonoBehaviour //Custom bid customBidButton.onClick.AddListener(BidCustom); //This allows the player to bid a custom amount. + + //Quit auction + quitAuction.onClick.AddListener(QuitAuction); } } diff --git a/Assets/Scripts/monopoly/ButtonHandler.cs b/Assets/Scripts/monopoly/ButtonHandler.cs index e89c81c..29daf6b 100644 --- a/Assets/Scripts/monopoly/ButtonHandler.cs +++ b/Assets/Scripts/monopoly/ButtonHandler.cs @@ -31,6 +31,7 @@ public class ButtonHandler : MonoBehaviour //Auction public GameObject AuctionUI; + public GameObject auctionButtonGameObject; public Button auctionButton; public Button auctionCompleteButton; private Auction auction; @@ -47,11 +48,13 @@ public class ButtonHandler : MonoBehaviour public void DisableBuying() { + auctionButtonGameObject.SetActive(false); buyButton.SetActive(false); } public void EnableBuying() { + auctionButtonGameObject.SetActive(true); buyButton.SetActive(true); }