Skip to content

Commit

Permalink
231026
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Oct 25, 2023
1 parent e5b82b8 commit 6258a9f
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion Assets/Script/CardSprite.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using static ManagerCard;
using static UnityEngine.Color;

public sealed class CardSprite : MonoBehaviour
{
Expand All @@ -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<ManagerCard>();
_mouseInput = FindObjectOfType<MouseInput>();

var index = 0;

Expand Down
12 changes: 12 additions & 0 deletions Assets/Script/CountCard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;

public sealed class CountCard : MonoBehaviour
{
private void Update()
{
if (transform.GetComponentInChildren<Transform>().childCount is 13)
{
Destroy(gameObject);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/CountCard.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 36 additions & 4 deletions Assets/Script/ManagerCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ private void Update()

public void DealCard()
{
foreach (var item in Bots)
{
item.Clear();
}

DeckCard = GenerateDeckCard();
ShuffleCard(DeckCard);
SolitaireSort();
Expand Down Expand Up @@ -104,22 +109,36 @@ public void ShuffleCard(List<string> 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<Selectable>().FaceUp = true;
newTopCard.GetComponent<Selectable>().IsDeckPile = true;
});

_deckLocation++;
}
else
{
Expand All @@ -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])
{
Expand All @@ -141,23 +160,36 @@ 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<Selectable>().Row = i;

if (Bots[i][^1] == cardName)
{
newCard.GetComponent<Selectable>().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<ManagerGame>().isplay = true;
}
}

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);
Expand Down
51 changes: 47 additions & 4 deletions Assets/Script/MouseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ManagerCard>();
private void Start()
{
_managerCard = FindObjectOfType<ManagerCard>();
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()
{
Expand All @@ -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<Selectable>().FaceUp)
{
if(!blo)
}
}
else if (hit.collider.CompareTag("PosTop"))
{
Expand All @@ -40,4 +76,11 @@ private void GetMouseClick()
}
}
}

private bool Blocked(GameObject selected)
{
var select=selected.GetComponent<Selectable>();

if(select.i)
}
}
95 changes: 91 additions & 4 deletions Assets/Script/Selectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}

0 comments on commit 6258a9f

Please sign in to comment.