// Object to store creditbalValues with the key "creditbal" // Function to fetch the creditbal value and return a Promise /*async function fetchCreditBal() { return new Promise((resolve, reject) => { var desiredUsername = localStorage.getItem('username'); // Create a new XMLHttpRequest object var xhttp = new XMLHttpRequest(); // Specify the type of request (GET or POST), the URL, and whether the request should be asynchronous xhttp.open("POST", "/js/fetch_creditbal.php", true); // Set the request header if you're sending data as JSON xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Set up a callback function to handle the response from the server xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Response from the server (if any) var creditbalValue = JSON.parse(this.responseText); alert(creditbalValue); // Update the object with the key "creditbal" return creditbalValue; } }; // Convert JavaScript data to a query string var data = "&desiredUsername=" + encodeURIComponent(desiredUsername); // Send the request with the data xhttp.send(data); }); }*/ /*NEW WORK FROM HERE :::::::::::::::::::::::::::::::::::::::::::: START*/ /*function getMyWalletBalance(){ var desiredUsername = localStorage.getItem('username'); var data = "&desiredUsername=" + encodeURIComponent(desiredUsername); var xhttp = new XMLHttpRequest(); xhttp.onreadyStateChange = function(){ if (this.readyState == 4 && this.status == 200) { var creditbalValue = JSON.parse(this.responseText); console.log(creditbalValue); return creditbalValue; } } xhttp.open("POST", "/js/fetch_creditbal.php", true); xhttp.send(data); }*/ var fetchcreditval = 0; // ✅ Step 1: Get username from URL function getURLParameter(name) { const urlParams = new URLSearchParams(window.location.search); return urlParams.get(name); } var urlUsername = getURLParameter('username'); if (urlUsername) { localStorage.setItem('username', urlUsername); document.cookie = "username=" + encodeURIComponent(urlUsername) + "; path=/"; } // ✅ Step 2: Then get it from localStorage var desiredUsername = localStorage.getItem('username'); console.log(desiredUsername); // ✅ Step 3: AJAX request with username function sendXMLRequest() { var formData = new FormData(); formData.append("desiredUsername", desiredUsername); const xhr = new XMLHttpRequest(); const url = '/js/fetch_creditbal.php'; xhr.open('POST', url, true); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { resp = JSON.parse(xhr.responseText); var bal = resp.balance; fetchcreditval = bal; } else if (xhr.readyState === 4) { console.error('Error:', xhr.status); } }; xhr.send(formData); } sendXMLRequest(); // ✅ Step 4: Set cookie manually again (redundant but keeping as you had it) function setCookie(name, value, daysToExpire) { const date = new Date(); date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000)); const expires = "expires=" + date.toUTCString(); document.cookie = name + "=" + value + ";" + expires + ";path=/"; } setCookie("username", desiredUsername, 1); /*NEW WORK FROM HERE :::::::::::::::::::::::::::::::::::::::::::: END*/ // Usage of the fetchCreditBal function with Promise /*var fetchcreditval = 0; function fetchData() { try { fetchcreditval = parseInt(fetchCreditBal()); } catch (error) { console.error("Error fetching credit balance:", error); } }*/ // Call the async function //fetchData(); //////////////////////////////////////////////////////////// // GAME v1.1 // //////////////////////////////////////////////////////////// /*! * * GAME SETTING CUSTOMIZATION START * */ function refreshWalletInGameSettings() { fetch('/js/fetch_wallet_balance.php') .then(res => res.text()) .then(balance => { gameSettings.credit = parseFloat(balance); // console.log("Wallet synced: " + balance); // Optional debug }); } // Start sync every 3 seconds silently setInterval(refreshWalletInGameSettings, 1000); var gameSettings = { enableFixedResult:false, //option to have fixed result by API, enabling this will disable 2D physics engine enablePercentage:false, //option to have result base on percentage, enabling this will disable 2D physics engine ballCollision:true, //ball collision for 2D physics engine gamePlayType:false, //game play type; true for chance, false for bet credit:0, //start credit chances:100, //start chances chancesPoint:10, //chances bet point minBet:10, //bet minimum maxBet:1000, //bet maximum maxBalls:100, //maximum balls nextBallDelay:0.4, //multiple ball drop delay history:10, //total history board:{ size:45, ballSize:12, pinSize:5, pinColor:'#fff', pinMoveColor:'#FFBF00', startPin:3, notiFontSize:22, notiColor:["#13BC5B","#CC0D0D"] }, rows:[ { total:8, even:false, prizes:[ {value:[0.5, 0.4, 0.2], text:["0.5x", "0.4x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.7, 0.3], text:["1x", "0.7x", "0.3x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.1, 1.3, 1.5], text:["1.1x", "1.3x", "1.5x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[2.1, 3, 4], text:["2.1x", "3x", "4x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[5.6, 13, 29], text:["5.6x", "13x", "29x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:9, even:true, prizes:[ {value:[0.7, 0.5, 0.2], text:["0.5x", "0.5x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.9, 0.6], text:["1x", "0.9x", "0.6x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.6, 1.7, 2], text:["1.6x", "1.7x", "2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[2, 4, 7], text:["2x", "4x", "7x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[5.6, 18, 43], text:["5.6x", "18x", "43x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:10, even:false, prizes:[ {value:[0.5, 0.4, 0.2], text:["0.5x", "0.4x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.6, 0.3], text:["1x", "0.6x", "0.3x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.1, 1.4, 0.9], text:["1.1x", "1.4x", "0.9x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.4, 2, 3], text:["1.4x", "2x", "3x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[3, 5, 10], text:["3x", "5x", "10x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[8.9, 22, 76], text:["8.9x", "22x", "76x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:11, even:true, prizes:[ {value:[0.7, 0.5, 0.2], text:["0.7x", "0.5x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.7, 0.4], text:["1x", "0.7x", "0.4x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.3, 1.8, 1.4], text:["1.3x", "1.8x", "1.4x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.9, 3, 5.2], text:["1.9x", "3x", "5.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[3, 6, 14], text:["3x", "6x", "14x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[8.4, 24, 120], text:["8.4x", "24x", "120x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:12, even:false, prizes:[ {value:[0.5, 0.3, 0.2], text:["0.5x", "0.3x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.6, 0.2], text:["1x", "0.6x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.1, 1.1, 0.7], text:["1.1x", "1.1x", "0.7x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.4, 2, 2], text:["1.4x", "2x", "2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.6, 4, 8.1], text:["1.6x", "4x", "8.1x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[3, 11, 24], text:["3x", "11x", "24x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[10, 33, 170], text:["10x", "33x", "170x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:13, even:true, prizes:[ {value:[0.7, 0.4, 0.2], text:["0.7x", "0.4x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[0.9, 0.7, 0.2], text:["0.9x", "0.7x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.2, 1.3, 1], text:["1.2x", "1.3x", "1x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.9, 3, 4], text:["1.9x", "3x", "4x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[3, 6, 1], text:["3x", "6x", "1x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[4, 13, 37], text:["4x", "13x", "37x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[8.1, 43, 280], text:["8.1x", "43x", "200x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] }, { total:14, even:false, prizes:[ {value:[0.5, 0.2, 0.2], text:["0.5x", "0.2x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#FFBF00", bgWinColor:"#F4A800", percent:0}, {value:[1, 0.5, 0.2], text:["1x", "0.5x", "0.2x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.1, 1, 0.3], text:["1.1x", "1x", "0.3x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF7C11", bgWinColor:"#FC7E15", percent:0}, {value:[1.3, 1.9, 1.9], text:["1.3x", "1.9x", "1.9x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.4, 4, 5], text:["1.4x", "4x", "5x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[1.9, 7, 18], text:["1.9x", "7x", "18x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF521E", bgWinColor:"#FF4A1A", percent:0}, {value:[4, 15, 56], text:["4x", "15x", "56x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#EF282C", bgWinColor:"#FC1521", percent:0}, {value:[7.1, 58, 420], text:["7.1x", "58x", "420x"], fontSize:12, lineHeight:10, x:0, y:3, color:"#fff", bgColor:"#ED0000", bgWinColor:"#FF0000", percent:0}, ] } ], }; //game text display var textDisplay = { creditLabel:"CREDIT", credit:"$[NUMBER]", betLabel:"BET AMOUNT", bet:"$[NUMBER]", chanceLabel:"CHANCES", chance:"X[NUMBER]", riskLabel:"RISK LEVEL", risk:["LOW","MID","HIGH"], rowsLabel:"ROWS", ballsLabel:"BALLS", buttonPlay:"PLAY", buttonPlaying:"PLAYING...", playBet:"PLAY $[NUMBER]", playChance:"x[NUMBER] CHANCES ($[TOTAL])", betInsufficient:"NOT ENOUGH CREDIT", chanceInsufficient:"NOT ENOUGH CHANCES", won:"YOU WON $[NUMBER]", lose:"BETTER LUCK NEXT TIME", playing:'PLAYING...', playingMultiple:'PLAYING... ([NUMBER] BALLS)', gameOver:'GAME OVER', collectPrize:"[NUMBER]", exitTitle:"EXIT GAME", exitMessage:"ARE YOU SURE YOU WANT\nTO QUIT GAME?", share:"SHARE YOUR SCORE", resultTitle:"GAME OVER", resultDesc:"YOU WON", resultScore:"$[NUMBER]" } //Social share, [SCORE] will replace with game score var shareEnable = true; //toggle share var shareTitle = "Highscore on Extreme Plinko Game at $[SCORE].";//social share score title var shareMessage = "$[SCORE] is mine new highscore on Extreme Plinko Game! Try it now!"; //social share score message /*! * * GAME SETTING CUSTOMIZATION END * */ $.editor = {enable:false}; var playerData = {chance:0, score:0, point:0, bet:0}; var gameData = {paused:true, dropCon:false, ballArray:[], historyArray:[], historyObj:[], pinObj:[], totalBet:0, totalBalls:0, totalRows:0, lastRows:-1, riskLevel:0, boardW:0, winAmount:0, moveArray:[], finalMoveArray:[], fixedResult:[]}; var tweenData = {score:0, scoreTarget:0, resultScore:0}; // Function to send the AJAX request function sendUpdateRequest() { // Get numeric credit value from your player data var newCreditValue = textDisplay.credit.replace('[NUMBER]', addCommas(Math.floor(playerData.point))); var numericValue = newCreditValue.replace(/[^0-9]/g, ''); // Set cookies (if needed) setCookie("username", desiredUsername, 1); // 1 day setCookie("updatedCredit", numericValue, 1); // Create form data and send AJAX request var formData = new FormData(); formData.append("desiredUsername", desiredUsername); formData.append("newCreditValue", numericValue); const xhr = new XMLHttpRequest(); const url = '/js/update_credit.php'; xhr.open('POST', url, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { console.log("Credit updated successfully"); } else { alert("There is an issue with the request."); console.error(xhr.responseText); } } }; xhr.send(formData); } /* function sendUpdateRequest() { var newCreditValue = textDisplay.credit.replace('[NUMBER]', addCommas(Math.floor(playerData.point))); // Replace with your desired value var numericValue = newCreditValue.replace(/[^0-9]/g, ''); var desiredUsername = localStorage.getItem('username'); // Replace with the desired username var xhttp = new XMLHttpRequest(); xhttp.open("POST", "/js/update_credit.php", true); xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log("Response from PHP:", this.responseText); } }; var data = "newCreditValue=" + encodeURIComponent(numericValue) + "&desiredUsername=" + encodeURIComponent(desiredUsername); xhttp.send(data); alert(''+data+''); console.log(''+data+''); }*/ // Call the function initially //sendUpdateRequest(); // Set up a loop to call the function every 30 seconds setInterval(sendUpdateRequest, 30000); // 30,000 milliseconds = 30 seconds /*! * * GAME BUTTONS - This is the function that runs to setup button event * */ function buildGameButton(){ $(window).focus(function() { if(!buttonSoundOn.visible){ toggleSoundInMute(false); } if (typeof buttonMusicOn != "undefined") { if(!buttonMusicOn.visible){ toggleMusicInMute(false); } } }); $(window).blur(function() { if(!buttonSoundOn.visible){ toggleSoundInMute(true); } if (typeof buttonMusicOn != "undefined") { if(!buttonMusicOn.visible){ toggleMusicInMute(true); } } }); gameData.physicsEngine = true; if(gameSettings.enableFixedResult){ gameData.physicsEngine = false; } if(gameSettings.enablePercentage){ gameData.physicsEngine = false; } buttonStart.cursor = "pointer"; buttonStart.addEventListener("click", function(evt) { playSound('soundClick'); goPage('game'); }); //game buttonBetHalf.cursor = "pointer"; buttonBetHalf.addEventListener("click", function(evt) { if(gameData.dropCon){ return; } playSound('soundClick'); toggleTotalBet(false); }); buttonBetMultiply.cursor = "pointer"; buttonBetMultiply.addEventListener("click", function(evt) { if(gameData.dropCon){ return; } playSound('soundClick'); toggleTotalBet(true); }); buttonRiskL.cursor = "pointer"; buttonRiskL.addEventListener("click", function(evt) { if(gameData.dropCon){ return; } playSound('soundClick'); toggleRiskLevel(false); }); buttonRiskR.cursor = "pointer"; buttonRiskR.addEventListener("click", function(evt) { if(gameData.dropCon){ return; } playSound('soundClick'); toggleRiskLevel(true); }); itemRowsDrag.dragType = "rows"; itemBallsDrag.dragType = "balls"; buildDragOption(itemRowsDrag); buildDragOption(itemBallsDrag); buttonBlank.cursor = "pointer"; buttonBlank.addEventListener("click", function(evt) { playSound('soundClick'); dropBalls(); }); //exit buttonConfirm.cursor = "pointer"; buttonConfirm.addEventListener("click", function(evt) { playSound('soundClick'); toggleConfirm(false); stopGame(true); goPage('main'); }); buttonCancel.cursor = "pointer"; buttonCancel.addEventListener("click", function(evt) { playSound('soundClick'); toggleConfirm(false); }); buttonContinue.cursor = "pointer"; buttonContinue.addEventListener("click", function(evt) { playSound('soundClick'); goPage('main'); }); //result buttonFacebook.cursor = "pointer"; buttonFacebook.addEventListener("click", function(evt) { share('facebook'); }); buttonTwitter.cursor = "pointer"; buttonTwitter.addEventListener("click", function(evt) { share('twitter'); }); buttonWhatsapp.cursor = "pointer"; buttonWhatsapp.addEventListener("click", function(evt) { share('whatsapp'); }); //options buttonSoundOff.cursor = "pointer"; buttonSoundOff.addEventListener("click", function(evt) { toggleSoundMute(true); }); buttonSoundOn.cursor = "pointer"; buttonSoundOn.addEventListener("click", function(evt) { toggleSoundMute(false); }); if (typeof buttonMusicOff != "undefined") { buttonMusicOff.cursor = "pointer"; buttonMusicOff.addEventListener("click", function(evt) { toggleMusicMute(true); }); } if (typeof buttonMusicOn != "undefined") { buttonMusicOn.cursor = "pointer"; buttonMusicOn.addEventListener("click", function(evt) { toggleMusicMute(false); }); } buttonFullscreen.cursor = "pointer"; buttonFullscreen.addEventListener("click", function(evt) { toggleFullScreen(); }); buttonSettings.cursor = "pointer"; buttonSettings.addEventListener("click", function(evt) { playSound('soundClick'); toggleOption(); }); buttonExit.cursor = "pointer"; buttonExit.addEventListener("click", function(evt) { playSound('soundClick'); toggleConfirm(true); toggleOption(); // Redirect after optional delay (like 500ms) setTimeout(function() { window.location.href = "https://bandhanplus.in/user/games"; // <- change this to your target URL }, 500); }); } function appendFocusFrame(){ $('#mainHolder').prepend('
=0; p--){ gameData.prizeArray.push(p); } var startP = 0; if(!gameSettings.rows[gameData.rowIndex].even){ startP = 1; } for(var p=startP; p pos.maxH){ pos.scalePercentY = pos.maxH/pos.h; } if(pos.w > pos.maxW){ pos.scalePercentX = pos.maxW/pos.w; } if(pos.scalePercentX > pos.scalePercentY){ pos.scaleX = pos.scalePercentY; pos.scaleY = pos.scalePercentY; }else{ pos.scaleX = pos.scalePercentX; pos.scaleY = pos.scalePercentX; } itemPlinko.visible = itemPlinkoP.visible = false; if(viewport.isLandscape){ statsCreditContainer.x = canvasW/100 * 11; statsCreditContainer.y = canvasH/100 * 20; statsBetChanceContainer.x = statsCreditContainer.x; statsBetChanceContainer.y = statsCreditContainer.y + spaceY; statsRiskContainer.x = statsCreditContainer.x; statsRiskContainer.y = statsCreditContainer.y + (spaceY*2); statsRowsContainer.x = statsCreditContainer.x; statsRowsContainer.y = statsCreditContainer.y + (spaceY*3); statsBallsContainer.x = statsCreditContainer.x; statsBallsContainer.y = statsCreditContainer.y + (spaceY*4); statsPlayContainer.x = statsCreditContainer.x; statsPlayContainer.y = statsCreditContainer.y + ((spaceY*4) + spaceButtonY); pos.x = canvasW/100 * 57; pos.y = canvasH/2 - ((pos.h * pos.scaleX) /2); itemPlinko.x = canvasW/100 * 57; itemPlinko.y = canvasH/2; itemPlinko.visible = true; historyContainer.x = canvasW/100 * 86; historyContainer.y = canvasH/2; }else{ statsBetChanceContainer.x = canvasW/100 * 18; statsBetChanceContainer.y = canvasH/100 * 68; statsRiskContainer.x = statsBetChanceContainer.x + spaceX; statsRiskContainer.y = statsBetChanceContainer.y; statsRowsContainer.x = statsBetChanceContainer.x; statsRowsContainer.y = statsBetChanceContainer.y + (spaceY); statsBallsContainer.x = statsRowsContainer.x + spaceX; statsBallsContainer.y = statsBetChanceContainer.y + (spaceY); statsCreditContainer.x = statsBetChanceContainer.x; statsCreditContainer.y = statsBetChanceContainer.y + (spaceY * 2); statsPlayContainer.x = statsCreditContainer.x + spaceX; statsPlayContainer.y = statsBetChanceContainer.y + (spaceY * 2); pos.x = canvasW/2; pos.y = (canvasH/100 * 39) - ((pos.h * pos.scaleX) /2); itemPlinkoP.x = canvasW/2; itemPlinkoP.y = canvasH/100 * 39; itemPlinkoP.visible = true; historyContainer.x = canvasW/2; historyContainer.y = canvasH/100 * 10; } TweenMax.to(plinkoContainer, .2, {x:pos.x, y:pos.y, scaleX:pos.scaleX, scaleY:pos.scaleY, overwrite:true}); positionWinHistory(); } /*! * * ANIMATION - This is the function that runs to animate * */ function startAnimate(obj){ TweenMax.to(obj, obj.tween.startSpeed, {delay:obj.tween.startDelay, alpha:obj.tween.startAlpha, overwrite:true, onComplete:function(){ TweenMax.to(obj, obj.tween.endSpeed, {delay:obj.tween.endDelay, alpha:obj.tween.endAlpha, overwrite:true, onComplete:function(){ if(obj.tween.loop){ startAnimate(obj) } }}); }}); } /*! * * TOGGLE GAME STATUS - This is the function that runs to toggle game status * */ function toggleGameStatus(stat, timer){ TweenMax.killTweensOf(statusTxt); if(stat != undefined){ statusTxt.text = stat; if(!isNaN(timer)){ TweenMax.to(statusTxt, timer, {doverwrite:true, onComplete:function(){ displayGameStatusAmount(); }}); } } } function displayGameStatusAmount(){ if(!gameData.dropCon){ if(gameSettings.gamePlayType){ var displayCalculate = textDisplay.playChance.replace('[NUMBER]', addCommas(Math.floor(gameData.totalBalls))); displayCalculate = displayCalculate.replace('[TOTAL]', addCommas(Math.floor(gameData.totalBalls * gameSettings.chancesPoint))); statusTxt.text = displayCalculate }else{ statusTxt.text = textDisplay.playBet.replace('[NUMBER]', addCommas(Math.floor(gameData.totalBet * gameData.totalBalls))); } }else{ if(gameData.totalBallsCount+1 == gameData.totalBalls){ statusTxt.text = textDisplay.playing; }else{ statusTxt.text = textDisplay.playingMultiple.replace('[NUMBER]', addCommas(Math.floor(gameData.totalBalls - (gameData.totalBallsCount+1)))); } } } /*! * * BET AMOUNT - This is the function that runs to toggle bet amount * */ function toggleTotalBet(con){ if(!con){ gameData.totalBet = gameData.totalBet/2; gameData.totalBet = gameData.totalBet < gameSettings.minBet ? gameSettings.minBet : gameData.totalBet; }else{ gameData.totalBet = gameData.totalBet * 2; gameData.totalBet = gameData.totalBet > gameSettings.maxBet ? gameSettings.maxBet : gameData.totalBet; } updateStats(); displayGameStatusAmount(); } /*! * * RISK LEVEL - This is the function that runs to toggle risk level * */ function toggleRiskLevel(con){ if(!con){ gameData.riskLevel--; gameData.riskLevel = gameData.riskLevel < 0 ? 0 : gameData.riskLevel; }else{ gameData.riskLevel++; gameData.riskLevel = gameData.riskLevel > 2 ? 2 : gameData.riskLevel; } updateRiskLevel(); } function updateRiskLevel(){ statRiskTxt.text = textDisplay.risk[gameData.riskLevel]; for(var p=0; p obj.target.endX ? obj.target.endX : obj.target.x; var dragPos = obj.target.x - obj.target.startX; var dragW = obj.target.endX - obj.target.startX; if(obj.target.dragType == "rows"){ var rowIndex = Math.floor(dragPos/dragW * (gameSettings.rows.length-1)); gameData.totalRows = gameSettings.rows[rowIndex].total; updateBoardRows(true); }else{ gameData.totalBalls = Math.floor(dragPos/dragW * gameSettings.maxBalls); gameData.totalBalls = gameData.totalBalls < 1 ? 1 : gameData.totalBalls; if(gameData.totalBalls != gameData.lastTotalBalls){ gameData.lastTotalBalls = gameData.totalBalls; playSound("soundBall"); } } updateStats(); displayGameStatusAmount(); } break; case 'drop': obj.target.dragCon = false; break; } } /*! * * DROP BALL - This is the function that runs to drop ball * */ function dropBalls(){ //memberpayment if(typeof memberData != 'undefined' && memberSettings.enableMembership && !memberData.ready){ return; } if(gameData.dropCon){ return; } if(gameSettings.gamePlayType){ if(playerData.chance < gameData.totalBalls){ toggleGameStatus(textDisplay.chanceInsufficient, 2); return; } playerData.chance -= gameData.totalBalls; playerData.chance = playerData.chance < 0 ? 0 : playerData.chance; }else{ if(playerData.point < Math.floor(gameData.totalBet * gameData.totalBalls)){ toggleGameStatus(textDisplay.betInsufficient, 2); return; } playerData.score -= gameData.totalBet * gameData.totalBalls; playerData.point = playerData.score; } plinkoWinContainer.removeAllChildren(); resetPhysicBall(); gameData.ballArray = []; gameData.winPoint = 0; updateStats(); //memberpayment if(typeof memberData != 'undefined' && memberSettings.enableMembership){ if(!gameData.physicsEngine){ var postData = { rows:gameData.rowIndex, balls:gameData.totalBalls, bet:gameData.totalBet, risk:gameData.riskLevel } getUserResult("proceedDropBalls", postData); }else{ var postData = { rows:gameData.rowIndex, balls:gameData.totalBalls, bet:gameData.totalBet, risk:gameData.riskLevel, status:"drop_start", } updateUserPoint("proceedDropBalls", postData); } }else{ if(gameSettings.enablePercentage){ createPercentage(); } proceedDropBalls(); } } function proceedDropBalls(result){ gameData.path = []; if(result != undefined){ gameData.path = result.path; } toggleGameStatus(textDisplay.playing); buttonBlankTxt.text = textDisplay.buttonPlaying; gameData.dropCon = true; gameData.totalBallsCount = 0; if(gameData.physicsEngine){ pausedPhysics(0, false); } loopDropBalls(); } function loopDropBalls(){ var tweenDelay = gameData.totalBallsCount == 0 ? 0 : gameSettings.nextBallDelay; TweenMax.to(gameData, tweenDelay, {overwrite:true, onComplete:function(){ displayGameStatusAmount() createBall(); gameData.totalBallsCount++; if(gameData.totalBallsCount < gameData.totalBalls){ loopDropBalls(); } }}); } /*! * * CREATE BALL - This is the function that runs to create ball * */ function createBall(){ var newBall = new createjs.Bitmap(loader.getResult('itemBall')); centerReg(newBall); newBall.active = true; newBall.ballIndex = gameData.ballArray.length; newBall.idleMove = 0; newBall.idleTimeCount = 0; newBall.ballX = 0; newBall.ballY = 0; gameData.ballArray.push(newBall); plinkoBallsContainer.addChild(newBall); var totalPin = gameSettings.board.startPin-1; if(!gameSettings.enableFixedResult){ totalPin = totalPin < 1 ? 1 : totalPin; var rangeX = gameSettings.board.size * totalPin; newBall.x = randomIntFromInterval(-(rangeX/2),(rangeX/2)); createPhysicBall(gameSettings.board.ballSize, newBall.x, newBall.y); }else{ generateMovePath(newBall); } } function removeBall(index){ var targetBall = gameData.ballArray[index]; targetBall.active = false; plinkoBallsContainer.removeChild(targetBall); if(!gameSettings.enableFixedResult){ removePhysicBall(index); } } /*! * * GENERATE PATH - This is the function that runs to generate path * */ function generateMovePath(targetBall){ targetBall.finalMoveArray = []; var startPos = {x:targetBall.x, y:targetBall.y}; targetBall.moveColumn = -1; targetBall.fixedResult = -1; targetBall.path = []; if(gameData.path.length > 0 && targetBall.ballIndex < gameData.path.length){ targetBall.path = gameData.path[targetBall.ballIndex]; startPos.x = $.move[0+'_'+targetBall.path[0].c].x; }else{ var center_column = Math.floor((gameData.totalColumn - gameSettings.board.startPin)/2); var random_pos = []; var start_column = center_column; for (var n = 0; n < gameSettings.board.startPin; n++) { random_pos.push(start_column); start_column++; } var prizeFixedResult = -1; if(targetBall.ballIndex < gameData.fixedResult.length){ prizeFixedResult = gameData.fixedResult[targetBall.ballIndex]; } if(prizeFixedResult == -1){ if(gameSettings.enablePercentage){ prizeFixedResult = getResultOnPercent(); } } if(prizeFixedResult != -1){ targetBall.fixedResult = (gameSettings.rows[gameData.rowIndex].prizes.length-1) - prizeFixedResult; if(randomBoolean()){ if(!gameSettings.rows[gameData.rowIndex].even){ targetBall.fixedResult = (gameSettings.rows[gameData.rowIndex].prizes.length-1) + prizeFixedResult; }else{ targetBall.fixedResult = (gameSettings.rows[gameData.rowIndex].prizes.length) + prizeFixedResult; } } var dropDistance = -1; var drop_column; for (var n = 0; n < random_pos.length; n++) { var checkDistance = Math.abs(random_pos[n] - targetBall.fixedResult); if(dropDistance == -1){ dropDistance = checkDistance; drop_column = random_pos[n]; } if(dropDistance > checkDistance){ dropDistance = checkDistance; drop_column = random_pos[n]; } } }else{ shuffle(random_pos); startPos.x = $.move[0+'_'+random_pos[0]].x; targetBall.moveColumn = random_pos[0]; } } var targetMoveArray = gameData.moveArray; for(var n=0; n= moveNum){ randomDirection = true; } } if(possibleMove[0].distance == possibleMove[1].distance){ if(targetBall.fixedResult != -1 && randomDirection){ var targetPrize = $.prize[targetBall.fixedResult]; var optionA = thisMove[row+'_'+possibleMove[0].column]; var optionB = thisMove[row+'_'+possibleMove[1].column]; var distanceA = getDistanceByValue(optionA.x, optionA.y, targetPrize.x, targetPrize.y); var distanceB = getDistanceByValue(optionB.x, optionB.y, targetPrize.x, targetPrize.y); if(distanceB > distanceA){ selectedColumn = possibleMove[0].column; }else{ selectedColumn = possibleMove[1].column; } }else{ if(randomBoolean()){ selectedColumn = possibleMove[1].column; } } } if(targetBall.fixedResult != -1){ var lastRow = gameData.totalRows; var centerRow = Math.floor(targetMoveArray[lastRow].length/2); var centerPrize = Math.floor(gameData.prizeArray.length/2); var targetColumn = 0; if(!gameSettings.rows[gameData.rowIndex].even){ targetColumn = centerRow - (centerPrize - targetBall.fixedResult); targetColumn--; }else{ targetColumn = centerRow - (centerPrize - targetBall.fixedResult); if(targetBall.fixedResult < centerPrize){ targetColumn--; } } targetColumn++; targetBall.moveColumn = Math.abs(selectedColumn - targetColumn); } if(targetBall.path.length > 0){ selectedColumn = targetBall.path[row].c; if(!isEven(row)){ selectedColumn++; } } thisMove[row+'_'+selectedColumn].alpha = .2; targetBall.x = thisMove[row+'_'+selectedColumn].x; targetBall.y = thisMove[row+'_'+selectedColumn].y; targetBall.finalMoveArray.push({x:thisMove[row+'_'+selectedColumn].x, y:thisMove[row+'_'+selectedColumn].y}); if(row == gameData.totalRows){ var bottomH = 0; var bottomY = plinkoSize + (plinkoSize/2); targetBall.finalMoveArray.push({x:thisMove[row+'_'+selectedColumn].x, y:thisMove[row+'_'+selectedColumn].y + (bottomY - (bottomH + ballSize))}); } } /*! * * MOVE BALL - This is the function that runs to move ball * */ function startBallMove(targetBall){ if(targetBall.moveIndex == targetBall.finalMoveArray.length-1 || targetBall.moveIndex == 0){ setTimeout(function(){ playHitSound(); }, 250); TweenMax.to(targetBall, .5, {x:targetBall.finalMoveArray[targetBall.moveIndex].x, y:targetBall.finalMoveArray[targetBall.moveIndex].y, ease:Bounce.easeOut, overwrite:true, onComplete:ballMoveComplete, onCompleteParams:[targetBall]}); }else{ var path_arr = [ {x:targetBall.x, y:targetBall.y}, {x:targetBall.finalMoveArray[targetBall.moveIndex].x, y:targetBall.finalMoveArray[targetBall.moveIndex].y - (gameSettings.board.size * 1.3)}, {x:targetBall.finalMoveArray[targetBall.moveIndex].x, y:targetBall.finalMoveArray[targetBall.moveIndex].y - (gameSettings.board.size * .2)}, {x:targetBall.finalMoveArray[targetBall.moveIndex].x, y:targetBall.finalMoveArray[targetBall.moveIndex].y}, ]; var randomSpeed = randomIntFromInterval(3,5)*.1; TweenMax.to(targetBall, randomSpeed, {bezier:{type:"cubic", values:path_arr}, ease:Circ.easeIn, overwrite:true, onComplete:ballMoveComplete, onCompleteParams:[targetBall]}); } } function ballMoveComplete(targetBall){ targetBall.moveIndex++; if(targetBall.moveIndex < targetBall.finalMoveArray.length){ var nearestPin = []; for(var n=0; n 0){ for(var p=0; p gameSettings.history){ removeHistory(gameData.historyObj[0]); gameData.historyObj.splice(0,1); gameData.historyArray.splice(0,1); } var prizeIndex = gameData.historyArray[gameData.historyArray.length-1]; var newHistory = createPrize(prizeIndex); newHistory.prizeText.text = newHistory.textArray[gameData.riskLevel]; newHistory.alpha = 0; gameData.historyObj.push(newHistory); historyContainer.addChild(newHistory); positionWinHistory(); animateHistory(newHistory); } function removeHistory(obj){ TweenMax.to(obj, .2, {onComplete:function(){ historyContainer.removeChild(obj); }}); } function positionWinHistory(){ var pos = {x:0, y:0, w:0, h:0, spaceX:3, spaceY:13}; if(viewport.isLandscape){ pos.h = (gameData.historyObj.length-1) * gameSettings.board.size; pos.h += (gameData.historyObj.length-1) * pos.spaceY; pos.y = -(pos.h/2); }else{ pos.w = (gameData.historyObj.length-1) * gameSettings.board.size; pos.w += (gameData.historyObj.length-1) * pos.spaceX; pos.x = -(pos.w/2); } for(var p=0; p $.prize[0].y && targetBall.active){ var distanceArray = []; for(var p=0; p gameSettings.chancesPoint){ gameData.winPoint += collectPoint - gameSettings.chancesPoint; isWinPoint = true; } }else{ collectPoint = gameData.totalBet * $.prize[distanceArray[0].index].valueArray[gameData.riskLevel]; if(collectPoint > gameData.totalBet){ gameData.winPoint += collectPoint - gameData.totalBet; isWinPoint = true; } } gameData.historyArray.push($.prize[distanceArray[0].index].prizeIndex); updateWinHistory(); animatePrize($.prize[distanceArray[0].index]); createWinText($.prize[distanceArray[0].index], collectPoint, isWinPoint); } } } if(gameData.dropCon){ var totalFinishBalls = 0; for(var b=0; b 0){ //win toggleGameStatus(textDisplay.won.replace('[NUMBER]', addCommas(Math.floor(gameData.winPoint)))); playerData.score += gameData.winPoint; TweenMax.to(playerData, 1, {point:playerData.score, overwrite:true, onUpdate:updateStats}); playSound('soundWin'); }else{ //no win toggleGameStatus(textDisplay.lose); playSound('soundLose'); } updateStats(); checkGameEnd(); sendUpdateRequest(); } /*! * * CHECK GAME END - This is the function that runs to check game end * */ function checkGameEnd(){ //memberpayment if(typeof memberData != 'undefined' && memberSettings.enableMembership){ if(!gameData.physicsEngine){ var returnPoint = { chance:playerData.chance, point:playerData.score, score:playerData.score }; matchUserResult(undefined, returnPoint); }else{ var postData = { bet:playerData.bet, win:gameData.winPoint, status:"drop_end", } updateUserPoint(undefined, postData); } } gameData.fixedResult = []; gameData.dropCon = false; buttonBlankTxt.text = textDisplay.buttonPlay; if(gameSettings.gamePlayType){ if(playerData.chance <= 0){ toggleGameStatus(textDisplay.gameOver); TweenMax.to(gameData, 3, {overwrite:true, onComplete:function(){ goPage('result'); }}); } }else{ if(playerData.score <= 0){ toggleGameStatus(textDisplay.gameOver); TweenMax.to(gameData, 3, {overwrite:true, onComplete:function(){ goPage('result'); }}); } } } /*! * * MILLISECONDS CONVERT - This is the function that runs to convert milliseconds to time * */ function millisecondsToTimeGame(milli) { var milliseconds = milli % 1000; var seconds = Math.floor((milli / 1000) % 60); var minutes = Math.floor((milli / (60 * 1000)) % 60); if(seconds<10){ seconds = '0'+seconds; } if(minutes<10){ minutes = '0'+minutes; } return minutes+':'+seconds; } /*! * * OPTIONS - This is the function that runs to toggle options * */ function toggleOption(){ if(optionsContainer.visible){ optionsContainer.visible = false; }else{ optionsContainer.visible = true; } } /*! * * OPTIONS - This is the function that runs to mute and fullscreen * */ function toggleSoundMute(con){ buttonSoundOff.visible = false; buttonSoundOn.visible = false; toggleSoundInMute(con); if(con){ buttonSoundOn.visible = true; }else{ buttonSoundOff.visible = true; } } function toggleMusicMute(con){ buttonMusicOff.visible = false; buttonMusicOn.visible = false; toggleMusicInMute(con); if(con){ buttonMusicOn.visible = true; }else{ buttonMusicOff.visible = true; } } function toggleFullScreen() { if (!document.fullscreenElement && // alternative standard method !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods if (document.documentElement.requestFullscreen) { document.documentElement.requestFullscreen(); } else if (document.documentElement.msRequestFullscreen) { document.documentElement.msRequestFullscreen(); } else if (document.documentElement.mozRequestFullScreen) { document.documentElement.mozRequestFullScreen(); } else if (document.documentElement.webkitRequestFullscreen) { document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); } } else { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } } } /*! * * SHARE - This is the function that runs to open share url * */ function share(action){ gtag('event','click',{'event_category':'share','event_label':action}); var loc = location.href loc = loc.substring(0, loc.lastIndexOf("/") + 1); var title = ''; var text = ''; title = shareTitle.replace("[SCORE]", addCommas(playerData.score)); text = shareMessage.replace("[SCORE]", addCommas(playerData.score)); var shareurl = ''; if( action == 'twitter' ) { shareurl = 'https://twitter.com/intent/tweet?url='+loc+'&text='+text; }else if( action == 'facebook' ){ shareurl = 'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(loc+'share.php?desc='+text+'&title='+title+'&url='+loc+'&thumb='+loc+'share.jpg&width=590&height=300'); }else if( action == 'whatsapp' ){ shareurl = "whatsapp://send?text=" + encodeURIComponent(text) + " - " + encodeURIComponent(loc); } window.open(shareurl); }