blackjackPlay.qsrc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # blackjackPlay
  2. minut += 1
  3. gs 'stat'
  4. if $ARGS[0] = 'new':
  5. killvar 'dealerHand'
  6. killvar 'playerHand'
  7. killvar 'playerBets'
  8. killvar 'playerPoints'
  9. dealerHand[] = 0
  10. dealerHand[] = 1
  11. playerHand[] = 2
  12. playerHand[] = 3
  13. cardsDealt = 4
  14. numHands = 1
  15. currentHand = 0
  16. handLosses = 0
  17. numAces = 0
  18. dealerPoints = 0
  19. insurance = 0
  20. betTotal = 0
  21. doubleBet = 0
  22. minBet = 10
  23. maxBet = 500
  24. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/stolbd.jpg"></center>'
  25. *PL 'You are sitting at the blackjack table.'
  26. act 'Bet' : gt 'blackjackPlay', 'bet'
  27. act 'Rules' : gt 'blackjackPlay', 'rules'
  28. act 'Leave' : gt 'cards'
  29. end
  30. if $ARGS[0] = 'rules':
  31. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/crupbd.jpg"></center>'
  32. *PL '<h2><u>Blackjack Rules:</u></h2>'
  33. *P '<ol><li>The player and dealer are each dealt 2 cards after initial bets (<<minBet>> <b>₽</b> - <<maxBet>> <b>₽</b>). The dealer will have 1 face-up card and 1 face-down card.</li>'
  34. *P '<li>Face cards are worth 10 points, aces can double as either 11 or 1, and all other cards are worth their numeric value.</li>'
  35. *P '<li>After the player finishes drawing, the dealer must continue to draw until he has 17 points or more.</li>'
  36. *P '<li>To win, the player must score more points than the dealer, have the dealer bust, or get a blackjack.</li>'
  37. *P '<li>Getting over 21 points is known as a bust, and an automatic loss.</li>'
  38. *P '<li>Getting an ace and a 10 point card in the first 2 cards is known as a blackjack, and is an automatic win which pays 3 : 2.</li>'
  39. *P '<li>If the dealer''s face-up card is an ace, the player can make a side-bet called "insurance" that pays 2 : 1 if the dealer has a blackjack.</li>'
  40. *P '<li>At any time, the player can choose to double his/her bet, which gives the player 1 more card but prevents further draws on that hand.</li>'
  41. *P '<li>If the player''s hand only consists of two cards of equal value, he/she can split them into 2 hands. Each hand must be covered by an amount equal to the original bet.</li>'
  42. *P '<li>The player cannot score a blackjack using a split hand.</li>'
  43. act 'Return' : gt 'blackjackPlay', 'new'
  44. end
  45. if $ARGS[0] = 'bet':
  46. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/stavkabd.jpg"></center>'
  47. playerBets[0] = INPUT('Place your bet.')
  48. if money < playerBets[0]:
  49. MSG 'You don''t have enough money for that bet.'
  50. gt 'blackjackPlay', 'new'
  51. elseif playerBets[0] < minBet:
  52. MSG 'There is a minimum bet of <<minBet>> <b>₽</b>.'
  53. gt 'blackjackPlay', 'new'
  54. elseif playerBets[0] > maxBet:
  55. MSG 'There is a maximum bet of <<maxBet>> <b>₽</b>.'
  56. gt 'blackjackPlay', 'new'
  57. end
  58. betTotal = playerBets[0]
  59. gs 'deckShuffle'
  60. if (deckFace[playerHand[0]] = 1 and deckFace[playerHand[1]] > 9) or (deckFace[playerHand[0]] > 9 and deckFace[playerHand[1]] = 1):
  61. gt 'blackjackPlay', 'blackjack'
  62. elseif deckFace[dealerHand[0]] > 9 and deckFace[dealerHand[1]] = 1:
  63. gt 'blackjackPlay', 'blackjack'
  64. elseif deckFace[dealerCards[0]] = 1:
  65. gt 'blackjackPlay', 'insurance1'
  66. else
  67. gt 'blackjackPlay', 'player'
  68. end
  69. end
  70. if $ARGS[0] = 'blackjack':
  71. gs 'blackjackView', 1
  72. if playerPoints[0] = 21 and dealerPoints = 21:
  73. *PL 'DRAW GAME'
  74. *PL 'You retrieve your bet.'
  75. elseif playerPoints[0] = 21:
  76. *PL 'PLAYER WINS'
  77. *PL 'You receive <<playerBets[0] * 3 / 2>> <b>₽</b> in winnings.'
  78. money += playerBets[0] * 3 / 2
  79. else
  80. *PL 'DEALER WINS'
  81. *PL 'The dealer takes your <<playerBets[0]>> <b>₽</b> bet.'
  82. money -= playerBets[0]
  83. end
  84. act 'Continue' : gt 'blackjackPlay', 'new'
  85. end
  86. if $ARGS[0] = 'insurance1':
  87. gs 'blackjackView'
  88. *PL 'The dealer has an ace showing. Would you like to place a bet for insurance?'
  89. insurance = 0
  90. act 'Bet insurance' :
  91. insurance = INPUT('Place your bet.')
  92. if money < insurance:
  93. MSG 'You don''t have enough money for that bet.'
  94. gt 'blackjackPlay', 'insurance1'
  95. elseif insurance < 0:
  96. MSG 'You cannot bet a negative amount of money.'
  97. gt 'blackjackPlay', 'insurance1'
  98. elseif insurance > playerBets[0] / 2:
  99. MSG 'Insurance cannot exceed half the original bet.'
  100. gt 'blackjackPlay', 'insurance1'
  101. else
  102. gt 'blackjackPlay', 'insurance2'
  103. end
  104. end
  105. act 'No insurance' : gt 'blackjackPlay', 'insurance2'
  106. end
  107. if $ARGS[0] = 'insurance2':
  108. if deckFace[dealerCards[1]] > 9: gs 'blackjackView', 1
  109. if deckFace[dealerCards[1]] < 10: gs 'blackjackView'
  110. if dealerPoints = 21:
  111. *PL 'DEALER WINS'
  112. *P 'The dealer takes your <<playerBets[0]>> <b>₽</b> bet'
  113. if insurance > 0: *P ' but also gives you <<insurance>> <b>₽</b> for your side bet'
  114. *P '.'
  115. money -= playerBets[0]
  116. money += insurance
  117. act 'Continue' : gt 'blackjackPlay', 'new'
  118. else
  119. *PL 'The dealer takes a peek at his hole card; no blackjack.'
  120. if insurance > 0: *P 'He relieves you of <<insurance>> <b>₽</b> for your side bet.'
  121. money -= insurance
  122. act 'Continue' :
  123. CLA
  124. wait 500
  125. gt 'blackjackPlay', 'player'
  126. end
  127. end
  128. end
  129. if $ARGS[0] = 'player':
  130. gs 'blackjackView'
  131. if playerPoints[currentHand] > 21: currentHand += 1 & handLosses += 1 & doubleBet = 0
  132. if playerPoints[currentHand] = 21 or doubleBet = 1: currentHand += 1 & doubleBet = 0
  133. if handLosses = numHands:
  134. *PL 'DEALER WINS'
  135. *P 'The dealer relieves you of <<betTotal>> <b>₽</b>.'
  136. money -= betTotal
  137. act 'Continue' : gt 'blackjackPlay', 'new'
  138. elseif currentHand >= numHands:
  139. *PL 'You can take no further actions.'
  140. act 'Continue' :
  141. CLA
  142. wait 500
  143. gt 'blackjackPlay', 'dealer'
  144. end
  145. else
  146. if numHands = 1:
  147. *PL 'You are considering actions for your hand.'
  148. $text = ''
  149. else
  150. *PL 'You are considering your actions for <b>hand #<<currentHand + 1>></b>.'
  151. $text = 'Hand #<<currentHand + 1>>: '
  152. end
  153. act '<<$text>>Hit' :
  154. i = currentHand * 16 + 2
  155. :loop1
  156. if playerHand[i] ! 0: i += 1 & jump 'loop1'
  157. playerHand[i] = cardsDealt
  158. cardsDealt += 1
  159. *CLR & CLA
  160. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/cartbde.jpg"></center>'
  161. wait 750
  162. gt 'blackjackPlay', 'player'
  163. end
  164. if money >= betTotal + playerBets[currentHand]:
  165. act '<<$text>>Double' :
  166. doubleBet = 1
  167. betTotal += playerBets[currentHand]
  168. playerBets[currentHand] += playerBets[currentHand]
  169. i = currentHand * 16 + 2
  170. :loop2
  171. if playerHand[i] ! 0: i += 1 & jump 'loop2'
  172. playerHand[i] = cardsDealt
  173. cardsDealt += 1
  174. *CLR & CLA
  175. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/cartbde.jpg"></center>'
  176. wait 750
  177. gt 'blackjackPlay', 'player'
  178. end
  179. if playerHand[currentHand * 16 + 2] = 0 and ((deckFace[playerHand[currentHand * 16]] > 9 and deckFace[playerHand[currentHand * 16 + 1]] > 9) or deckFace[playerHand[currentHand * 16]] = deckFace[playerHand[currentHand * 16 + 1]]):
  180. act '<<$text>>Split' :
  181. betTotal += playerBets[currentHand]
  182. playerBets[numHands] = playerBets[currentHand]
  183. numHands += 1
  184. i = (currentHand + 1) * 16
  185. :loop3
  186. if playerHand[i] ! 0: i += 16 & jump 'loop3'
  187. playerHand[i] = playerHand[currentHand * 16 + 1]
  188. playerHand[currentHand * 16 + 1] = cardsDealt
  189. cardsDealt += 1
  190. playerHand[i + 1] = cardsDealt
  191. cardsDealt += 1
  192. *CLR & CLA
  193. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/cartbde.jpg"></center>'
  194. wait 750
  195. gt 'blackjackPlay', 'player'
  196. end
  197. end
  198. end
  199. act '<<$text>>Stay' :
  200. currentHand += 1
  201. CLA
  202. wait 500
  203. if currentHand < numHands: gt 'blackjackPlay', 'player'
  204. if currentHand >= numHands: gt 'blackjackPlay', 'dealer'
  205. end
  206. end
  207. end
  208. if $ARGS[0] = 'dealer':
  209. gs 'blackjackView', 1
  210. if dealerPoints < 17:
  211. act 'Continue' :
  212. i = 2
  213. :loop4
  214. if dealerHand[i] ! 0: i += 1 & jump 'loop4'
  215. dealerHand[i] = cardsDealt
  216. cardsDealt += 1
  217. *CLR & CLA
  218. *PL '<center><img <<$set_imgh>> src="images/locations/city/industrial/casino/cartbde.jpg"></center>'
  219. wait 750
  220. gt 'blackjackPlay', 'dealer'
  221. end
  222. elseif dealerPoints > 21:
  223. betTotal = 0
  224. i = 0
  225. :loop5
  226. if playerPoints[i] <= 21: betTotal += playerBets[i]
  227. i += 1
  228. if i < numHands: jump 'loop5'
  229. *PL 'PLAYER WINS'
  230. *P 'You receive <<betTotal>> <b>₽</b> in winnings.'
  231. money += betTotal
  232. act 'Continue' : gt 'blackjackPlay', 'new'
  233. else
  234. betTotal = 0
  235. i = 0
  236. :loop6
  237. if playerPoints[i] > 21:
  238. betTotal -= playerBets[i]
  239. elseif playerPoints[i] < dealerPoints:
  240. betTotal -= playerBets[i]
  241. elseif playerpoints[i] > dealerPoints:
  242. betTotal += playerBets[i]
  243. end
  244. i += 1
  245. if i < numHands: jump 'loop6'
  246. if betTotal = 0:
  247. *PL 'DRAW GAME'
  248. if numHands = 1: *P 'You retrieve your bet.'
  249. if numHands > 1: *P 'You retrieve your bets.'
  250. elseif betTotal < 0:
  251. *PL 'DEALER WINS'
  252. if numHands > 1: *P 'After taking into account all the hands, you have lost. '
  253. *P 'The dealer relieves you of <<0 - betTotal>> <b>₽</b>.'
  254. else
  255. *PL 'PLAYER WINS'
  256. if numHands > 1: *P 'After taking into account all the hands, you have won. '
  257. *P 'You receive <<betTotal>> <b>₽</b> in winnings.'
  258. end
  259. money += betTotal
  260. act 'Continue' : gt 'blackjackPlay', 'new'
  261. end
  262. end
  263. --- blackjackPlay ---------------------------------