Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Deck
  6. {
  7.     private readonly string[] CARDS = new string[] {
  8.                 "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "Th", "Jh", "Qh", "Kh", "Ah",
  9.                 "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "Ts", "Js", "Qs", "Ks", "As",
  10.                 "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "Td", "Jd", "Qd", "Kd", "Ad",
  11.                 "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "Tc", "Jc", "Qc", "Kc", "Ac"};
  12.     private static readonly int NUM_CARDS = 52;
  13.     private Card[] deck = new Card[NUM_CARDS];
  14.  
  15.  
  16.     public void getNewDeck()
  17.     {
  18.         Card tempCard;
  19.         string tempString;
  20.  
  21.         for (int i = 0; i < NUM_CARDS; i++)
  22.         {
  23.             tempString = CARDS[i];
  24.             tempCard = new Card(tempString[0], tempString[1]);
  25.             deck[i] = tempCard;
  26.         }
  27.     }
  28.  
  29.     public Card[] shuffle()
  30.     {
  31.         System.Random r = new System.Random();
  32.  
  33.         for (int i = NUM_CARDS - 1; i > 0; i--)
  34.         {
  35.             int j = r.Next(0, NUM_CARDS);
  36.             Card temp = deck[i];
  37.             deck[i] = deck[j];
  38.             deck[j] = temp;
  39.         }
  40.         return deck;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement