mirror of
https://github.com/smyalygames/monopoly.git
synced 2025-05-18 14:24:12 +02:00
Added the basics of a jail system
This commit is contained in:
parent
12cbc174bc
commit
1b384883bc
@ -1396,6 +1396,7 @@ Transform:
|
|||||||
- {fileID: 768846291}
|
- {fileID: 768846291}
|
||||||
- {fileID: 399889871}
|
- {fileID: 399889871}
|
||||||
- {fileID: 724284470}
|
- {fileID: 724284470}
|
||||||
|
- {fileID: 1679278721}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0}
|
||||||
@ -2060,6 +2061,7 @@ MonoBehaviour:
|
|||||||
- {fileID: 768846290}
|
- {fileID: 768846290}
|
||||||
- {fileID: 399889870}
|
- {fileID: 399889870}
|
||||||
- {fileID: 724284469}
|
- {fileID: 724284469}
|
||||||
|
- {fileID: 1679278720}
|
||||||
players:
|
players:
|
||||||
- {fileID: 1272828665}
|
- {fileID: 1272828665}
|
||||||
- {fileID: 305116340}
|
- {fileID: 305116340}
|
||||||
@ -3152,6 +3154,36 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1628500262}
|
m_GameObject: {fileID: 1628500262}
|
||||||
m_CullTransparentMesh: 0
|
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
|
--- !u!1 &1747654226
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -90,8 +90,8 @@ public class Board //Creating the class for the board mechanics.
|
|||||||
public int totalProperties; //Defining how many properties can exist.
|
public int totalProperties; //Defining how many properties can exist.
|
||||||
private TextHandler textHandler;
|
private TextHandler textHandler;
|
||||||
private ButtonHandler buttonHandler;
|
private ButtonHandler buttonHandler;
|
||||||
private List<Player> players;
|
public List<Player> players;
|
||||||
private int currentPlayer = 0;
|
public int currentPlayer = 0;
|
||||||
public List<Property> existingProperties;
|
public List<Property> existingProperties;
|
||||||
public List<Property> avaliableProperties = new List<Property>(); //Has a list of all the available properties.
|
public List<Property> avaliableProperties = new List<Property>(); //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);
|
textHandler.updateRoll(roll);
|
||||||
|
|
||||||
int money = players[player].money;
|
int money = players[currentPlayer].money;
|
||||||
textHandler.updateMoney(money);
|
textHandler.updateMoney(money);
|
||||||
|
|
||||||
string propertyName = existingProperties[players[player].position].property_name;
|
string propertyName = existingProperties[players[currentPlayer].position].property_name;
|
||||||
int propertyValue = existingProperties[players[player].position].property_value;
|
int propertyValue = existingProperties[players[currentPlayer].position].property_value;
|
||||||
|
|
||||||
if (propertyValue != 0)
|
if (propertyValue != 0)
|
||||||
{
|
{
|
||||||
@ -138,6 +138,30 @@ public class Board //Creating the class for the board mechanics.
|
|||||||
buttonHandler.disableRollDice();
|
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.
|
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.
|
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
|
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.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.
|
buttonHandler.enableRollDice(); //Allows the user to roll the dice if the property cannot be bought
|
||||||
return false; //Returns false if the player can't buy the property.
|
return false; //Returns false if the property is not buybale.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuyProperty()
|
public void BuyProperty()
|
||||||
{
|
{
|
||||||
int position = players[currentPlayer].position; //This is the current position of the player for the property.
|
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
|
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
|
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.
|
avaliableProperties.RemoveAt(i); //Removes the property from the list.
|
||||||
players[currentPlayer].BuyProperty(property); //This buys the property in the player class
|
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.
|
textHandler.updateMoney(players[currentPlayer].money); //This updates the amount of money the player has.
|
||||||
buttonHandler.disableBuying();
|
buttonHandler.disableBuying(); //Removes the buy button.
|
||||||
buttonHandler.enableRollDice();
|
buttonHandler.enableRollDice(); //Re-enables the user to roll the dice.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +217,8 @@ public class Player
|
|||||||
private string name;
|
private string name;
|
||||||
private int playerNumber;
|
private int playerNumber;
|
||||||
public int money; //Initializes the variable for money.
|
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<Property> ownedProperties = new List<Property>();
|
public List<Property> ownedProperties = new List<Property>();
|
||||||
public GameObject player;
|
public GameObject player;
|
||||||
private Movement movement;
|
private Movement movement;
|
||||||
@ -192,6 +226,8 @@ public class Player
|
|||||||
public Player(string playerName, int playerNumber, GameObject player)
|
public Player(string playerName, int playerNumber, GameObject player)
|
||||||
{
|
{
|
||||||
name = playerName;
|
name = playerName;
|
||||||
|
position = 0;
|
||||||
|
inJail = false;
|
||||||
this.playerNumber = playerNumber;
|
this.playerNumber = playerNumber;
|
||||||
money = 1500; //Set the default starting money.
|
money = 1500; //Set the default starting money.
|
||||||
this.player = player;
|
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).
|
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.
|
position += roll; //Add the position with what was rolled.
|
||||||
|
|
||||||
if (position >= 40) //If the player has reached or passed go then...
|
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.
|
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.
|
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
|
//return position; //Returns where the player needs to move to on the board
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToJail() //If the player needs to go to jail.
|
public void GoToJail() //If the player needs to go to jail.
|
||||||
{
|
{
|
||||||
|
int previousPosition = position;
|
||||||
|
Debug.Log("Jailed!!!");
|
||||||
position = 40; //Special position for jail.
|
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.
|
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.
|
public void BuyProperty(Property property) //This function allows the player to own a property.
|
||||||
@ -240,6 +284,11 @@ public class Player
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Pay(int money)
|
||||||
|
{
|
||||||
|
this.money -= money;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Main : MonoBehaviour
|
public class Main : MonoBehaviour
|
||||||
|
@ -17,8 +17,9 @@ public class Movement : MonoBehaviour
|
|||||||
private Main main;
|
private Main main;
|
||||||
|
|
||||||
|
|
||||||
public void Move(int _roll, int playerNumber)
|
public void Move(int previousPosition, int _roll, int playerNumber)
|
||||||
{
|
{
|
||||||
|
position = previousPosition;
|
||||||
roll = _roll;
|
roll = _roll;
|
||||||
movement = true;
|
movement = true;
|
||||||
currentPlayer = playerNumber;
|
currentPlayer = playerNumber;
|
||||||
@ -32,21 +33,36 @@ public class Movement : MonoBehaviour
|
|||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (!movement) return;
|
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]);
|
//Debug.Log(waypoints[current]);
|
||||||
position++;
|
position++;
|
||||||
if (position >= waypoints.Length)
|
if (position >= waypoints.Length-1)
|
||||||
{
|
{
|
||||||
position = 0;
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
players[currentPlayer].transform.position = Vector3.MoveTowards(players[currentPlayer].transform.position,
|
if (!main.board.CheckBuyable(roll))
|
||||||
waypoints[position].transform.position, Time.deltaTime * speed);
|
{
|
||||||
|
main.board.CheckFees();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
players[currentPlayer].transform.position = Vector3.MoveTowards(players[currentPlayer].transform.position, waypoints[position].transform.position, Time.deltaTime * speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@ public class RollDice : MonoBehaviour
|
|||||||
{
|
{
|
||||||
System.Random random = new System.Random();
|
System.Random random = new System.Random();
|
||||||
|
|
||||||
|
private int dice1;
|
||||||
|
private int dice2;
|
||||||
private int current;
|
private int current;
|
||||||
|
private int totalRoll;
|
||||||
private Main main;
|
private Main main;
|
||||||
|
|
||||||
public Button m_RollDice;
|
public Button m_RollDice;
|
||||||
@ -23,8 +26,32 @@ public class RollDice : MonoBehaviour
|
|||||||
m_RollDice.onClick.AddListener(TaskOnClick);
|
m_RollDice.onClick.AddListener(TaskOnClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskOnClick() {
|
void TaskOnClick()
|
||||||
current = random.Next(1, 7) + random.Next(1, 7);
|
{
|
||||||
main.board.MovePlayer(0, current);
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user