diff --git a/Assets/Scenes/monopoly.unity b/Assets/Scenes/monopoly.unity index 6a15ee4..0cf8147 100644 --- a/Assets/Scenes/monopoly.unity +++ b/Assets/Scenes/monopoly.unity @@ -1396,6 +1396,7 @@ Transform: - {fileID: 768846291} - {fileID: 399889871} - {fileID: 724284470} + - {fileID: 1679278721} m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0} @@ -2060,6 +2061,7 @@ MonoBehaviour: - {fileID: 768846290} - {fileID: 399889870} - {fileID: 724284469} + - {fileID: 1679278720} players: - {fileID: 1272828665} - {fileID: 305116340} @@ -3152,6 +3154,36 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1628500262} m_CullTransparentMesh: 0 +--- !u!1 &1679278720 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1679278721} + m_Layer: 0 + m_Name: 40 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1679278721 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1679278720} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.4132, y: 1, z: 0.4173} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 758519666} + m_RootOrder: 40 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1747654226 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/monopoly/Main.cs b/Assets/Scripts/monopoly/Main.cs index bb40059..606a42b 100644 --- a/Assets/Scripts/monopoly/Main.cs +++ b/Assets/Scripts/monopoly/Main.cs @@ -90,8 +90,8 @@ public class Board //Creating the class for the board mechanics. public int totalProperties; //Defining how many properties can exist. private TextHandler textHandler; private ButtonHandler buttonHandler; - private List players; - private int currentPlayer = 0; + public List players; + public int currentPlayer = 0; public List existingProperties; public List avaliableProperties = new List(); //Has a list of all the available properties. @@ -115,16 +115,16 @@ public class Board //Creating the class for the board mechanics. } } - public void MovePlayer(int player, int roll) + public void MovePlayer(int roll) { - players[player].Move(roll); + players[currentPlayer].Move(roll); textHandler.updateRoll(roll); - int money = players[player].money; + int money = players[currentPlayer].money; textHandler.updateMoney(money); - string propertyName = existingProperties[players[player].position].property_name; - int propertyValue = existingProperties[players[player].position].property_value; + string propertyName = existingProperties[players[currentPlayer].position].property_name; + int propertyValue = existingProperties[players[currentPlayer].position].property_value; if (propertyValue != 0) { @@ -138,6 +138,30 @@ public class Board //Creating the class for the board mechanics. buttonHandler.disableRollDice(); } + public void CheckFees() + { + int playerPosition = players[currentPlayer].position; + Property currentProperty = existingProperties[playerPosition]; + + if (currentProperty.property_rent >= 100) + { + players[currentPlayer].Pay(Convert.ToInt32(currentProperty.property_rent)); + } + } + + public void NextPlayer() + { + if (currentPlayer + 1 >= players.Count) + { + Debug.Log("Restarted"); + currentPlayer = 0; + } + else + { + currentPlayer++; + } + } + public bool CheckBuyable(int position) //This checks if the property can be bought by the user. { @@ -148,18 +172,27 @@ public class Board //Creating the class for the board mechanics. if (property.property_name == avaliableProperties[i].property_name) //Checks if the name exists in the available properties that can be purchased. { buttonHandler.enableBuying(); //If it can, it will return true and break from the function - return true; //Returns true if the player can buy the property. + return true; //Returns true if the property is buyable. } } buttonHandler.disableBuying(); //If the name is not found, the property has not been found. - buttonHandler.enableRollDice(); //Lets the player continue moving if they can't buy the property. - return false; //Returns false if the player can't buy the property. + buttonHandler.enableRollDice(); //Allows the user to roll the dice if the property cannot be bought + return false; //Returns false if the property is not buybale. } public void BuyProperty() { int position = players[currentPlayer].position; //This is the current position of the player for the property. Property property = existingProperties[position]; //This gets the property that the player is buying + int money = players[currentPlayer].money; + + if (money - property.property_value < 0) + { + Debug.Log("The player doesn't have enough money!"); + buttonHandler.disableBuying(); //Removes the buy button. + buttonHandler.enableRollDice(); //Re-enables the user to roll the dice. + return; + } for (int i = 0; i < avaliableProperties.Count; i++) //Checks through all of the properties that are buyable using a linear search { @@ -168,8 +201,8 @@ public class Board //Creating the class for the board mechanics. avaliableProperties.RemoveAt(i); //Removes the property from the list. players[currentPlayer].BuyProperty(property); //This buys the property in the player class textHandler.updateMoney(players[currentPlayer].money); //This updates the amount of money the player has. - buttonHandler.disableBuying(); - buttonHandler.enableRollDice(); + buttonHandler.disableBuying(); //Removes the buy button. + buttonHandler.enableRollDice(); //Re-enables the user to roll the dice. return; } } @@ -184,7 +217,8 @@ public class Player private string name; private int playerNumber; public int money; //Initializes the variable for money. - public int position = 0; //Positions vary from 0-39 (40 squares on the board) (Go is 0) + public int position; //Positions vary from 0-39 (40 squares on the board) (Go is 0) + public bool inJail; public List ownedProperties = new List(); public GameObject player; private Movement movement; @@ -192,6 +226,8 @@ public class Player public Player(string playerName, int playerNumber, GameObject player) { name = playerName; + position = 0; + inJail = false; this.playerNumber = playerNumber; money = 1500; //Set the default starting money. this.player = player; @@ -201,27 +237,35 @@ public class Player public void Move(int roll) //This moves the player a certain length (what they got from rolling the dice). { + int previousPosition = position; + position += roll; //Add the position with what was rolled. + if (position >= 40) //If the player has reached or passed go then... { position -= 40; //As the player has gone round the board once, it removes the fact that it has gone around the board once. money += 200; //Collect money as they pass go. } - movement.Move(position, playerNumber); + movement.Move(previousPosition, position, playerNumber); //return position; //Returns where the player needs to move to on the board } public void GoToJail() //If the player needs to go to jail. { + int previousPosition = position; + Debug.Log("Jailed!!!"); position = 40; //Special position for jail. + inJail = true; + movement.Move(previousPosition,position, playerNumber); //Moves the player to jail. } - public void GetOutOfJail(int length) //If the player is going out of jail. + public void GetOutOfJail(int roll) //If the player is going out of jail. { position = 10; //Moves the player out of jail. - //Move(length); //Then moves the player. + inJail = false; + Move(roll); //Then moves the player. } public void BuyProperty(Property property) //This function allows the player to own a property. @@ -239,6 +283,11 @@ public class Player Debug.Log("Error: You do not have enough money to pay for the property!"); } } + + public void Pay(int money) + { + this.money -= money; + } } diff --git a/Assets/Scripts/monopoly/Movement.cs b/Assets/Scripts/monopoly/Movement.cs index 37d77b9..524645e 100644 --- a/Assets/Scripts/monopoly/Movement.cs +++ b/Assets/Scripts/monopoly/Movement.cs @@ -17,8 +17,9 @@ public class Movement : MonoBehaviour private Main main; - public void Move(int _roll, int playerNumber) + public void Move(int previousPosition, int _roll, int playerNumber) { + position = previousPosition; roll = _roll; movement = true; currentPlayer = playerNumber; @@ -32,21 +33,36 @@ public class Movement : MonoBehaviour void Update() { if (!movement) return; - if ((Vector3.Distance(waypoints[position].transform.position, players[currentPlayer].transform.position) < WPradius) && position != roll) + + if ((Vector3.Distance(waypoints[position].transform.position, players[currentPlayer].transform.position) < WPradius) && roll == 40) //This checks if the player has to go to jail + { + position = 40; + } + else if ((Vector3.Distance(waypoints[position].transform.position, players[currentPlayer].transform.position) < WPradius) && position != roll) { //Debug.Log(waypoints[current]); position++; - if (position >= waypoints.Length) + if (position >= waypoints.Length-1) { position = 0; } - } else if ((Vector3.Distance(waypoints[position].transform.position, players[currentPlayer].transform.position) < WPradius) && position == roll) + } + else if ((Vector3.Distance(waypoints[position].transform.position, players[currentPlayer].transform.position) < WPradius) && position == roll) { - main.board.CheckBuyable(roll); movement = false; + if (position == 30) //This checks if the player has landed on go to jail. + { + main.board.players[currentPlayer].GoToJail(); + //main.board.NextPlayer(); + return; + } + + if (!main.board.CheckBuyable(roll)) + { + main.board.CheckFees(); + } } - players[currentPlayer].transform.position = Vector3.MoveTowards(players[currentPlayer].transform.position, - waypoints[position].transform.position, Time.deltaTime * speed); + players[currentPlayer].transform.position = Vector3.MoveTowards(players[currentPlayer].transform.position, waypoints[position].transform.position, Time.deltaTime * speed); } } diff --git a/Assets/Scripts/monopoly/RollDice.cs b/Assets/Scripts/monopoly/RollDice.cs index a7e29f0..cefde50 100644 --- a/Assets/Scripts/monopoly/RollDice.cs +++ b/Assets/Scripts/monopoly/RollDice.cs @@ -7,7 +7,10 @@ public class RollDice : MonoBehaviour { System.Random random = new System.Random(); + private int dice1; + private int dice2; private int current; + private int totalRoll; private Main main; public Button m_RollDice; @@ -23,8 +26,32 @@ public class RollDice : MonoBehaviour m_RollDice.onClick.AddListener(TaskOnClick); } - void TaskOnClick() { - current = random.Next(1, 7) + random.Next(1, 7); - main.board.MovePlayer(0, current); + void TaskOnClick() + { + + current = main.board.currentPlayer; + bool inJail = main.board.players[current].inJail; + + dice1 = random.Next(1, 7); + dice2 = random.Next(1, 7); + totalRoll = dice1 + dice2; + + if (inJail) + { + if (dice1 != dice2) + { + Debug.Log($"You rolled {dice1} and {dice2}"); + return; + } + else + { + Debug.Log($"You got out of jail with {dice1} and {dice2}!"); + main.board.players[current].GetOutOfJail(totalRoll); + return; + } + + } + + main.board.MovePlayer(4); } }