Commit ce885967 by alsunj

Upload New File

parent 3c1094d6
Showing with 71 additions and 0 deletions
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
public class DeckScript : MonoBehaviour
{
// Get cards form unity for what we give them values
public Sprite[] cardSprites;
// Array for shuffled card values
int[] cardValues = new int[53];
int currentIndex = 0;
void Start()
{
GetCardValues();
}
// Update is called once per frame
void GetCardValues()
{
int num = 0;
// Loop to assign values
for (int i = 0; i < cardSprites.Length; i++)
{
num = i;
// Count up to the amount of cards, 52
num %= 13;
// Kui kaardi vrtus lheb le 10 siis mra ta 10ks
if (num > 10 || num == 0)
{
num = 10;
}
cardValues[i] = num++;
}
}
public void Shuffle()
{
// Tavaline massiivi andmete vahetaja
for (int i = cardSprites.Length - 1; i > 0; --i)
{
int j = Mathf.FloorToInt(Random.Range(0.0f, 1.0f) * (cardSprites.Length - 1)) + 1;
Sprite face = cardSprites[i];
cardSprites[i] = cardSprites[j];
cardSprites[j] = face;
int value = cardValues[i];
cardValues[i] = cardValues[j];
cardValues[j] = value;
}
currentIndex = 1;
}
// give out next card
public int DealCard(CardScript cardScript)
{
cardScript.SetSprite(cardSprites[currentIndex]);
cardScript.SetValue(cardValues[currentIndex]);
currentIndex++;
return cardScript.GetValueOfCard();
}
public Sprite GetCardBack()
{
return cardSprites[0];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment