Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hint "Gellow, Start BlackJack by executing your action";
- cardSuits = [
- "Spades", "Hearts", "Diamonds", "Clubs"
- ];
- cardFaces = [
- "2", "3", "4", "5", "6", "7", "8", "9",
- "10", "J", "Q", "K", "A"
- ];
- cardDeck = [];
- dealerCards = [];
- playerCards = [];
- getCard = {
- _cardNumber = _this select 0;
- _cardSuit = floor (_cardNumber / 13);
- _cardFace = _cardNumber % 13;
- [_cardSuit, _cardFace];
- };
- getCardNameFromNumber = {
- format ["%1 %2", (cardSuits select (_this select 0)), (cardFaces select (_this select 1))];
- };
- getCardFromDeck = {
- _card = selectRandom cardDeck;
- // Remove card from deck
- cardDeck deleteAt (cardDeck find _card);
- _card;
- };
- getValueOfCards = {
- _cards = _this select 0;
- _totalValue = 0;
- _aces = 0;
- {
- _card = [_x] call getCard;
- _cardFace = cardFaces select (_card select 1);
- switch (_cardFace) do {
- //Put the aces appart for now
- case "A": { _aces = _aces + 1; };
- case "K": { _totalvalue = _totalValue + 10; };
- case "Q": { _totalvalue = _totalValue + 10; };
- case "J": { _totalvalue = _totalValue + 10; };
- default { _totalValue = _totalValue + (parseNumber _cardFace); };
- };
- } forEach _cards;
- if (_aces > 0) then {
- if (_totalValue + (_aces * 11) > 21) then {
- if ((_totalValue + 11) <= 21 - (_aces - 1)) then {
- _totalValue = _totalValue + 11 + (_aces - 1);
- } else {
- _totalValue = _totalValue + _aces;
- };
- } else {
- _totalValue = _totalValue + (_aces * 11);
- };
- };
- _totalValue;
- };
- handToString = {
- _hand = _this select 0;
- _str = "";
- {
- _str = format ["%1%2, ", _str, ([_x] call getCard) call getCardNameFromNumber];
- } forEach _hand;
- _str;
- };
- dealerGrabCards = {
- while { ([dealerCards] call getValueOfCards) < 17; } do {
- dealerCards append [call getCardFromDeck];
- };
- _dealerValue = [dealerCards] call getValueOfCards;
- _playerValue = [playerCards] call getValueOfCards;
- if (_dealerValue > 21) then {
- hint format [
- "Dealer is > 21 (%4) (%1)!\n\nYou have %2\n\nYour hand value: %3\n\nYou win!",
- [dealerCards] call handToString,
- [playerCards] call handToString,
- _playerValue,
- _dealerValue
- ];
- } else {
- if (_dealerValue isEqualTo _playerValue) then {
- hint format [
- "Dealer has %4 (%1)!\n\nYou have %2\n\nYour hand value: %3\n\nIt Equals, You get your money back.",
- [dealerCards] call handToString,
- [playerCards] call handToString,
- _playerValue,
- _dealerValue
- ];
- } else {
- if (_dealerValue > _playerValue) then {
- hint format [
- "Dealer has %4 (%1)!\n\nYou have %2\n\nYour hand value: %3\n\nThe dealer is closer to 21, You lose!",
- [dealerCards] call handToString,
- [playerCards] call handToString,
- _playerValue,
- _dealerValue
- ];
- } else {
- hint format [
- "Dealer has %4 (%1)!\n\nYou have %2\n\nYour hand value: %3\n\nYou are closer to 21, You win!",
- [dealerCards] call handToString,
- [playerCards] call handToString,
- _playerValue,
- _dealerValue
- ];
- }
- }
- }
- call startBlackjack;
- };
- getPlayerTurnStatus = {
- _playerValue = [playerCards] call getValueOfCards;
- _dealerValue = [dealerCards] call getValueOfCards;
- if (_dealerValue isEqualTo 21) then {
- if (_playerValue isEqualTo 21) then {
- hint format [
- "Dealer has BlackJack (%1 and %2)!\n\nYou have %3\n\nYour hand value: %4\n\nYou have BlackJack too! You get your money back.",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- ([(dealerCards select 1)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- call startBlackjack;
- } else {
- hint format [
- "Dealer has BlackJack (%1 and %2)!\n\nYou have %3\n\nYour hand value: %4\n\nYou Lose!",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- ([(dealerCards select 1)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- call startBlackjack;
- }
- } else {
- if (_playerValue isEqualTo 21) then {
- if ((count playerCards) > 2) then {
- hint format [
- "Dealer has %1\n\You have %2\n\nYour hand value: %3",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- } else {
- hint format [
- "Dealer has %1\n\You have %2\n\nYour hand value: %3\n\nYou have BlackJack!",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- };
- call dealerGrabCards;
- } else {
- if (_playerValue > 21) then {
- hint format [
- "Dealer has %1\n\nYou have %2\n\nYour hand value: %3\n\nYour value is over 21, You Lose!",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- call startBlackjack;
- } else {
- hint format [
- "Dealer has %1\n\nYou have %2\n\nYour hand value: %3",
- ([(dealerCards select 0)] call getCard) call getCardNameFromNumber,
- [playerCards] call handToString,
- _playerValue
- ];
- call giveChoices;
- };
- };
- };
- };
- fold = {
- call dealerGrabCards;
- };
- hit = {
- playerCards append [call getCardFromDeck];
- call getPlayerTurnStatus;
- };
- giveChoices = {
- player addAction ['Fold', {removeAllActions (_this select 0); call fold;}, [player]];
- player addAction ['Hit', {removeAllActions (_this select 0); call hit;}, [player]];
- };
- initBlackjack = {
- _caller = _this select 0;
- if (isNull _caller) exitWith {};
- //reset vars
- cardDeck = [];
- playerCards = [];
- dealerCards = [];
- playerHits = 0;
- // Make the carddeck
- for "_i" from 1 to 52 do {
- cardDeck set [_i - 1, _i];
- };
- // Shuffle the carddeck
- cardDeck call BIS_fnc_arrayShuffle;
- // Get Dealer Cards
- for "_i" from 0 to 1 do {
- dealerCards set [_i, call getCardFromDeck];
- };
- // Give the player cards
- for "_i" from 0 to 1 do {
- playerCards set [_i, call getCardFromDeck];
- };
- call getPlayerTurnStatus;
- };
- startBlackjack = {
- player addAction ['Start Blackjack', {(_this select 0) removeaction (_this select 2); call initBlackjack;}, [player]];
- };
- call startBlackjack;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement