script.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.total -= self.selectedChip;
  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.total -= self.selectedChip;
  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.total -= self.oddsChipCount;
  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.rolled = false;
  85. setTimeout(function() {
  86. if (self.comePoints.length == 0) {
  87. self.game = false;
  88. };
  89. }, 1)
  90. },
  91. resetPassGame: function() {
  92. var self = this;
  93. self.total += self.passChipCount;
  94. self.passChipCount = 0;
  95. self.passchips = [];
  96. self.game = false;
  97. },
  98. resetComeGame: function() {
  99. var self = this;
  100. self.currentComeChips = [];
  101. self.comeChipCount = 0;
  102. self.currentComeChips = [];
  103. self.comePoints = [];
  104. },
  105. resetOddsGame: function () {
  106. var self = this;
  107. self.total += self.oddsChipCount;
  108. self.oddsChipCount = 0;
  109. self.oddschips = [];
  110. },
  111. onRollDice: function() {
  112. var self = this;
  113. self.rolledOnce = true;
  114. self.rolled = true;
  115. self.dice1 = Math.floor(Math.random() * 6) + 1;
  116. self.dice2 = Math.floor(Math.random() * 6) + 1;
  117. self.dice1Text = 'fas fa-dice-' + self.numtoString(self.dice1);
  118. self.dice2Text = 'fas fa-dice-' + self.numtoString(self.dice2);
  119. if (!self.passPoint || self.comePoints.length > 1) {
  120. self.passGame();
  121. } else {
  122. self.mainGame();
  123. }
  124. },
  125. numtoString: function(_num) {
  126. switch (_num) {
  127. case 1:
  128. return 'one';
  129. break;
  130. case 2:
  131. return 'two';
  132. break;
  133. case 3:
  134. return 'three';
  135. break;
  136. case 4:
  137. return 'four';
  138. break;
  139. case 5:
  140. return 'five';
  141. break;
  142. case 6:
  143. return 'six';
  144. break;
  145. }
  146. },
  147. passGame: function() {
  148. var self = this;
  149. if (self.comePoints.length > 0) {
  150. self.mainGame();
  151. };
  152. self.oddsAlert = '';
  153. if (self.passChipCount == 0) return;
  154. var totalDice = self.dice1 + self.dice2;
  155. if (totalDice == 7 || totalDice == 11) {
  156. self.alert = 'Game Won! You rolled ' + totalDice;
  157. self.total += (self.passChipCount * 2);
  158. self.resetGame();
  159. } else if (totalDice == 2 || totalDice == 3 || totalDice == 12) {
  160. self.alert = 'Game Lost! You rolled ' + totalDice;
  161. self.resetGame();
  162. } else {
  163. self.passPoint = totalDice;
  164. self.alert = "Roll the dice until you get " + self.passPoint + " to win";
  165. }
  166. },
  167. mainGame: function() {
  168. var self = this;
  169. var totalDice = self.dice1 + self.dice2;
  170. if (self.passChipCount > 0) { //ensure pass game is ongoing
  171. if (totalDice == self.passPoint) {
  172. self.alert = 'Game Won! You rolled ' + totalDice;
  173. self.total += (self.passChipCount * 2);
  174. if (self.oddsChipCount > 0) {
  175. self.oddsGame();
  176. }else {
  177. self.resetGame();
  178. }
  179. } else if (totalDice == 7) {
  180. self.alert = 'Game Lost! You rolled ' + totalDice;
  181. if (self.oddsChipCount > 0) {
  182. self.oddsGame();
  183. }else {
  184. self.resetGame();
  185. }
  186. };
  187. };
  188. if (self.comePoints.length > 0) {
  189. self.comeAlert = '';
  190. var multipleAlerts = [];
  191. for (var i = 0; i < self.comePoints.length; i++) {
  192. if (totalDice == self.comePoints[i].move) {
  193. multipleAlerts.push('Come Game Won! You rolled ' + totalDice);
  194. self.total += (self.comePoints[i].chipCount * 2);
  195. self.comePoints.splice(i, 1);
  196. } else if (totalDice == 7) {
  197. multipleAlerts.push('Come Game Lost! You rolled ' + totalDice);
  198. self.comePoints.splice(i, 1);
  199. } else {
  200. multipleAlerts.push("Roll the dice until you also get " + self.comePoints[i].move + " to win");
  201. };
  202. };
  203. self.comeAlert = multipleAlerts.toString();
  204. };
  205. if (self.comePoints.length == 0 && !self.passPoint) {
  206. self.resetGame();
  207. }
  208. if (self.comeChipCount > 0) {
  209. self.comeGame(totalDice);
  210. }
  211. },
  212. comeGame: function(_totalDice) {
  213. var self = this;
  214. if (self.currentComeChips.length > 0) {
  215. if (_totalDice == 7 || _totalDice == 11) {
  216. self.comeAlert = 'Come Game Won! You rolled ' + _totalDice + '\n';
  217. self.total += (self.currentComeChips * 2);
  218. if (self.comePoints.length == 0) {
  219. self.resetComeGame();
  220. }
  221. } else if (_totalDice == 2 || _totalDice == 3 || _totalDice == 12) {
  222. self.comeAlert = 'Come Game Lost! You rolled ' + _totalDice + '\n';
  223. if (self.comePoints.length == 0) {
  224. self.resetComeGame();
  225. }
  226. } else {
  227. var obj = {
  228. move: _totalDice,
  229. chipCount: self.comeChipCount
  230. };
  231. self.comePoints.push(obj);
  232. self.comeAlert = "Roll the dice until you also get " + _totalDice + " to win";
  233. self.comeChipCount = 0;
  234. };
  235. }
  236. },
  237. oddsGame: function() {
  238. var self = this;
  239. if (self.oddsChipCount == 0) return;
  240. var totalDice = self.dice1 + self.dice2;
  241. if (totalDice == self.passPoint) {
  242. self.oddsAlert = 'Odds Game Won! You rolled ' + totalDice;
  243. self.total += (self.oddsChipCount * 2);
  244. self.resetGame();
  245. } else if (totalDice == 7) {
  246. self.oddsAlert = 'Odds Game Lost! You rolled ' + totalDice;
  247. self.resetGame();
  248. } else {
  249. self.oddsAlert = "Win you pass point to win your odds!";
  250. }
  251. },
  252. totalCounter: function() {
  253. var self = this;
  254. }
  255. },
  256. mounted: function() {
  257. }
  258. });
  259. </script>