From 6f4c8a85a3387eb0bb174dcbff100caa8fdeb8fc Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Sat, 29 Aug 2020 01:32:07 +0100 Subject: [PATCH] Made it so that the player has to own all the properties in a colour to buy/sell. --- .idea/.idea.Monopoly/.idea/indexLayout.xml | 1 + Assets/Scenes/monopoly.unity | 444 +++++++++++++++++++++ Assets/Scripts/monopoly/ButtonHandler.cs | 2 +- Assets/Scripts/monopoly/Inventory.cs | 109 +++-- Assets/Scripts/monopoly/Main.cs | 95 ++--- Assets/Scripts/monopoly/RollDice.cs | 6 +- 6 files changed, 572 insertions(+), 85 deletions(-) diff --git a/.idea/.idea.Monopoly/.idea/indexLayout.xml b/.idea/.idea.Monopoly/.idea/indexLayout.xml index 5dd61ff..28e982d 100644 --- a/.idea/.idea.Monopoly/.idea/indexLayout.xml +++ b/.idea/.idea.Monopoly/.idea/indexLayout.xml @@ -3,6 +3,7 @@ + Assets Library/PackageCache/com.unity.collab-proxy@1.3.9 Library/PackageCache/com.unity.ext.nunit@1.0.0 Library/PackageCache/com.unity.ide.rider@1.2.1 diff --git a/Assets/Scenes/monopoly.unity b/Assets/Scenes/monopoly.unity index 4823f8b..fbbc7b7 100644 --- a/Assets/Scenes/monopoly.unity +++ b/Assets/Scenes/monopoly.unity @@ -364,6 +364,81 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &85078179 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 85078180} + - component: {fileID: 85078182} + - component: {fileID: 85078181} + m_Layer: 5 + m_Name: Top + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &85078180 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 85078179} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1977242781} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -0.072, y: 116.468} + m_SizeDelta: {x: 433.26605, y: 21.62259} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &85078181 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 85078179} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &85078182 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 85078179} + m_CullTransparentMesh: 0 --- !u!1 &90351256 GameObject: m_ObjectHideFlags: 0 @@ -1144,6 +1219,7 @@ RectTransform: - {fileID: 1029953937} - {fileID: 1111531777} - {fileID: 1871971151} + - {fileID: 653887086} m_Father: {fileID: 0} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1237,6 +1313,7 @@ MonoBehaviour: buyHouse: {fileID: 569742455} buyHouseText: {fileID: 756575550} sellHouse: {fileID: 505820772} + sellHouseText: {fileID: 1720726636} mortgage: {fileID: 516041487} mortgageText: {fileID: 1679217085} --- !u!1 &314548389 @@ -2873,6 +2950,42 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 639335086} m_CullTransparentMesh: 0 +--- !u!1 &653887085 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 653887086} + m_Layer: 5 + m_Name: Messaging + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &653887086 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 653887085} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1977242781} + m_Father: {fileID: 310476697} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &666103012 GameObject: m_ObjectHideFlags: 0 @@ -6629,6 +6742,140 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1325381973} m_CullTransparentMesh: 0 +--- !u!1 &1334990292 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1334990293} + - component: {fileID: 1334990295} + - component: {fileID: 1334990294} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1334990293 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1334990292} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1983450634} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1334990294 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1334990292} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: X + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4281479730 + m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 24 + m_fontSizeBase: 24 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 1 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1334990295 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1334990292} + m_CullTransparentMesh: 0 --- !u!1 &1375901707 GameObject: m_ObjectHideFlags: 0 @@ -8969,6 +9216,83 @@ Transform: m_Father: {fileID: 1621919988} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1977242780 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1977242781} + - component: {fileID: 1977242783} + - component: {fileID: 1977242782} + m_Layer: 5 + m_Name: Panel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1977242781 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1977242780} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 85078180} + - {fileID: 1983450634} + m_Father: {fileID: 653887086} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 335.29407, y: 154.56815} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1977242782 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1977242780} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 0.392} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1977242783 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1977242780} + m_CullTransparentMesh: 0 --- !u!1 &1978267159 GameObject: m_ObjectHideFlags: 0 @@ -9127,6 +9451,126 @@ RectTransform: m_AnchoredPosition: {x: 0, y: -294.8} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &1983450633 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1983450634} + - component: {fileID: 1983450637} + - component: {fileID: 1983450636} + - component: {fileID: 1983450635} + m_Layer: 5 + m_Name: Close Button + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1983450634 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983450633} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1334990293} + m_Father: {fileID: 1977242781} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 206.46, y: 116.47} + m_SizeDelta: {x: 22.386719, y: 21.624939} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1983450635 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983450633} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1983450636} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &1983450636 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983450633} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1983450637 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983450633} + m_CullTransparentMesh: 0 --- !u!1 &1983981045 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/monopoly/ButtonHandler.cs b/Assets/Scripts/monopoly/ButtonHandler.cs index 136c387..24579a1 100644 --- a/Assets/Scripts/monopoly/ButtonHandler.cs +++ b/Assets/Scripts/monopoly/ButtonHandler.cs @@ -39,7 +39,7 @@ public class ButtonHandler : MonoBehaviour void OpenInventory() { - inventoryClass.OpenInventory(); + inventoryClass.UpdateInventory(); GameUI.SetActive(false); PropertyUI.SetActive(true); inventoryText.text = "Close Inventory"; diff --git a/Assets/Scripts/monopoly/Inventory.cs b/Assets/Scripts/monopoly/Inventory.cs index 4ce0b0e..3fc15bf 100644 --- a/Assets/Scripts/monopoly/Inventory.cs +++ b/Assets/Scripts/monopoly/Inventory.cs @@ -22,11 +22,26 @@ public class Inventory : MonoBehaviour public Button buyHouse; public TextMeshProUGUI buyHouseText; public Button sellHouse; + public TextMeshProUGUI sellHouseText; public Button mortgage; public TextMeshProUGUI mortgageText; + private Button lastButton; //This is the function that will be used when the user clicks to open the inventory. - public void OpenInventory() + + public void UpdateInventory() //This is meant to update what is on the property panel when + { + if (inventoryPanel.activeSelf) //This checks if the inventory panel is open. + { + OpenInventory(); //This updates only the inventory panel. + } + else if (propertyPanel.activeSelf) //This checks if the property panel is open. + { + OpenProperties(lastButton); //This updates the properties panel. + } + } + + public void OpenInventory() //This function renders the inventory pannel. { Player currentPlayer = main.board.players[main.board.currentPlayer]; //Initialises the current player to make the code look neater. for (int i = 0; i < properties.Length; i++) //Checks through all of the buttons. @@ -44,6 +59,7 @@ public class Inventory : MonoBehaviour void OpenProperties(Button button) //This functions runs when a property has been clicked on in the inventory. { + lastButton = button; //This caches the previously used button for updating when closed and reopened. Property property = new Property(); //This is used for the property information to make the code look neater. int currentProperty = 50; //This is used for identifying the property in the ownedProperties list - 50 is used if the property wasn't found for some reason. @@ -63,9 +79,11 @@ public class Inventory : MonoBehaviour propertyHouses.text = property.ParseHouses(); //This shows how many houses there are. backButton.onClick.AddListener(CloseProperties); //This adds a listener to go back to the main menu screen for the inventory. - + + //These clears all of the previous listeners. buyHouse.onClick.RemoveAllListeners(); sellHouse.onClick.RemoveAllListeners(); + //These adds listeners to the sell and buy buttons for this specific property. buyHouse.onClick.AddListener(() => BuyHouse(currentProperty, property.property_name)); sellHouse.onClick.AddListener(() => SellHouse(currentProperty, property.property_name)); @@ -93,6 +111,13 @@ public class Inventory : MonoBehaviour break; } + if (!main.board.players[main.board.currentPlayer].CheckColourSet(property.property_group)) //This checks if all of the colour group properties are owned. + { + //If they aren't all owned, the buy and sell buttons will be disabled. + buyHouse.interactable = false; + sellHouse.interactable = false; + } + //Buttons if (!main.board.players[main.board.currentPlayer].ownedProperties[currentProperty].mortgage) //This checks if the property is not mortgaged. { @@ -109,47 +134,60 @@ public class Inventory : MonoBehaviour propertyPanel.SetActive(true); //This shows the property specific menu. } - void BuyHouse(int currentProperty, string propertyName) + void BuyHouse(int currentProperty, string propertyName) //This is the function for the buy button. { - main.board.BuyHouseOnProperty(propertyName); - Property property = main.board.players[main.board.currentPlayer].ownedProperties[currentProperty]; - propertyHouses.text = property.ParseHouses(); - if (property.houses == 4) + main.board.BuyHouseOnProperty(propertyName); //This will pass the buy function in the main script. + + Property property = main.board.players[main.board.currentPlayer].ownedProperties[currentProperty]; //This caches the current property information. + + propertyHouses.text = property.ParseHouses(); //This changes the text for how many houses there are on the property. + + switch (property.houses) //This now checks how many houses there are on the property. { - buyHouseText.text = "Buy Hotel"; - } - else if (property.houses > 4) - { - buyHouseText.text = "Buy Hotel"; - buyHouse.interactable = false; - } - else - { - buyHouseText.text = "Buy House"; + case 4: //This checks if there are enough houses to buy a hotel now. + buyHouseText.text = "Buy Hotel"; //This changes the text on the button to buying a hotel. + sellHouseText.text = "Sell House"; //This changes the text on the button to selling a house. + break; + case 5: //This checks if the property has reached its limit on buying properties. + buyHouseText.text = "Buy Hotel"; //This changes the text on the button to buying a hotel. + sellHouseText.text = "Sell Hotel"; //This changes the text on the button to selling a hotel. + buyHouse.interactable = false; //This disables the user from buying more houses. + break; + default: + buyHouseText.text = "Buy House"; //If there aren't enough for a hotel, the button will display Buy House. + sellHouseText.text = "Sell House"; //This changes the button text to selling a house. + break; } - sellHouse.interactable = true; + sellHouse.interactable = true; //As when a property will be bought, it will immediately allow the user to sell their houses. } - void SellHouse(int currentProperty, string propertyName) + void SellHouse(int currentProperty, string propertyName) //This is the function for the buy button. { - main.board.SellHouseOnProperty(propertyName); - Property property = main.board.players[main.board.currentPlayer].ownedProperties[currentProperty]; - propertyHouses.text = property.ParseHouses(); - if (property.houses == 0) - { - sellHouse.interactable = false; - } - else if (property.houses < 4) - { - buyHouseText.text = "Buy House"; - } - else if (property.houses >= 4) - { - buyHouseText.text = "Buy Hotel"; - } + main.board.SellHouseOnProperty(propertyName); //This will pass the sell function in the main script. - buyHouse.interactable = true; + Property property = main.board.players[main.board.currentPlayer].ownedProperties[currentProperty]; //This caches the current property information. + + propertyHouses.text = property.ParseHouses(); //This changes the text for how many houses there are on the property. + + switch (property.houses) //This now checks how many houses there are on the property. + { + case 0: //This checks if there are 0 houses left. + buyHouseText.text = "Buy House"; //This changes the button text to buying a house. + sellHouseText.text = "Sell House"; //This changes the button text to selling a house. + sellHouse.interactable = false; //If there are no more houses, the player can't sell anymore, so the sell button will be disabled. + break; + case 4: //This is for when they have sold the hotel. + buyHouseText.text = "Buy Hotel"; //This changes the button text to buying a hotel. + sellHouseText.text = "Sell House"; //This changes the button text to selling a house. + break; + default: + buyHouseText.text = "Buy House"; //This changes the button text to buying a house. + sellHouseText.text = "Sell House"; //This changes the button text to selling a house. + break; + } + + buyHouse.interactable = true; //As when a property is sold, it means that the houses aren't at its max and hence enables the buy button. } void Mortgage(int currentProperty) //This function runs when the Mortgage button has been pressed. @@ -174,6 +212,7 @@ public class Inventory : MonoBehaviour void CloseProperties() //This closes the property specific window and goes to the inventory main menu. { + OpenInventory(); //This updates the inventory panel. propertyPanel.SetActive(false); //This closes the property specific window. inventoryPanel.SetActive(true); //This opens the inventory main menu. } diff --git a/Assets/Scripts/monopoly/Main.cs b/Assets/Scripts/monopoly/Main.cs index 9b85801..d4864be 100644 --- a/Assets/Scripts/monopoly/Main.cs +++ b/Assets/Scripts/monopoly/Main.cs @@ -223,20 +223,20 @@ public class Board //Creating the class for the board mechanics. return false; //Returns false if the property is not buybale. } - public (int, int) FindOwner(string propertyName) + public (int, int) FindOwner(string propertyName) //This function is used to find the property and the owner of it. { - for (int i = 0; i < players.Count; i++) + for (int i = 0; i < players.Count; i++) //This is the loop for the amount of players playing. { - for (int j = 0; j < players[i].ownedProperties.Count; j++) + for (int j = 0; j < players[i].ownedProperties.Count; j++) //This is the loop for the amount of properties the currently searched player owns. { - if (players[i].ownedProperties[j].property_name == propertyName) + if (players[i].ownedProperties[j].property_name == propertyName) //This checks if the property name parameter matches the one that the player owns. { - return (i, j); + return (i, j); //It returns the player then the property position. } } } - return (0, 0); + return (0, 0); //Default error. } public void BuyProperty() @@ -270,90 +270,95 @@ public class Board //Creating the class for the board mechanics. } - public void BuyHouseOnProperty(string propertyName) + public void BuyHouseOnProperty(string propertyName) //This function links the UI button and this class to buy properties. { - var location = FindOwner(propertyName); + var location = FindOwner(propertyName); //This function finds the owner and the position of the property in the owner's list of properties. - Property property = players[location.Item1].ownedProperties[location.Item2]; + Property property = players[location.Item1].ownedProperties[location.Item2]; //This caches the property information that was selected. - if (property.houses < 4) + if (!players[location.Item1].CheckColourSet(property.property_group)) //This checks if the player owns all of the properties in the group. { - if (BuyHouse()) + return; //This stops the function if they don't own all the properties in the group. + } + + if (property.houses < 4) //This checks if the property has less than 4 houses. + { + if (BuyHouse()) //This then buys a house locally. { - players[location.Item1].ownedProperties[location.Item2].addHouse(); + players[location.Item1].ownedProperties[location.Item2].addHouse(); //This then buys the house in the Property class. } } - else if (property.houses == 4) + else if (property.houses == 4) //This checks if the property has enough houses to buy a hotel. { - if (BuyHotel()) + if (BuyHotel()) //This buys a hotel locally. { - players[location.Item1].ownedProperties[location.Item2].addHouse(); + players[location.Item1].ownedProperties[location.Item2].addHouse(); //This then buys the hotel in the Property class. } } - players[location.Item1].Pay(Convert.ToInt32(property.property_cost)); + players[location.Item1].Pay(Convert.ToInt32(property.property_cost)); //This then makes the player pay for the house that they bought. } - public void SellHouseOnProperty(string propertyName) + public void SellHouseOnProperty(string propertyName) //This function links the UI button and this class to sell properties. { - var location = FindOwner(propertyName); + var location = FindOwner(propertyName); //This function finds the owner and the position of the property in the owner's list of properties. - Property property = players[location.Item1].ownedProperties[location.Item2]; + Property property = players[location.Item1].ownedProperties[location.Item2]; //This caches the property information that was selected. - if (property.houses <= 4 && property.houses > 0) + if (property.houses <= 4 && property.houses > 0) //This checks if the properties has a house(s). { - SellHouse(); - players[location.Item1].ownedProperties[location.Item2].removeHouse(); + SellHouse(); //This then locally sells the house(s) locally. + players[location.Item1].ownedProperties[location.Item2].removeHouse(); //This then removes the house in the Property class. } - else if (property.houses == 5) + else if (property.houses == 5) //This checks if the property has a hotel. { - if (SellHotel()) + if (SellHotel()) //This then sells the hotel locally. { - players[location.Item1].ownedProperties[location.Item2].removeHouse(); + players[location.Item1].ownedProperties[location.Item2].removeHouse(); //This then removes the hotel in the Property class. } } - players[location.Item1].Pay(Convert.ToInt32(property.property_cost)/-2); + players[location.Item1].Pay(Convert.ToInt32(property.property_cost)/-2); //This then gives back the money to the player for half the house/hotel's cost. } - private bool BuyHouse() + private bool BuyHouse() //This function is used to buy houses locally. { - if (houses > 0) + if (houses > 0) //This checks if there are enough houses to buy. { - houses--; - return true; + houses--; //This removes a house from the board as the house can be bought. + return true; //This says that the house can be bought. } - return false; + return false; //This says that the house cannot be bought. } - private void SellHouse() + private void SellHouse() //This function is used to sell a house locally. { - houses++; + houses++; //This adds a house to the board as the house has been sold. } - private bool BuyHotel() + private bool BuyHotel() //This function is used to buy a hotel locally. { - if (hotels > 0) + if (hotels > 0) //This checks if there are enough hotels on the board. { - houses += 4; - hotels--; - return true; + houses += 4; //This adds 4 houses to the board as the player only has a hotel now. + hotels--; //This removes a hotel from the board. + return true; //This says that the hotel can be bought. } - return false; + return false; //This says that the hotel cannot be bought. } - private bool SellHotel() + private bool SellHotel() //This function is used to sell a hotel locally. { - if (houses >= 4) + if (houses >= 4) //This first checks if there are enough houses to sell the hotel. { - houses -= 4; - hotels++; - return true; + houses -= 4; //This removes 4 houses from the board and gives it to the property. + hotels++; //This then adds a hotel to the board. + return true; //This returns true to say that the hotel can be sold. } - return false; + return false; //This returns false to say that the hotel cannot be sold. } } diff --git a/Assets/Scripts/monopoly/RollDice.cs b/Assets/Scripts/monopoly/RollDice.cs index 8394f89..9204e40 100644 --- a/Assets/Scripts/monopoly/RollDice.cs +++ b/Assets/Scripts/monopoly/RollDice.cs @@ -1,6 +1,4 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; using UnityEngine.UI; public class RollDice : MonoBehaviour @@ -54,4 +52,4 @@ public class RollDice : MonoBehaviour main.board.MovePlayer(totalRoll); } -} +} \ No newline at end of file