diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 2785c49..35a3cba 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2090,6 +2090,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1ec7c6587489d4441b9a5f9b57ca0bc6, type: 3} m_Name: m_EditorClassIdentifier: + Slot: {fileID: 0} --- !u!1 &1943609418 GameObject: m_ObjectHideFlags: 0 @@ -2355,7 +2356,7 @@ SpriteRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: dad99cc115f7ec143b4dec916337800f, type: 3} + m_Sprite: {fileID: 21300000, guid: 4e91445daa38b914b8cafafc0c273166, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 @@ -2429,7 +2430,7 @@ BoxCollider2D: m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} - oldSize: {x: 4.07, y: 6.8} + oldSize: {x: 5, y: 7.26} newSize: {x: 4.07, y: 6.8} adaptiveTilingThreshold: 0.5 drawMode: 0 diff --git a/Assets/Script/CardSprite.cs b/Assets/Script/CardSprite.cs index 44bd64b..473b839 100644 --- a/Assets/Script/CardSprite.cs +++ b/Assets/Script/CardSprite.cs @@ -1,5 +1,6 @@ using UnityEngine; using static ManagerCard; +using static UnityEngine.Color; public sealed class CardSprite : MonoBehaviour { @@ -8,14 +9,24 @@ public sealed class CardSprite : MonoBehaviour private SpriteRenderer _displayCard; private ManagerCard _managerCard; private Selectable _selectable; + private MouseInput _mouseInput; private void Start() => SetDeckCard(); - private void Update() => _displayCard.sprite = _selectable.FaceUp ? FaceCard : BackCard; + private void Update() + { + _displayCard.sprite = _selectable.FaceUp ? FaceCard : BackCard; + + if (_mouseInput.Slot) + { + _displayCard.color = name == _mouseInput.Slot.name ? green : white; + } + } private void SetDeckCard() { _managerCard = FindObjectOfType(); + _mouseInput = FindObjectOfType(); var index = 0; diff --git a/Assets/Script/CountCard.cs b/Assets/Script/CountCard.cs new file mode 100644 index 0000000..2e70e4b --- /dev/null +++ b/Assets/Script/CountCard.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +public sealed class CountCard : MonoBehaviour +{ + private void Update() + { + if (transform.GetComponentInChildren().childCount is 13) + { + Destroy(gameObject); + } + } +} diff --git a/Assets/Script/CountCard.cs.meta b/Assets/Script/CountCard.cs.meta new file mode 100644 index 0000000..c8d16f1 --- /dev/null +++ b/Assets/Script/CountCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f1a14da29a79c743843245caa3b20f8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/ManagerCard.cs b/Assets/Script/ManagerCard.cs index f069119..57afe0b 100644 --- a/Assets/Script/ManagerCard.cs +++ b/Assets/Script/ManagerCard.cs @@ -77,6 +77,11 @@ private void Update() public void DealCard() { + foreach (var item in Bots) + { + item.Clear(); + } + DeckCard = GenerateDeckCard(); ShuffleCard(DeckCard); SolitaireSort(); @@ -104,22 +109,36 @@ public void ShuffleCard(List list) public void DealFromDeck() { + foreach (Transform nameCard in DeckButton.transform) + { + if (nameCard.CompareTag("Card")) + { + _ = DeckCard.Remove(nameCard.name); + DisCardPile.Add(nameCard.name); + Destroy(nameCard.gameObject); + } + } + if (_deckLocation < _trips) { TripsOnDisplay.Clear(); var xPos = 2.5f; - var zPos = 0.2f; + var zPos = 0.3f; DeckTrips[_deckLocation].ForEach(x => { var newTopCard = Instantiate(CardPrefab, new Vector3(DeckButton.transform.position.x + xPos, DeckButton.transform.position.y, DeckButton.transform.position.z + zPos), identity, DeckButton.transform); xPos += 0.5f; + zPos -= 0.3f; newTopCard.name = x; TripsOnDisplay.Add(x); newTopCard.GetComponent().FaceUp = true; + newTopCard.GetComponent().IsDeckPile = true; }); + + _deckLocation++; } else { @@ -132,7 +151,7 @@ private IEnumerator CreateDeckCard() for (var i = 0; i < 7; i++) { var ySet = 0f; - var zSet = 0f; + var zSet = 0.3f; foreach (var cardName in Bots[i]) { @@ -141,15 +160,28 @@ private IEnumerator CreateDeckCard() var newCard = Instantiate(CardPrefab, new Vector3(PosBots[i].transform.position.x, PosBots[i].transform.position.y - ySet, transform.position.z - zSet), identity, PosBots[i].transform); newCard.name = cardName; + newCard.GetComponent().Row = i; if (Bots[i][^1] == cardName) { newCard.GetComponent().FaceUp = true; } - ySet += 0.2f; + ySet += 0.3f; zSet += 0.05f; + DisCardPile.Add(cardName); } + + foreach (var item in DisCardPile) + { + if (DeckCard.Contains(item)) + { + _ = DeckCard.Remove(item); + } + } + + DisCardPile.Clear(); + FindObjectOfType().isplay = true; } } @@ -157,7 +189,7 @@ private void SolitaireSort() { for (var i = 0; i < 7; i++) { - for (var j = 0; j < 7; j++) + for (var j = i; j < 7; j++) { Bots[j].Add(DeckCard.LastOrDefault()); DeckCard.RemoveAt(DeckCard.Count - 1); diff --git a/Assets/Script/MouseInput.cs b/Assets/Script/MouseInput.cs index 5fddeed..ebd3c5e 100644 --- a/Assets/Script/MouseInput.cs +++ b/Assets/Script/MouseInput.cs @@ -3,14 +3,45 @@ using static UnityEngine.Input; using static UnityEngine.Physics2D; using static UnityEngine.Vector2; +using static UnityEngine.Time; public sealed class MouseInput : MonoBehaviour { + public GameObject Slot; private ManagerCard _managerCard; + private float _times; + private float _setTimes; + private float _doubleClickTime = 0.5f; + private int _clickCount; - private void Start() => _managerCard = FindObjectOfType(); + private void Start() + { + _managerCard = FindObjectOfType(); + Slot = gameObject; + _setTimes = _times; + } + + private void Update() + { + if (_clickCount is 1) + { + _times -= deltaTime; + } + + if (_times <= 0) + { + _times = _setTimes; + _clickCount = 0; + } - private void Update() => GetMouseClick(); + if (_clickCount is 3) + { + _times = 0; + _clickCount = 1; + } + + GetMouseClick(); + } private void GetMouseClick() { @@ -22,12 +53,17 @@ private void GetMouseClick() { if (hit.collider.CompareTag("Deck")) { - print($"Deck: {hit.collider.name}"); _managerCard.DealFromDeck(); + Slot = gameObject; } else if (hit.collider.CompareTag("Card")) { - print($"Card: {hit.collider.name}"); + var selected = hit.collider.gameObject; + + if(!selected.GetComponent().FaceUp) + { + if(!blo) + } } else if (hit.collider.CompareTag("PosTop")) { @@ -40,4 +76,11 @@ private void GetMouseClick() } } } + + private bool Blocked(GameObject selected) + { + var select=selected.GetComponent(); + + if(select.i) + } } diff --git a/Assets/Script/Selectable.cs b/Assets/Script/Selectable.cs index ee2e182..d74e535 100644 --- a/Assets/Script/Selectable.cs +++ b/Assets/Script/Selectable.cs @@ -3,12 +3,99 @@ public sealed class Selectable : MonoBehaviour { public bool FaceUp = false; + public bool Top = false; + public bool IsDeckPile = false; + public int Values; + public int Row; + public string Suit; + public string ValueString; - private void Start() - { - } + private void Start() => CheckValue(); - private void Update() + private void CheckValue() { + if (CompareTag("Card")) + { + Suit = transform.name[0].ToString(); + + for (var i = 1; i < transform.name.Length; i++) + { + ValueString += transform.name[i].ToString(); + } + + switch (ValueString) + { + case "A": + { + Values = 1; + break; + } + case "2": + { + Values = 2; + break; + } + case "3": + { + Values = 3; + break; + } + case "4": + { + Values = 4; + break; + } + case "5": + { + Values = 5; + break; + } + case "6": + { + Values = 6; + break; + } + case "7": + { + Values = 7; + break; + } + case "8": + { + Values = 8; + break; + } + case "9": + { + Values = 9; + break; + } + case "10": + { + Values = 10; + break; + } + case "J": + { + Values = 11; + break; + } + case "Q": + { + Values = 12; + break; + } + case "K": + { + Values = 13; + break; + } + default: + { + Values = 0; + break; + } + } + } } }