script.blade.php 11 KB

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