Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- public class Deck
- {
- //Note the distinct lack of MonoBehavior, it wasn't behaving nicely for Object shit.
- private List<Card> deck = new List<Card>(); // Here we do some Object shit and apparently make it into a list.
- private const int NUMBER_OF_CARDS = 52; // This sets the max number of cards I guess.
- private Random ranNum = new Random(); // Initiates the Random Handler for Shuffeling
- public int Count() { get: return deck.Count; } // returns the remaining Cards in the Deck
- /// <summary>
- /// Initiator of Class "Deck"
- /// </summary>
- public Deck()
- {
- // Initating the Arrays containing all Card Values and Suits
- string[] faces = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
- string[] suits = { "Hearts", "Clubs", "Diamonds", "Spades" };
- // Looping through until we hit the NUMBER_OF_CARDS Limit
- // Each Loop creating a new "Card" Class with it's unique face/suit combination
- for (int count = 0; count < NUMBER_OF_CARDS; count++)
- {
- /*
- * These are for debugging, not used but it's good to see how it's done in Unity since Console.WriteLine doesn't work there.
- */
- //int outcome = count % 13;
- //int outcome2 = count / 13;
- //Debug.Log(outcome);
- //Debug.Log(outcome2);
- // Create new Class "Card" with it's unique face/suit combination
- // Using the Array Length of "faces" (13) to get all cards done nicely
- deck.Add(new Card(faces[count % faces.Length], suits[count / faces.Length]));
- }
- }
- /// <summary>
- /// Shuffles the Deck by randomly repacing Item positions within the Array/List
- /// Or as John wrote: Shuffles the deck, using shit I have no idea about.
- /// </summary>
- public void Shuffle()
- {
- for (int first = 0; first < deck.Count; first++)
- {
- int second = ranNum.Next(deck.Count); // Chooses a random index
- Card temp = deck[first]; // Reference to the Card in the Deck with Index "first" and saves it as Card "temp"
- deck[first] = deck[second]; // Changes the indexed Cards in the Deck which now doubles the Card "deck[second]"
- deck[second] = temp; // Saves the Card "temp" to the Deck, replacing the second double Card from the previous Step
- }
- }
- /// <summary>
- /// Returns the Topmost Card from the Deck
- /// </summary>
- /// <returns>Class: Card</returns>
- public Card DealCard()
- {
- if (deck.Count >= 0) //Checks if there's any cards to draw, maybe.
- {
- Card C = deck[0]; //References to the first Card in the Deck
- deck.Remove(C); // Removes the Card from the Deck
- //Debug.Log(C.ToString()); // debug Stuff again
- return C; // Return Value
- }
- else
- return null; //If shit hits the fan then null. Other code prevents this from happening though. Or it should.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment