script.blade.php 11 KB

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