blackjackPlay.qsrc 9.0 KB

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