Advertisement
Tyler_Elric

Untitled

Nov 27th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Black Jack </title>
  4. <style type="text/css">
  5. body{
  6. background: #093028;
  7. background: -webkit-linear-gradient(to top, #093028 , #237A57);
  8. background: linear-gradient(to top, #093028 , #237A57);
  9. }
  10.  
  11. hr{
  12. width: 50%;
  13. }
  14.  
  15. td{
  16. width: 100px;
  17. height: 50px;
  18. vertical-align: center;
  19. }
  20.  
  21. html{
  22. font-family: "Lato", sans-serif;
  23. }
  24.  
  25. table {
  26. box-shadow: rgba(0,0,0,.4) 0 4px 8px;
  27. background: rgba(35, 81, 64, 0.7);
  28. border-collapse: collapse;
  29. padding:1em;
  30. color:white;
  31. }
  32.  
  33. table,th,td{
  34. border: none;
  35. text-align: center;
  36. }
  37.  
  38. button {
  39. height: 50px;
  40. width: 120px;
  41. color: white;
  42. background-color: #701D15;
  43. padding:.25em;
  44. border: none;
  45. box-shadow: rgba(0,0,0,.4) 0 4px 5px 1px;
  46. margin-bottom:1em;
  47. margin-left:.5em;
  48. margin-right:.5em;
  49. }
  50.  
  51. #betId::before,
  52. #cashId::before {
  53. content: "$";
  54. }
  55.  
  56. [data-value]::after {
  57. content: attr(data-value);
  58. }
  59.  
  60. </style>
  61. <script type="text/javascript">
  62. var player, dealer, bet, cash, name
  63.  
  64. var player=0;
  65. var dealer=0;
  66. var bet=0;
  67. var cash=500;
  68. var name="Rachel";
  69.  
  70. function showBet ()
  71. {
  72. document.getElementById("betId").dataset.value = bet;
  73. }
  74.  
  75. function incrementBet() {
  76. if(bet+10<=cash) {
  77. bet+=10;
  78. } else {
  79. alert("You can't bet that much! Add more money!");
  80. }
  81. }
  82.  
  83. function getBet()
  84. {
  85. var value = prompt("How much money would you like to bet?");
  86. if (value[0]=="$")
  87. value = value.slice(1);
  88. value= parseInt(value);
  89. if (value>cash){
  90. alert("You can't bet that much! Add more money!");
  91. } else if(value<0) {
  92. alert("Nice try you scamp. You can't bet negative money unless you're the IRS.")
  93. } else{
  94. bet=value;
  95. }
  96. }
  97.  
  98. function play()
  99. {
  100. player += Math.floor((Math.random()*11) + 1);
  101. document.getElementById("playerId").dataset.value = player;
  102. if (player >= 21)
  103. calculateWinnings();
  104. }
  105.  
  106. function calculateWinnings()
  107. {
  108. while (dealer < 18)
  109. {
  110. dealer += Math.floor((Math.random()*11) + 1);
  111. }
  112. cash = cash - bet;
  113. document.getElementById("dealerId").dataset.value = dealer;
  114. if(player > 21)
  115. {
  116. document.getElementById("resultId").innerHTML = "Busted! You lose!";
  117. }
  118. else if (dealer > 21)
  119. {
  120. document.getElementById("resultId").innerHTML = "Dealer Busted! " + name + " wins!";
  121. cash += bet * 2;
  122. }
  123. else if (player == 21)
  124. {
  125. document.getElementById("resultId").innerHTML = name + " got 21!" + name + " wins!"
  126. cash += bet*3;
  127. }
  128. else if (player > dealer)
  129. {
  130. document.getElementById("resultId").innerHTML = name + " wins!"
  131. cash += bet * 2;
  132. }
  133. else if (dealer >= player)
  134. {
  135. document.getElementById("resultId").innerHTML = "Dealer wins!"
  136. }
  137.  
  138. document.getElementById("cashId").dataset.value = cash;
  139. bet = 0;
  140. }
  141.  
  142. function newGame()
  143. {
  144. player = dealer = bet = 0;
  145. document.getElementById("playerId").dataset.value = player;
  146. document.getElementById("dealerId").dataset.value = dealer;
  147. document.getElementById("betId").dataset.value = bet;
  148. document.getElementById("resultId").innerHTML = "";
  149. document.getElementById("cashId").dataset.value = cash;
  150. }
  151.  
  152. function addMoney()
  153. {
  154. var value = prompt("How much money would you like to add?");
  155. cash += parseInt(value);
  156. document.getElementById("cashId").dataset.value = cash;
  157. }
  158.  
  159. </script>
  160.  
  161. </head>
  162. <body>
  163. <center>
  164. <h1> Welcome to Black Jack! </h1>
  165. <table>
  166. <tr>
  167. <th> Your Total </th>
  168. <th> Dealer Total </th>
  169. <th> Bet Amount </th>
  170. <th> Cash Remaining </th>
  171. </tr>
  172. <tr>
  173. <td> <p id='playerId' data-value="0">&nbsp;</p></td>
  174. <td> <p id='dealerId' data-value="0">&nbsp;</p></td>
  175. <td> <p id='betId' data-value="0">&nbsp;</p></td>
  176. <td> <p id='cashId' data-value="500"></p></td>
  177. </tr>
  178.  
  179. </table>
  180.  
  181. <p> Game Result: <b id="resultId"></b></p>
  182.  
  183. <button onclick="incrementBet(); showBet();"> $10 </button>
  184. <button onclick="getBet(); showBet();"> Custom Bet </button>
  185. <button onclick="newGame();"> New Game </button>
  186. <br/>
  187. <button onclick="play();"> Deal Card </button>
  188. <button onclick="calculateWinnings();"> Reveal Cards </button>
  189. <button onclick="addMoney();"> Add Money </button>
  190. <br/>
  191.  
  192.  
  193. </center>
  194.  
  195. </body>
  196.  
  197.  
  198. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement