Skip to content

Commit

Permalink
231027
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Oct 26, 2023
1 parent 6258a9f commit 5217a30
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 16 deletions.
32 changes: 32 additions & 0 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2523,3 +2554,4 @@ SceneRoots:
- {fileID: 620967028}
- {fileID: 1618202105}
- {fileID: 7300258972767921120}
- {fileID: 1472046482}
10 changes: 5 additions & 5 deletions Assets/Script/ManagerCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -181,7 +181,7 @@ private IEnumerator CreateDeckCard()
}

DisCardPile.Clear();
FindObjectOfType<ManagerGame>().isplay = true;
FindObjectOfType<ManagerGame>().IsPlay = true;
}
}

Expand All @@ -207,15 +207,15 @@ 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;
}

if (_tripsRemainder is not 0)
{
var myRemainders = new List<string>();

index = 0;
index = default;

for (var i = 0; i < _tripsRemainder; i++)
{
Expand All @@ -227,7 +227,7 @@ private void SortDeckIntoTrips()
_trips++;
}

_deckLocation = 0;
_deckLocation = default;
}

private void RestacktopDeck()
Expand Down
85 changes: 85 additions & 0 deletions Assets/Script/ManagerGame.cs
Original file line number Diff line number Diff line change
@@ -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<CardSprite>();

foreach (var card in cards)
{
Destroy(card.gameObject);
}

FindObjectOfType<ManagerCard>().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));
}
11 changes: 11 additions & 0 deletions Assets/Script/ManagerGame.cs.meta

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

73 changes: 66 additions & 7 deletions Assets/Script/MouseInput.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -60,9 +61,9 @@ private void GetMouseClick()
{
var selected = hit.collider.gameObject;

if(!selected.GetComponent<Selectable>().FaceUp)
if (!selected.GetComponent<Selectable>().FaceUp)
{
if(!blo)
if (!blo)
}
}
else if (hit.collider.CompareTag("PosTop"))
Expand All @@ -77,10 +78,68 @@ private void GetMouseClick()
}
}

private void StackBots(GameObject selected)
{
var s1 = Slot.GetComponent<Selectable>();
var s2 = selected.GetComponent<Selectable>();

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<Selectable>().Values = default;
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Suit = default;
}
else
{
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().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<Selectable>().Values = s1.Values;
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Suit = s1.Suit;
s1.Top = true;
}
else
{
s1.Top = default;
}

Slot = gameObject;
}

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

if(select.i)
return select.IsDeckPile ? select.name != _managerCard.TripsOnDisplay.LastOrDefault() : selected.name != _managerCard.Bots[select.Row].LastOrDefault();
}
}
8 changes: 4 additions & 4 deletions Assets/Script/Selectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +92,7 @@ private void CheckValue()
}
default:
{
Values = 0;
Values = default;
break;
}
}
Expand Down
File renamed without changes
File renamed without changes.

0 comments on commit 5217a30

Please sign in to comment.