diff --git a/Assets/GameVariables.asset b/Assets/GameVariables.asset new file mode 100644 index 0000000..9d43359 --- /dev/null +++ b/Assets/GameVariables.asset @@ -0,0 +1,34 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9f37e854902a46cb8bd927cf84ab450c, type: 3} + m_Name: GameVariables + m_EditorClassIdentifier: + bgTilePrefabs: {fileID: 2914066502361773997, guid: 3f39182b81f944a4d93213431acb41c3, + type: 3} + bombPrefab: {fileID: 5652386976359944012, guid: aa0291e650b382941875040db9e8a232, + type: 3} + gemsPrefabs: + - {fileID: 3808538059049426536, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} + - {fileID: 4490600519223577409, guid: 784323496d719684cb6201b200b95864, type: 3} + - {fileID: 745607475630438949, guid: 93bd623174244c047af9ce43cc254c32, type: 3} + - {fileID: 6213027626580313688, guid: 473855e3d0d3c8143836b678c9a1b8b5, type: 3} + - {fileID: 1845825807271331471, guid: 91ba2370328500d4db689dad894b1602, type: 3} + destroyEffectPrefabs: [] + bonusAmount: 0.5 + bombChance: 2 + dropHeight: 0 + gemSpeed: 7 + scoreSpeed: 5 + width: 7 + height: 7 + rowsSize: 7 + colsSize: 7 diff --git a/Assets/GameVariables.asset.meta b/Assets/GameVariables.asset.meta new file mode 100644 index 0000000..5287795 --- /dev/null +++ b/Assets/GameVariables.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: edd9a973e745f4f41bce834af2c68d05 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Gems/Bomb Variant.prefab b/Assets/Prefabs/Gems/Bomb Variant.prefab index d40c3f1..2d50b4f 100644 --- a/Assets/Prefabs/Gems/Bomb Variant.prefab +++ b/Assets/Prefabs/Gems/Bomb Variant.prefab @@ -5,6 +5,7 @@ PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: + serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, @@ -55,6 +56,11 @@ PrefabInstance: value: objectReference: {fileID: 8968486364681163996, guid: 05c754e3d4f9fd349ac1def58d17670f, type: 3} + - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} propertyPath: m_LocalPosition.x @@ -70,6 +76,11 @@ PrefabInstance: propertyPath: m_LocalPosition.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} propertyPath: m_LocalRotation.x @@ -85,16 +96,6 @@ PrefabInstance: propertyPath: m_LocalRotation.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, - type: 3} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - target: {fileID: 7667143225876670887, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -110,5 +111,31 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 7667143225876670874, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + insertIndex: -1 + addedObject: {fileID: 5350632371355805727} m_SourcePrefab: {fileID: 100100000, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} +--- !u!1 &1210587634127288510 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 7667143225876670874, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + m_PrefabInstance: {fileID: 8839428272799928612} + m_PrefabAsset: {fileID: 0} +--- !u!114 &5350632371355805727 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1210587634127288510} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7645dd1d371740729311dd834ab649f3, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/Gems/Gem - Blue.prefab b/Assets/Prefabs/Gems/Gem - Blue.prefab index 6547f1c..0dcaa4c 100644 --- a/Assets/Prefabs/Gems/Gem - Blue.prefab +++ b/Assets/Prefabs/Gems/Gem - Blue.prefab @@ -10,8 +10,8 @@ GameObject: m_Component: - component: {fileID: 7667143225876670887} - component: {fileID: 7667143225876670884} - - component: {fileID: -7932498854989450506} - component: {fileID: -4313073739878660840} + - component: {fileID: 3808538059049426536} m_Layer: 0 m_Name: Gem - Blue m_TagString: Untagged @@ -26,12 +26,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7667143225876670874} + serializedVersion: 2 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7667143225876670884 SpriteRenderer: @@ -44,10 +45,12 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 0 + m_RayTraceProcedural: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -83,25 +86,6 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!114 &-7932498854989450506 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7667143225876670874} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c5d1e13e319aa044e9776fbd351e9d03, type: 3} - m_Name: - m_EditorClassIdentifier: - posIndex: {x: 0, y: 0} - type: 0 - isMatch: 0 - destroyEffect: {fileID: 8904178830182364799, guid: d794be08823edd34da1790efd1739074, - type: 3} - scoreValue: 10 - blastSize: 1 --- !u!61 &-4313073739878660840 BoxCollider2D: m_ObjectHideFlags: 0 @@ -112,6 +96,25 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 @@ -128,3 +131,15 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.95, y: 0.95} m_EdgeRadius: 0 +--- !u!114 &3808538059049426536 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7667143225876670874} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7645dd1d371740729311dd834ab649f3, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/RootLifetimeScope.prefab b/Assets/Prefabs/RootLifetimeScope.prefab index 4412f5c..da3c60c 100644 --- a/Assets/Prefabs/RootLifetimeScope.prefab +++ b/Assets/Prefabs/RootLifetimeScope.prefab @@ -10,6 +10,7 @@ GameObject: m_Component: - component: {fileID: 5754733557323264208} - component: {fileID: 7273189601935488900} + - component: {fileID: 5589707646945116404} m_Layer: 0 m_Name: RootLifetimeScope m_TagString: Untagged @@ -48,3 +49,15 @@ MonoBehaviour: TypeName: autoRun: 1 autoInjectGameObjects: [] +--- !u!114 &5589707646945116404 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8304424163596944933} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 51137073af0548959f4e16ceffc344b5, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scenes/Scene_Submission.unity b/Assets/Scenes/Scene_Submission.unity index 79bb11a..25a9f62 100644 --- a/Assets/Scenes/Scene_Submission.unity +++ b/Assets/Scenes/Scene_Submission.unity @@ -151,8 +151,6 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 376092240} - - {fileID: 1445334646} - {fileID: 259844899} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -224,50 +222,6 @@ Transform: m_Children: [] m_Father: {fileID: 3199143} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &376092239 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 376092240} - - component: {fileID: 376092241} - m_Layer: 0 - m_Name: SC_GameLogic - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &376092240 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 376092239} - serializedVersion: 2 - 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_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 3199143} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &376092241 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 376092239} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: db185b18195d3814aab9ba4ac5f95047, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -810,66 +764,6 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!1 &1445334645 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1445334646} - - component: {fileID: 1445334647} - m_Layer: 0 - m_Name: SC_GameVariables - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1445334646 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1445334645} - serializedVersion: 2 - 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_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 3199143} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1445334647 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1445334645} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3b3b891bcdf21df4ab82ea34c3afc99e, type: 3} - m_Name: - m_EditorClassIdentifier: - bgTilePrefabs: {fileID: 2914066502361773997, guid: 3f39182b81f944a4d93213431acb41c3, - type: 3} - bomb: {fileID: 7728721766547317714, guid: aa0291e650b382941875040db9e8a232, type: 3} - gems: - - {fileID: -7932498854989450506, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} - - {fileID: 1972979191936378847, guid: 784323496d719684cb6201b200b95864, type: 3} - - {fileID: 3416069867743778491, guid: 93bd623174244c047af9ce43cc254c32, type: 3} - - {fileID: 8289337781777951430, guid: 473855e3d0d3c8143836b678c9a1b8b5, type: 3} - - {fileID: 4372168081761593873, guid: 91ba2370328500d4db689dad894b1602, type: 3} - bonusAmount: 0.5 - bombChance: 3 - dropHeight: 1 - gemSpeed: 7 - scoreSpeed: 5 - rowsSize: 7 - colsSize: 7 --- !u!1 &1450061018 GameObject: m_ObjectHideFlags: 0 @@ -1037,6 +931,56 @@ Transform: - {fileID: 1136728301} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2056718315 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2056718317} + - component: {fileID: 2056718316} + m_Layer: 0 + m_Name: LevelScope + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &2056718316 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2056718315} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a1e22ac45ff5446daf1aaa01329759a9, type: 3} + m_Name: + m_EditorClassIdentifier: + parentReference: + TypeName: Scopes.RootLifetimeScope + autoRun: 1 + autoInjectGameObjects: [] + gameVariables: {fileID: 11400000, guid: edd9a973e745f4f41bce834af2c68d05, type: 2} + gemsHolder: {fileID: 1740955909} +--- !u!4 &2056718317 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2056718315} + serializedVersion: 2 + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -1046,3 +990,4 @@ SceneRoots: - {fileID: 1740955909} - {fileID: 1450061022} - {fileID: 3199143} + - {fileID: 2056718317} diff --git a/Assets/Scripts/Scopes/LevelLifetimeScope.cs b/Assets/Scripts/Scopes/LevelLifetimeScope.cs new file mode 100644 index 0000000..67eea6b --- /dev/null +++ b/Assets/Scripts/Scopes/LevelLifetimeScope.cs @@ -0,0 +1,39 @@ +using Models; +using Models.Interfaces; +using ScriptableObjects; +using Services; +using Services.Interfaces; +using UnityEngine; +using VContainer; +using VContainer.Unity; +using Views; + +namespace Scopes +{ + public class LevelLifetimeScope : LifetimeScope + { + [SerializeField] private GameVariables gameVariables; + [SerializeField] private Transform gemsHolder; + + protected override void Configure(IContainerBuilder builder) + { + builder.RegisterInstance(this.gameVariables); + builder.RegisterInstance(this.gemsHolder); + + builder.Register(c => + new GameBoard(this.gameVariables.width, this.gameVariables.height), + Lifetime.Scoped); + + builder.Register(Lifetime.Scoped); + builder.Register(Lifetime.Scoped); + + builder.Register>(c => + new ObjectPoolService(this.gameVariables.gemsPrefabs, this.gemsHolder, this.gameVariables.width * this.gameVariables.height), + Lifetime.Scoped); + + builder.Register(Lifetime.Scoped); + + builder.RegisterEntryPoint(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Scopes/LevelLifetimeScope.cs.meta b/Assets/Scripts/Scopes/LevelLifetimeScope.cs.meta new file mode 100644 index 0000000..a0b23ee --- /dev/null +++ b/Assets/Scripts/Scopes/LevelLifetimeScope.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a1e22ac45ff5446daf1aaa01329759a9 +timeCreated: 1765676452 \ No newline at end of file diff --git a/Assets/Scripts/Scopes/RootLifetimeScope.cs b/Assets/Scripts/Scopes/RootLifetimeScope.cs index 5a866d9..f739e4b 100644 --- a/Assets/Scripts/Scopes/RootLifetimeScope.cs +++ b/Assets/Scripts/Scopes/RootLifetimeScope.cs @@ -1,10 +1,14 @@ +using Services; +using Services.Interfaces; using VContainer; using VContainer.Unity; namespace Scopes { public class RootLifetimeScope : LifetimeScope { - protected override void Configure(IContainerBuilder builder) { - + protected override void Configure(IContainerBuilder builder) + { + builder.RegisterComponentInHierarchy() + .As(); } } } \ No newline at end of file diff --git a/Assets/Scripts/ScriptableObjects/GameVariables.cs b/Assets/Scripts/ScriptableObjects/GameVariables.cs index 6ac8a16..fabc141 100644 --- a/Assets/Scripts/ScriptableObjects/GameVariables.cs +++ b/Assets/Scripts/ScriptableObjects/GameVariables.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using Enums; using UnityEngine; using Views; @@ -14,6 +16,8 @@ namespace ScriptableObjects { public int dropHeight = 1; public float gemSpeed = 7; public float scoreSpeed = 5; + public int width; + public int height; [HideInInspector] public int rowsSize = 7; diff --git a/Assets/Scripts/Services/GameBoardService.cs b/Assets/Scripts/Services/GameBoardService.cs index 58fb74c..7ca4e76 100644 --- a/Assets/Scripts/Services/GameBoardService.cs +++ b/Assets/Scripts/Services/GameBoardService.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using Cysharp.Threading.Tasks; @@ -7,6 +6,7 @@ using Models.Interfaces; using ScriptableObjects; using Services.Interfaces; using UnityEngine; +using Utils; using Views; using Object = UnityEngine.Object; using Random = UnityEngine.Random; @@ -17,26 +17,20 @@ namespace Services { private GameVariables gameVariables; private IMatchService matchService; private IScoreService scoreService; + private IObjectPool objectPool; private Transform gemsHolder; - public GameBoardService(IGameBoard gameBoard, GameVariables gameVariables, IMatchService matchService, IScoreService scoreSerivce, Transform gemsHolder) { + public GameBoardService(IGameBoard gameBoard, GameVariables gameVariables, IMatchService matchService, IScoreService scoreSerivce, IObjectPool objectPool, Transform gemsHolder) { this.gameBoard = gameBoard; this.gameVariables = gameVariables; this.matchService = matchService; this.scoreService = scoreSerivce; + this.objectPool = objectPool; this.gemsHolder = gemsHolder; } - - private int RandomGemTypeAsInt() { - GemType[] spawnableGems = Enum.GetValues(typeof(GemType)) - .Cast() - .Where(gType => gType != GemType.Bomb) - .ToArray(); - - return Random.Range(0, spawnableGems.Length); - } public void Setup() { + Debug.Log("Setting up the board"); for (int x = 0; x < this.gameBoard.Width; x++) for (int y = 0; y < this.gameBoard.Height; y++) { @@ -44,29 +38,26 @@ namespace Services { GameObject backgroundTile = Object.Instantiate(this.gameVariables.bgTilePrefabs, position, Quaternion.identity); backgroundTile.transform.SetParent(this.gemsHolder); backgroundTile.name = "BG Tile - " + x + ", " + y; - - - - int gemToUse = RandomGemTypeAsInt(); + + int gemToUse = RandomUtils.RandomGemTypeAsInt(); int iterations = 0; while (this.matchService.MatchesAt(new Vector2Int(x, y), (GemType)gemToUse) && iterations < 100) { - gemToUse = RandomGemTypeAsInt(); + gemToUse = RandomUtils.RandomGemTypeAsInt(); iterations++; } - //ToDo: change gameVariables.gemsPrefabs[gemToUse] since gemToUse is index, if the order changes it wont work SpawnGem(new Vector2Int(x, y), this.gameVariables.gemsPrefabs[gemToUse], (GemType)gemToUse); } } public void SpawnGem(Vector2Int position, GemView gemPrefab, GemType gemType) { + Debug.Log("Spawning gem at " + position + " with type " + gemType + ""); if (Random.Range(0, 100f) < this.gameVariables.bombChance) gemPrefab = this.gameVariables.bombPrefab; - - GemView gemView = Object.Instantiate(gemPrefab, new Vector3(position.x, position.y + this.gameVariables.dropHeight, 0f), Quaternion.identity); - gemView.transform.SetParent(this.gemsHolder); + + GemView gemView = this.objectPool.Get(gemType, position, this.gameVariables.dropHeight); gemView.name = "Gem - " + position.x + ", " + position.y; SetGem(new Vector2Int(position.x,position.y), new Gem(gemType, position)); } @@ -140,7 +131,7 @@ namespace Services { { Gem currentGem = this.gameBoard.GetGemAt(new Vector2Int(x,y)); if (currentGem == null) { - int gemToUse = RandomGemTypeAsInt(); + int gemToUse = RandomUtils.RandomGemTypeAsInt(); SpawnGem(new Vector2Int(x, y), this.gameVariables.gemsPrefabs[gemToUse], (GemType)gemToUse); } } @@ -174,7 +165,8 @@ namespace Services { if (currentGem != null) { GemView gemView = gemsViews.FirstOrDefault(gv => gv.Gem == currentGem); - Object.Instantiate(this.gameVariables.destroyEffectPrefabs[(int)currentGem.Type], new Vector2(position.x, position.y), Quaternion.identity); + if(this.gameVariables.destroyEffectPrefabs.Length > 0) + Object.Instantiate(this.gameVariables.destroyEffectPrefabs[(int)currentGem.Type], new Vector2(position.x, position.y), Quaternion.identity); Object.Destroy(gemView!.gameObject); SetGem(position, null); diff --git a/Assets/Scripts/Services/InputService.cs b/Assets/Scripts/Services/InputService.cs new file mode 100644 index 0000000..83c3766 --- /dev/null +++ b/Assets/Scripts/Services/InputService.cs @@ -0,0 +1,35 @@ +using System; +using Services.Interfaces; +using UnityEngine; + +namespace Services { + public class InputService : MonoBehaviour, IInputService + { + public event Action OnPointerDown; + public event Action OnPointerUp; + + private bool wasDown; + + private void Update() + { + // Mouse + var isDown = Input.GetMouseButton(0); + if (!wasDown && isDown) + OnPointerDown?.Invoke(Input.mousePosition); + + if (wasDown && !isDown) + OnPointerUp?.Invoke(Input.mousePosition); + + wasDown = isDown; + + // Optional: Touch (if you want both, you can merge logic more carefully) + if (Input.touchCount <= 0) return; + + var t = Input.GetTouch(0); + if (t.phase == TouchPhase.Began) + OnPointerDown?.Invoke(t.position); + else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled) + OnPointerUp?.Invoke(t.position); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Services/InputService.cs.meta b/Assets/Scripts/Services/InputService.cs.meta new file mode 100644 index 0000000..6a7ddf8 --- /dev/null +++ b/Assets/Scripts/Services/InputService.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 51137073af0548959f4e16ceffc344b5 +timeCreated: 1765676415 \ No newline at end of file diff --git a/Assets/Scripts/Services/Interfaces/IObjectPool.cs b/Assets/Scripts/Services/Interfaces/IObjectPool.cs index 7ce4b7b..8d2d9e1 100644 --- a/Assets/Scripts/Services/Interfaces/IObjectPool.cs +++ b/Assets/Scripts/Services/Interfaces/IObjectPool.cs @@ -1,8 +1,10 @@ +using Enums; +using UnityEngine; + namespace Services.Interfaces { public interface IObjectPool where T : class { - T Get(); - void Fill(); - void Release(T gameObject); + T Get(GemType type, Vector2Int position, float offsetY); + void Release(T gemView); void Clear(); } } \ No newline at end of file diff --git a/Assets/Scripts/Services/LevelEntryPoint.cs b/Assets/Scripts/Services/LevelEntryPoint.cs new file mode 100644 index 0000000..fd8d55f --- /dev/null +++ b/Assets/Scripts/Services/LevelEntryPoint.cs @@ -0,0 +1,26 @@ +using Services.Interfaces; +using UnityEngine; +using VContainer.Unity; +using Views; + +namespace Services +{ + public class LevelEntryPoint : IStartable + { + private readonly IObjectPool gemViewPool; + private readonly IGameBoardService gameBoardService; + + public LevelEntryPoint(IObjectPool gemViewPool, IGameBoardService gameBoardService) + { + this.gemViewPool = gemViewPool; + this.gameBoardService = gameBoardService; + } + + public void Start() + { + Debug.Log("Level Entry Point"); + this.gameBoardService.Setup(); + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Services/LevelEntryPoint.cs.meta b/Assets/Scripts/Services/LevelEntryPoint.cs.meta new file mode 100644 index 0000000..c22db6a --- /dev/null +++ b/Assets/Scripts/Services/LevelEntryPoint.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e888313cbfdb43e2b11c0e7d1d030fdb +timeCreated: 1765676578 \ No newline at end of file diff --git a/Assets/Scripts/Services/MatchService.cs b/Assets/Scripts/Services/MatchService.cs index 13d5395..951efbe 100644 --- a/Assets/Scripts/Services/MatchService.cs +++ b/Assets/Scripts/Services/MatchService.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Enums; +using Models.Interfaces; using Services.Interfaces; using UnityEngine; @@ -9,9 +10,9 @@ namespace Services { private List currentMatches = new List(); public List CurrentMatches => this.currentMatches; - private GameBoard gameBoard; + private IGameBoard gameBoard; - public MatchService(GameBoard gameBoard) { + public MatchService(IGameBoard gameBoard) { this.gameBoard = gameBoard; } diff --git a/Assets/Scripts/Services/ObjectPoolService.cs b/Assets/Scripts/Services/ObjectPoolService.cs index 80c76b8..1b4d001 100644 --- a/Assets/Scripts/Services/ObjectPoolService.cs +++ b/Assets/Scripts/Services/ObjectPoolService.cs @@ -1,35 +1,49 @@ +using System; using System.Collections; using System.Collections.Generic; +using System.Linq; +using Enums; using Services.Interfaces; using UnityEngine; +using Utils; using Views; +using Object = UnityEngine.Object; +using Random = UnityEngine.Random; namespace Services { public class ObjectPoolService:IObjectPool { - private readonly GemView prefab; + private readonly GemView[] prefabs; private readonly Transform parent; private readonly int size; private readonly Stack pool = new Stack(); - public ObjectPoolService(GemView prefab, Transform parent, int size = 5) { - this.prefab = prefab; + public ObjectPoolService(GemView[] prefabs, Transform parent, int size = 5) { + this.prefabs = prefabs; this.parent = parent; this.size = size; } - public GemView Get() { - return this.pool.Count == 0 ? Object.Instantiate(this.prefab, this.parent) : this.pool.Pop(); - } - - public void Fill() { - for (int i = 0; i < this.size; i++) { - Object.Instantiate(this.prefab, this.parent); + public GemView Get(GemType type, Vector2Int position, float dropHeight) { + int typeAsInt = (int) type; + + GemView gemView; + if (this.pool.Count > 0) { + gemView = this.pool.Pop(); + gemView.transform.localPosition = new Vector2(position.x, position.y + dropHeight); + return gemView; } + + gemView = Object.Instantiate(this.prefabs[typeAsInt], new Vector2(position.x, position.y + dropHeight), Quaternion.identity, this.parent); + return gemView; } - - public void Release(GemView gameObject) { - this.pool.Push(gameObject); + + public void Release(GemView gemView) { + if (gemView == null) + return; + + gemView.gameObject.SetActive(false); + this.pool.Push(gemView); } public void Clear() { diff --git a/Assets/Scripts/Utils.meta b/Assets/Scripts/Utils.meta new file mode 100644 index 0000000..2818716 --- /dev/null +++ b/Assets/Scripts/Utils.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bb63cba0ae32411c8c20c6228c68c922 +timeCreated: 1765680476 \ No newline at end of file diff --git a/Assets/Scripts/Utils/RandomUtils.cs b/Assets/Scripts/Utils/RandomUtils.cs new file mode 100644 index 0000000..306692c --- /dev/null +++ b/Assets/Scripts/Utils/RandomUtils.cs @@ -0,0 +1,17 @@ +using System; +using System.Linq; +using Enums; +using Random = UnityEngine.Random; + +namespace Utils { + public static class RandomUtils { + public static int RandomGemTypeAsInt() { + GemType[] spawnableGems = Enum.GetValues(typeof(GemType)) + .Cast() + .Where(gType => gType != GemType.Bomb) + .ToArray(); + + return Random.Range(0, spawnableGems.Length); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/RandomUtils.cs.meta b/Assets/Scripts/Utils/RandomUtils.cs.meta new file mode 100644 index 0000000..ec687a4 --- /dev/null +++ b/Assets/Scripts/Utils/RandomUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ba833efb34fd4c16a0a2ef2ad6979951 +timeCreated: 1765680493 \ No newline at end of file