Commit 6cc6c3b3 by alsunj

Upload New File

parent 566fea8e
Showing with 111 additions and 0 deletions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
// Nii mängija kui ka diileri kood
// Kasuta teisi scripte
public CardScript cardScript;
public DeckScript deckScript;
// Total value of player/dealer's hand
public int handValue = 0;
// Betting money
private int money = DBmanager.bank;
//public int money = 5000;
// Massiiv kaartidest, mis tekivad ühes käes/hand
public GameObject[] hand;
// Index uuele kaardile
public int cardIndex = 0;
// Is ace 1 or 11
List<CardScript> aceList = new List<CardScript>();
public void StartHand()
{
GetCard();
GetCard();
}
// Update is called once per frame
public int GetCard()
{
// Get a card
int cardValue = deckScript.DealCard(hand[cardIndex].GetComponent<CardScript>());
// Show card on game screen
hand[cardIndex].GetComponent<Renderer>().enabled = true;
// Hand/käe kogu väärtus
handValue += cardValue;
// Kui väärtus on 1 on tegemist ässaga
if (cardValue == 1)
{
aceList.Add(hand[cardIndex].GetComponent<CardScript>());
}
// Kontroll kas kasutame 1e või 11 ässa väärtusena
AceCheck();
cardIndex++;
return handValue;
}
// Conversion: is ace 1 or 11
public void AceCheck()
{
// for each ace in the ace list
foreach (CardScript ace in aceList)
{
if (handValue + 10 < 22 && ace.GetValueOfCard() == 1)
{
// if converting, adjust card object and hand value
ace.SetValue(11);
handValue += 10;
}
else if (handValue > 21 && ace.GetValueOfCard() == 11)
{
ace.SetValue(1);
handValue -= 10;
}
}
}
// Add or subtract from money, for bets
public void AdjustMoney(int amount)
{
money += amount;
}
// Output players current money amount
public int GetMoney()
{
return money;
}
// Hides all cards, resets the needed variables
public void ResetHand()
{
for (int i = 0; i < hand.Length; i++)
{
hand[i].GetComponent<CardScript>().ResetCard();
hand[i].GetComponent<Renderer>().enabled = false;
}
cardIndex = 0;
handValue = 0;
aceList = new List<CardScript>();
for (int i = 0; i < 2; i++)
{
hand[i].GetComponent<Renderer>().enabled = true;
}
}
}
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