diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 35a3cba..0bf87aa 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1962,6 +1962,37 @@ Rigidbody2D: m_SleepingMode: 1 m_CollisionDetection: 0 m_Constraints: 0 +--- !u!1 &1472046481 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1472046482} + m_Layer: 0 + m_Name: PlayerPrefs + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1472046482 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1472046481} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.55712897, y: 0.7730025, z: 7.508913} + 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!1 &1618202103 GameObject: m_ObjectHideFlags: 0 @@ -2523,3 +2554,4 @@ SceneRoots: - {fileID: 620967028} - {fileID: 1618202105} - {fileID: 7300258972767921120} + - {fileID: 1472046482} diff --git a/Assets/Script/ManagerCard.cs b/Assets/Script/ManagerCard.cs index 57afe0b..5c92450 100644 --- a/Assets/Script/ManagerCard.cs +++ b/Assets/Script/ManagerCard.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -using static UnityEngine.Quaternion; using static System.Linq.Enumerable; +using static UnityEngine.Quaternion; public sealed class ManagerCard : MonoBehaviour { @@ -181,7 +181,7 @@ private IEnumerator CreateDeckCard() } DisCardPile.Clear(); - FindObjectOfType().isplay = true; + FindObjectOfType().IsPlay = true; } } @@ -207,7 +207,7 @@ private void SortDeckIntoTrips() for (var i = 0; i < _trips; i++) { - DeckTrips.Add(Range(0, 3).Select(x => DeckCard[x + index]).ToList()); + DeckTrips.Add(Range(default, 3).Select(x => DeckCard[x + index]).ToList()); index += 3; } @@ -215,7 +215,7 @@ private void SortDeckIntoTrips() { var myRemainders = new List(); - index = 0; + index = default; for (var i = 0; i < _tripsRemainder; i++) { @@ -227,7 +227,7 @@ private void SortDeckIntoTrips() _trips++; } - _deckLocation = 0; + _deckLocation = default; } private void RestacktopDeck() diff --git a/Assets/Script/ManagerGame.cs b/Assets/Script/ManagerGame.cs new file mode 100644 index 0000000..53de50c --- /dev/null +++ b/Assets/Script/ManagerGame.cs @@ -0,0 +1,85 @@ +using UnityEngine; +using UnityEngine.UI; +using static UnityEngine.GameObject; +using static UnityEngine.Mathf; +using static UnityEngine.PlayerPrefs; +using static UnityEngine.Time; + +public sealed class ManagerGame : MonoBehaviour +{ + public GameObject PopUp; + public Text TxtMessage; + public Text TxtYourTime; + public Text TxtCountTime; + public bool IsPlay; + private bool _isTime; + private float _countTime = default; + + private void Start() + { + TxtMessage.text = "Ready !!!"; + TxtYourTime.text = $"your time {DisplayTime(GetYourTime())}"; + PopUp.SetActive(true); + } + + private void Update() + { + var cards = FindGameObjectsWithTag("Card"); + + if (IsPlay && cards.Length <= 0) + { + OverGame(); + } + + if (_isTime) + { + _countTime += deltaTime; + TxtCountTime.text = DisplayTime(_countTime); + } + } + + public void BtnPlayGame() + { + PopUp.SetActive(default); + BtnNewGame(); + } + + public void BtnNewGame() + { + var cards = FindObjectsOfType(); + + foreach (var card in cards) + { + Destroy(card.gameObject); + } + + FindObjectOfType().DealCard(); + _isTime = true; + _countTime = default; + IsPlay = default; + } + + private void OverGame() + { + _isTime = default; + SetYourTime(_countTime); + TxtMessage.text = "You Win!"; + TxtYourTime.text = $"your time {DisplayTime(GetYourTime())}"; + PopUp.SetActive(true); + } + + private void SetYourTime(float time) + { + var yourTime = GetYourTime(); + + if (yourTime > time || yourTime <= 0) + { + SetFloat("time", time); + _ = GetYourTime(); + } + } + + private float GetYourTime() => GetFloat("time"); + + private string DisplayTime(float time) => string.Format("{0:00}:{1:00}", FloorToInt(time / 60), FloorToInt(time % 60)); +} diff --git a/Assets/Script/ManagerGame.cs.meta b/Assets/Script/ManagerGame.cs.meta new file mode 100644 index 0000000..c9799c3 --- /dev/null +++ b/Assets/Script/ManagerGame.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 46a24f5f56dda16408400020427ff60c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/MouseInput.cs b/Assets/Script/MouseInput.cs index ebd3c5e..85566d5 100644 --- a/Assets/Script/MouseInput.cs +++ b/Assets/Script/MouseInput.cs @@ -1,9 +1,10 @@ +using System.Linq; using UnityEngine; using static UnityEngine.Camera; using static UnityEngine.Input; using static UnityEngine.Physics2D; -using static UnityEngine.Vector2; using static UnityEngine.Time; +using static UnityEngine.Vector2; public sealed class MouseInput : MonoBehaviour { @@ -31,12 +32,12 @@ private void Update() if (_times <= 0) { _times = _setTimes; - _clickCount = 0; + _clickCount = default; } if (_clickCount is 3) { - _times = 0; + _times = default; _clickCount = 1; } @@ -60,9 +61,9 @@ private void GetMouseClick() { var selected = hit.collider.gameObject; - if(!selected.GetComponent().FaceUp) + if (!selected.GetComponent().FaceUp) { - if(!blo) + if (!blo) } } else if (hit.collider.CompareTag("PosTop")) @@ -77,10 +78,68 @@ private void GetMouseClick() } } + private void StackBots(GameObject selected) + { + var s1 = Slot.GetComponent(); + var s2 = selected.GetComponent(); + + var yPos = 0.3f; + var zPos = 0.01f; + + for (var i = 0; i <= 13; i++) + { + if (s2.Top || s1.Values == i) + { + yPos = default; + break; + } + } + + Slot.transform.position = new Vector3(selected.transform.position.x, selected.transform.position.y - yPos, selected.transform.position.z - zPos); + Slot.transform.parent = selected.transform; + + if (s1.IsDeckPile) + { + _managerCard.TripsOnDisplay.Remove(Slot.name); + } + else if (s1.Top) + { + if (s2.Top && s1.Values is 1) + { + _managerCard.PosTops[s1.Row].GetComponent().Values = default; + _managerCard.PosTops[s1.Row].GetComponent().Suit = default; + } + else + { + _managerCard.PosTops[s1.Row].GetComponent().Values = s1.Values - 1; + } + } + else + { + _managerCard.Bots[s1.Row].Remove(Slot.name); + } + + s1.IsDeckPile = default; + s1.Row = s2.Row; + + if (s2.Top) + { + _managerCard.PosTops[s1.Row].GetComponent().Values = s1.Values; + _managerCard.PosTops[s1.Row].GetComponent().Suit = s1.Suit; + s1.Top = true; + } + else + { + s1.Top = default; + } + + Slot = gameObject; + } + private bool Blocked(GameObject selected) { - var select=selected.GetComponent(); + var select = selected.GetComponent(); - if(select.i) + return select.IsDeckPile ? select.name != _managerCard.TripsOnDisplay.LastOrDefault() : selected.name != _managerCard.Bots[select.Row].LastOrDefault(); } } diff --git a/Assets/Script/Selectable.cs b/Assets/Script/Selectable.cs index d74e535..5d035f9 100644 --- a/Assets/Script/Selectable.cs +++ b/Assets/Script/Selectable.cs @@ -2,9 +2,9 @@ public sealed class Selectable : MonoBehaviour { - public bool FaceUp = false; - public bool Top = false; - public bool IsDeckPile = false; + public bool FaceUp = default; + public bool Top = default; + public bool IsDeckPile = default; public int Values; public int Row; public string Suit; @@ -92,7 +92,7 @@ private void CheckValue() } default: { - Values = 0; + Values = default; break; } } diff --git a/Assets/Sprites/popup.png b/Assets/Sprites/pop_up.png similarity index 100% rename from Assets/Sprites/popup.png rename to Assets/Sprites/pop_up.png diff --git a/Assets/Sprites/popup.png.meta b/Assets/Sprites/pop_up.png.meta similarity index 100% rename from Assets/Sprites/popup.png.meta rename to Assets/Sprites/pop_up.png.meta