Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class DeckOfCards : MonoBehaviour
- {
- public List<GameObject> deck = new List<GameObject>();
- public Transform Hand1Pos;
- public Transform Hand2Pos;
- public Transform Hand3Pos;
- public Transform Hand4Pos;
- public Transform Hand5Pos;
- public Transform Hand6Pos;
- public Transform Hand7Pos;
- private List<GameObject> cards = new List<GameObject>();
- private List<GameObject> hand = new List<GameObject>();
- private int cardsDealt = 0;
- private bool showReset = false;
- void IntroDeal()
- {
- }
- GameObject DealCard()
- {
- if(hand.Count <= 0)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand1Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 1)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand2Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 2)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand3Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 3)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand4Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 4)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand5Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 5)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand6Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- else if(hand.Count == 6)
- {
- int card = Random.Range(0, cards.Count - 1);
- GameObject go = GameObject.Instantiate(cards[card], Hand7Pos.position, Quaternion.identity) as GameObject;
- cards.RemoveAt(card);
- return go;
- }
- if(hand.Count >= 7)
- {
- return null;
- }
- }
- void AddCard()
- {
- GameObject newCard = DealCard();
- hand.Add(newCard);
- cardsDealt ++;
- }
- void Start()
- {
- IntroDeal();
- }
- void GameOver()
- {
- cardsDealt = 0;
- for (int v = 0; v < hand.Count; v++) {
- Destroy(hand[v]);
- }
- hand.Clear();
- cards.Clear();
- cards.AddRange(deck);
- }
- void OnGUI()
- {
- // Deal button
- if (GUI.Button(new Rect(10, 10, 100, 20), "Deal"))
- {
- DealCard ();
- }
- // GameOver button
- if (GUI.Button(new Rect(Screen.width - 110, 10, 100, 20), "GameOver"))
- {
- GameOver();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment