script.blade.php 9.9 KB

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