Bloodknight64

DeckOfCards

Oct 30th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class DeckOfCards : MonoBehaviour
  6. {
  7.     public List<GameObject> deck = new List<GameObject>();
  8.    
  9.     public Transform Hand1Pos;
  10.     public Transform Hand2Pos;
  11.     public Transform Hand3Pos;
  12.     public Transform Hand4Pos;
  13.     public Transform Hand5Pos;
  14.     public Transform Hand6Pos;
  15.     public Transform Hand7Pos;
  16.  
  17.     private List<GameObject> cards = new List<GameObject>();
  18.     private List<GameObject> hand = new List<GameObject>();
  19.     private int cardsDealt = 0;
  20.     private bool showReset = false;
  21.  
  22.     void IntroDeal()
  23.     {
  24.            
  25.     }
  26.    
  27.     GameObject DealCard()
  28.     {
  29.         if(hand.Count <= 0)
  30.         {
  31.             int card = Random.Range(0, cards.Count - 1);
  32.             GameObject go = GameObject.Instantiate(cards[card], Hand1Pos.position, Quaternion.identity) as GameObject;
  33.             cards.RemoveAt(card);
  34.             return go;
  35.         }
  36.         else if(hand.Count == 1)
  37.         {
  38.             int card = Random.Range(0, cards.Count - 1);
  39.             GameObject go = GameObject.Instantiate(cards[card], Hand2Pos.position, Quaternion.identity) as GameObject;
  40.             cards.RemoveAt(card);
  41.             return go;
  42.         }
  43.         else if(hand.Count == 2)
  44.         {
  45.             int card = Random.Range(0, cards.Count - 1);
  46.             GameObject go = GameObject.Instantiate(cards[card], Hand3Pos.position, Quaternion.identity) as GameObject;
  47.             cards.RemoveAt(card);
  48.             return go;
  49.         }
  50.         else if(hand.Count == 3)
  51.         {
  52.             int card = Random.Range(0, cards.Count - 1);
  53.             GameObject go = GameObject.Instantiate(cards[card], Hand4Pos.position, Quaternion.identity) as GameObject;
  54.             cards.RemoveAt(card);
  55.             return go;
  56.         }
  57.         else if(hand.Count == 4)
  58.         {
  59.             int card = Random.Range(0, cards.Count - 1);
  60.             GameObject go = GameObject.Instantiate(cards[card], Hand5Pos.position, Quaternion.identity) as GameObject;
  61.             cards.RemoveAt(card);
  62.             return go;
  63.         }
  64.         else if(hand.Count == 5)
  65.         {
  66.             int card = Random.Range(0, cards.Count - 1);
  67.             GameObject go = GameObject.Instantiate(cards[card], Hand6Pos.position, Quaternion.identity) as GameObject;
  68.             cards.RemoveAt(card);
  69.             return go;
  70.         }
  71.         else if(hand.Count == 6)
  72.         {
  73.             int card = Random.Range(0, cards.Count - 1);
  74.             GameObject go = GameObject.Instantiate(cards[card], Hand7Pos.position, Quaternion.identity) as GameObject;
  75.             cards.RemoveAt(card);
  76.             return go;
  77.         }
  78.         if(hand.Count >= 7)
  79.         {
  80.             return null;
  81.         }
  82.     }
  83.    
  84.     void AddCard()
  85.     {
  86.         GameObject newCard = DealCard();
  87.         hand.Add(newCard);
  88.         cardsDealt ++;
  89.     }
  90.  
  91.     void Start()
  92.     {
  93.         IntroDeal();
  94.     }
  95.  
  96.     void GameOver()
  97.     {
  98.        cardsDealt = 0;
  99.        for (int v = 0; v < hand.Count; v++) {
  100.          Destroy(hand[v]);
  101.        }
  102.         hand.Clear();
  103.         cards.Clear();
  104.         cards.AddRange(deck);
  105.     }
  106.  
  107.     void OnGUI()
  108.     {
  109.         // Deal button
  110.         if (GUI.Button(new Rect(10, 10, 100, 20), "Deal"))
  111.         {
  112.             DealCard ();
  113.         }
  114.        
  115.         // GameOver button
  116.         if (GUI.Button(new Rect(Screen.width - 110, 10, 100, 20), "GameOver"))
  117.         {
  118.             GameOver();
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment