script.blade.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <script type="text/javascript">
  2. var crapsComponent = new Vue({
  3. el: '#crapsComponent',
  4. delimiters: ['@{{', '}}'],
  5. data: {
  6. game: false,
  7. chips: [1, 5, 10, 25, 50, 100],
  8. total: 10000,
  9. max: 2000,
  10. bet: 0,
  11. selectedChip: 1,
  12. alert: 'Place your bets by clicking on the Pass Line',
  13. comeAlert: '',
  14. passChipCount: 0,
  15. passchips: [],
  16. passPoint: 0,
  17. comeChipCount: 0,
  18. currentComeChips: [],
  19. comePoints: [],
  20. oddsChipCount: 0,
  21. oddschips: [],
  22. oddsAlert: '',
  23. rolledOnce: false,
  24. rolled: false,
  25. rollCount: 0,
  26. dice1Text: 'fas fa-dice-two',
  27. dice2Text: 'fas fa-dice-three',
  28. },
  29. methods: {
  30. currencyFormat: function(_num) {
  31. var formatter = new Intl.NumberFormat('en-US', {
  32. style: 'currency',
  33. currency: 'USD',
  34. });
  35. return formatter.format(_num);
  36. },
  37. onPassLine: function() {
  38. var self = this;
  39. if (self.passPoint) return;
  40. self.game = true;
  41. self.alert = 'Place your bets by clicking on the Pass Line';
  42. self.passChipCount += self.selectedChip;
  43. if (self.passchips.indexOf(self.selectedChip) <= -1) {
  44. self.passchips.push(self.selectedChip);
  45. };
  46. self.totalCounter();
  47. },
  48. onComeLine: function() {
  49. var self = this;
  50. if (!self.passPoint) return;
  51. self.game = true;
  52. self.comeAlert = 'Place new bets by clicking on the COME';
  53. self.comeChipCount += self.selectedChip;
  54. if (self.currentComeChips.indexOf(self.selectedChip) <= -1) {
  55. self.currentComeChips.push(self.selectedChip);
  56. };
  57. self.totalCounter();
  58. },
  59. onOddsLine: function() {
  60. var self = this;
  61. if (!self.passPoint) return;
  62. self.oddsAlert = "";
  63. var max = self.passChipCount * 3;
  64. if (self.selectedChip > max || (self.oddsChipCount + self.selectedChip) > max) {
  65. self.oddschips = self.passchips;
  66. self.oddsChipCount = max;
  67. self.oddsAlert = "Max odds bet reached! (x3 of your pass bet)";
  68. } else {
  69. self.oddsChipCount += self.selectedChip;
  70. if (self.oddschips.indexOf(self.selectedChip) <= -1) {
  71. self.oddschips.push(self.selectedChip);
  72. };
  73. }
  74. self.totalCounter();
  75. },
  76. resetGame: function() {
  77. var self = this;
  78. self.passchips = [];
  79. self.passChipCount = 0;
  80. self.passPoint = 0;
  81. self.oddschips = [];
  82. self.oddsChipCount = 0;
  83. self.total = 10000;
  84. self.rolled = false;
  85. setTimeout(function() {
  86. if (self.comePoints.length == 0) {
  87. self.game = false;
  88. };
  89. }, 1)
  90. },
  91. resetComeGame: function() {
  92. var self = this;
  93. self.currentComeChips = [];
  94. self.comeChipCount = 0;
  95. self.currentComeChips = [];
  96. self.comePoints = [];
  97. },
  98. resetOddsGame: function () {
  99. var self = this;
  100. self.oddsChipCount = 0;
  101. self.oddschips = [];
  102. },
  103. onRollDice: function() {
  104. var self = this;
  105. self.rolledOnce = true;
  106. self.rolled = true;
  107. self.dice1 = Math.floor(Math.random() * 6) + 1;
  108. self.dice2 = Math.floor(Math.random() * 6) + 1;
  109. self.dice1Text = 'fas fa-dice-' + self.numtoString(self.dice1);
  110. self.dice2Text = 'fas fa-dice-' + self.numtoString(self.dice2);
  111. if (!self.passPoint || self.comePoints.length > 1) {
  112. self.passGame();
  113. } else {
  114. self.mainGame();
  115. }
  116. },
  117. numtoString: function(_num) {
  118. switch (_num) {
  119. case 1:
  120. return 'one';
  121. break;
  122. case 2:
  123. return 'two';
  124. break;
  125. case 3:
  126. return 'three';
  127. break;
  128. case 4:
  129. return 'four';
  130. break;
  131. case 5:
  132. return 'five';
  133. break;
  134. case 6:
  135. return 'six';
  136. break;
  137. }
  138. },
  139. passGame: function() {
  140. var self = this;
  141. if (self.comePoints.length > 0) {
  142. self.mainGame();
  143. };
  144. self.oddsAlert = '';
  145. if (self.passChipCount == 0) return;
  146. var totalDice = self.dice1 + self.dice2;
  147. if (totalDice == 7 || totalDice == 11) {
  148. self.alert = 'Game Won! You rolled ' + totalDice;
  149. self.resetGame();
  150. } else if (totalDice == 2 || totalDice == 3 || totalDice == 12) {
  151. self.alert = 'Game Lost! You rolled ' + totalDice;
  152. self.resetGame();
  153. } else {
  154. self.passPoint = totalDice;
  155. self.alert = "Roll the dice until you get " + self.passPoint + " to win";
  156. }
  157. },
  158. mainGame: function() {
  159. var self = this;
  160. var totalDice = self.dice1 + self.dice2;
  161. if (self.passChipCount > 0) { //ensure pass game is ongoing
  162. if (totalDice == self.passPoint) {
  163. self.alert = 'Game Won! You rolled ' + totalDice;
  164. if (self.oddsChipCount > 0) {
  165. self.oddsGame();
  166. }else {
  167. self.resetGame();
  168. }
  169. } else if (totalDice == 7) {
  170. self.alert = 'Game Lost! You rolled ' + totalDice;
  171. if (self.oddsChipCount > 0) {
  172. self.oddsGame();
  173. }else {
  174. self.resetGame();
  175. }
  176. };
  177. };
  178. if (self.comePoints.length > 0) {
  179. self.comeAlert = '';
  180. var multipleAlerts = [];
  181. for (var i = 0; i < self.comePoints.length; i++) {
  182. if (totalDice == self.comePoints[i].move) {
  183. multipleAlerts.push('Come Game Won! You rolled ' + totalDice);
  184. self.comePoints.splice(i, 1);
  185. } else if (totalDice == 7) {
  186. multipleAlerts.push('Come Game Lost! You rolled ' + totalDice);
  187. self.comePoints.splice(i, 1);
  188. } else {
  189. multipleAlerts.push("Roll the dice until you also get " + self.comePoints[i].move + " to win");
  190. };
  191. };
  192. self.comeAlert = multipleAlerts.toString();
  193. };
  194. if (self.comePoints.length == 0 && !self.passPoint) {
  195. self.resetGame();
  196. }
  197. if (self.comeChipCount > 0) {
  198. self.comeGame(totalDice);
  199. }
  200. },
  201. comeGame: function(_totalDice) {
  202. var self = this;
  203. if (self.currentComeChips.length > 0) {
  204. if (_totalDice == 7 || _totalDice == 11) {
  205. self.comeAlert = 'Come Game Won! You rolled ' + _totalDice + '\n';
  206. if (self.comePoints.length == 0) {
  207. self.resetComeGame();
  208. }
  209. } else if (_totalDice == 2 || _totalDice == 3 || _totalDice == 12) {
  210. self.comeAlert = 'Come Game Lost! You rolled ' + _totalDice + '\n';
  211. if (self.comePoints.length == 0) {
  212. self.resetComeGame();
  213. }
  214. } else {
  215. var obj = {
  216. move: _totalDice,
  217. chipCount: self.comeChipCount
  218. };
  219. self.comePoints.push(obj);
  220. self.comeAlert = "Roll the dice until you also get " + _totalDice + " to win";
  221. self.comeChipCount = 0;
  222. };
  223. }
  224. },
  225. oddsGame: function() {
  226. var self = this;
  227. if (self.oddsChipCount == 0) return;
  228. var totalDice = self.dice1 + self.dice2;
  229. if (totalDice == self.passPoint) {
  230. self.oddsAlert = 'Odds Game Won! You rolled ' + totalDice;
  231. self.resetGame();
  232. } else if (totalDice == 7) {
  233. self.oddsAlert = 'Odds Game Lost! You rolled ' + totalDice;
  234. self.resetGame();
  235. } else {
  236. self.oddsAlert = "Win you pass point to win your odds!";
  237. }
  238. },
  239. totalCounter: function() {
  240. var self = this;
  241. }
  242. },
  243. mounted: function() {
  244. }
  245. });
  246. </script>