88 lines
2.2 KiB
C#
88 lines
2.2 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class Deck : MonoBehaviour
|
||
|
{
|
||
|
public List<CardData> cardDataList;
|
||
|
public List<CardData> drawList;
|
||
|
public List<CardData> handList;
|
||
|
public List<CardData> discardList;
|
||
|
public List<CardData> wasteList;
|
||
|
public int randomSeed;
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
randomSeed = 200;
|
||
|
Random.InitState(randomSeed);
|
||
|
// Add cards into cardDataList
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
public void DrawCards(int amount)
|
||
|
{
|
||
|
for (int i = 0; i < amount; i++)
|
||
|
{
|
||
|
handList.Add(drawList[drawList.Count - 1]);
|
||
|
drawList.RemoveAt(drawList.Count - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void UseACard(int index)
|
||
|
{
|
||
|
// TODO: Add card type into card data
|
||
|
// Chech if the card is waste card;
|
||
|
//if (handList[index].cardTags == wastCard)
|
||
|
//{
|
||
|
// wasteList.Add(handList[index]);
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
discardList.Add(handList[index]);
|
||
|
//}
|
||
|
handList.RemoveAt(index);
|
||
|
}
|
||
|
public void AddACardIntoDiscardList(CardData card)
|
||
|
{
|
||
|
discardList.Add(card);
|
||
|
}
|
||
|
|
||
|
private void Shuffle()
|
||
|
{
|
||
|
Debug.LogError("Start Shuffle.");
|
||
|
Debug.LogError("DrawList count: " + drawList.Count);
|
||
|
Debug.LogError("DiscardList count: " + discardList.Count);
|
||
|
|
||
|
// Put all cards in drawList into discardList
|
||
|
if (drawList.Count > 0)
|
||
|
{
|
||
|
for (int i = 0; i < drawList.Count; i++)
|
||
|
{
|
||
|
discardList.Add(drawList[i]);
|
||
|
}
|
||
|
drawList.Clear();
|
||
|
}
|
||
|
|
||
|
do
|
||
|
{
|
||
|
int index = Random.Range(0, discardList.Count);
|
||
|
drawList.Add(discardList[index]);
|
||
|
discardList[index] = discardList[discardList.Count - 1];
|
||
|
discardList.RemoveAt(discardList.Count - 1);
|
||
|
} while (discardList.Count != 0);
|
||
|
Debug.LogError("DrawList count: " + drawList.Count);
|
||
|
Debug.LogError("DiscardList count: " + discardList.Count);
|
||
|
Debug.LogError("End Shuffle.");
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|