// Default options for the loading spinner var spin_opts = { lines: 13, length: 2, width: 2, radius: 5, corners: 1, rotate: 0, direction: 1, color: '#fff' }; var sound_enabled = true; $game_html = $('

Next tile worth:

In play:

'); var win = new Howl({urls: [webroot+'sound/win.mp3', webroot+'sound/win.ogg', webroot+'sound/win.wav']}); var lose = new Howl({urls: [webroot+'sound/lose.mp3', webroot+'sound/lose.ogg', webroot+'sound/lose.wav']}); var busy = false; var consecutive_zeros = 0; /* SATOSHIMINES.JS V0.81 */ function Game(bet, game_hash, num_mines){ num_mines = typeof num_mines !== 'undefined' ? num_mines : 3; var game_hash_qs = (typeof game_hash==='undefined')?'':'&game_hash='+game_hash; var _this = this; var timer = 0; var timer_int = setInterval(function(){ timer++; }, 100); // A new game busy = true; $.ajax({ url: webroot+'action/newgame.php', data: 'player_hash='+playerhash+'&bet='+bet+game_hash_qs+'&num_mines='+num_mines, type: 'POST', dataType: 'json' }).done(function(jqxhr){ busy = false; clearInterval(timer_int); clean_feed(); if (jqxhr.status == 'success'){ ga('send', 'event', 'game', 'new', 'wait', timer); var returnedBet = parseFloat(jqxhr.bet); returnedBet = (isNaN(returnedBet))?0:returnedBet; if (jqxhr.gametype != 'practice' && bet != 0){ updateBalance(returnedBet * -1); } _this.betNumber = parseInt(jqxhr.betNumber); _this.game_hash = jqxhr.game_hash; _this.bet = jqxhr.bet; _this.stake = jqxhr.stake; _this.next = jqxhr.next; _this.id = jqxhr.id; _this.jqel = $game_html.clone(); if (jqxhr.gametype == 'practice'){ _this.jqel.addClass('practice_game'); } // Mark tiles that have already been guessed if (typeof jqxhr.guesses !== 'undefined' && jqxhr.guesses != null){ var guesses_ar = jqxhr.guesses.split('-'); for(var i=0; i'); } } _this.changed_stake_recently = false; _this.jqel.attr('id', 'game_'+_this.game_hash).find('#stake').text('฿'+parseFloat(_this.stake).toFixed(6)); _this.jqel.find('#next').text('฿'+parseFloat(_this.next).toFixed(6)); _this.jqel.hide().addClass('hidegame').css('visibility','hidden').prependTo('.feed').slideDown(300, function(){ $(this).hide().css('visibility','visible').removeClass('hidegame').show();//.fadeIn(400,function(){ // Game is now available in the DOM as jqel. //$(this).removeClass('hidegame'); _this.jqel.find('.cashout').click(function(e){ e.preventDefault(); if (!busy){ _this.cashout(); } }); _this.jqel.find('.board li').click(function(e){ e.preventDefault(); if (!busy){ var $tile = $(this); _this.guess($tile); } }); $(this).bind('mouseover', function(){ $('.feed div.game').addClass('faded'); _this.jqel.removeClass('faded'); }); _this.message('A game for ฿'+jqxhr.bet+' has started. Secret hash: '+jqxhr.secret+'', 'first'); //}).removeClass('hidegame'); }); } else if (jqxhr.status == 'error'){ show_error(jqxhr.message); } }).fail(function(){ //alert('jqxhr failed'); show_error('This game could not be retrieved at this time.'); }).always(function(){ setTimeout(function(){ $('#start_game').removeAttr('disabled').spin(false); }, 500); });; // end ajax } Game.prototype.message = function(message, msgtype){ //msgtype = (typeof msgtype==='undefined')?'':msgtype; if(message.length < 1){ return true; } var $el = $('

'+message+'

'); if (arguments.length > 1){ for (var i = 1, len = arguments.length; i<=len; i++){ $el.addClass(arguments[i]); } } $el.hide().prependTo(this.jqel.find('.messages')).slideDown(200); } Game.prototype.cashout = function(){ var timer = 0; var timer_int = setInterval(function(){ timer++; }, 100); var _this = this; _this.jqel.find('button.cashout').attr('disabled','disabled').spin(spin_opts); $.ajax({ url: webroot+'action/cashout.php', // terribly insecure. Fix later data: 'game_hash='+_this.game_hash, type: 'POST', dataType: 'json' }).done(function(jqxhr){ clearInterval(timer_int); if (jqxhr.status == 'success'){ ga('send', 'event', 'game', 'cashout', 'wait', timer); updateBalance(parseFloat(jqxhr.win)); _this.jqel.find('.inplay p').html('Won: ฿'+jqxhr.win+''); _this.jqel.find('.cashout').hide(); _this.message(jqxhr.message, 'won'); _this.message('Secret: '+jqxhr.mines+'-'+jqxhr.random_string); var mines = jqxhr.mines.split('-'); for (i=0; i'); } } else if (jqxhr.status == 'error'){ _this.message(jqxhr.message,'error'); } }).fail(function(){ alert('jqxhr failed'); //$('').prependTo('.history').slideDown(); }).always(function(){ _this.jqel.find('button.cashout').removeAttr('disabled').spin(false); }); // end ajax } Game.prototype.guess = function($tile){ var timer = 0; var timer_int = setInterval(function(){ timer++; }, 100); var _this = this; var tile_number = parseInt($tile.attr('data-tile')); if (tile_number > 0 && tile_number < 26){ var opts = { lines: 13, length: 2, width: 2, radius: 6, corners: 1, rotate: 0, direction: 1, color: '#000' }; $tile.spin(opts); $tile.addClass('active_tile'); busy = true; $.ajax({ url: webroot+'action/checkboard.php', data: 'game_hash='+_this.game_hash+'&guess='+tile_number+'&v04=1', type: 'POST', dataType: 'json' }).done(function(jqxhr){ busy = false; clearInterval(timer_int); $tile.spin(false); $tile.removeClass('active_tile'); _this.betNumber++; if (jqxhr.status == 'success'){ ga('send', 'event', 'game', 'guess', 'wait', timer); if (jqxhr.outcome == 'bitcoins'){ _this.change_stake(jqxhr.stake); _this.jqel.find('#next').html('฿'+jqxhr.next.toFixed(6)); _this.message(jqxhr.message, 'find'); _this.jqel.find('li[data-tile="'+jqxhr.guess+'"]').addClass('pressed').html(''); } if (jqxhr.outcome == 'bomb'){ _this.message(jqxhr.message, 'bomb'); _this.jqel.find('li[data-tile="'+jqxhr.guess+'"]').addClass('pressed bomb').html(''); _this.message('Secret: '+jqxhr.bombs+'-'+jqxhr.random_string); _this.change_stake(0); _this.jqel.find('.cashout').hide(); var bombs = jqxhr.bombs.split('-'); for (i=0; i'); } if (sound_enabled){ lose.play(); } } } else if (jqxhr.status == 'error'){ //$('').prependTo('.history').slideDown(); _this.message(jqxhr.message, 'error'); } }).fail(function(){ $tile.removeClass('active_tile').spin(false); this.message('There was a problem making that guess.', 'error'); //$('').prependTo('.history').slideDown(); }); } else { //alert("Hey, wait a minute!"); this.message('Hey, wait a minute.'); } } Game.prototype.change_stake = function(stake){ // Set that the bank has been changed recently // and change it back after 5 seconds var _this = this; this.changed_stake_recently = true; var current_stake = parseFloat($('#stake').text().substr(1)); if (stake > current_stake){ // winnings going UP _this.animate_stake(current_stake, stake); } else { $('#stake').html('฿'+stake.toFixed(6)); } setTimeout(function(){ _this.changed_stake_recently = false; }, 5000); } Game.prototype.animate_stake = function(old_stake, new_stake){ var _this = this; if (!old_stake || !new_stake){ return false; } var difference = new_stake - old_stake; //var steps = 0.0001; var steps = difference / 20; var current_stake = old_stake; if (sound_enabled){ win.play(); } for (var i=0; i<20; i++){ setTimeout(function(){ current_stake += steps; _this.jqel.find('#stake').html('฿'+current_stake.toFixed(6)); }, 40*i); } setTimeout(function(){ _this.jqel.find('#stake').html('฿'+new_stake.toFixed(6)); }, 800); } /* Misc functions */ function updateBalance(change){ var currentBalance = parseFloat($('.player .balance .val').text().substr(1)); document.title = '฿'+(currentBalance+change).toFixed(6)+' - Satoshi Mines'; $('.player .balance .val').text('฿'+(currentBalance+change).toFixed(6)); if (currentBalance + change > 0){ $('#cashout_balance').removeClass('disabled'); } else { $('#cashout_balance').addClass('disabled'); } } function show_error(message){ $('

'+message+'

').hide().prependTo('.feed').slideDown(200); } function show_success(message){ $('

'+message+'

').hide().prependTo('.feed').slideDown(200); } function clean_feed(){ $('.feed>*').not($('.feed>*').slice(0,19)).remove(); } $(document).ready(function(){ if (document.addEventListener){ document.addEventListener("touchstart", function() {},false); } /* Navigation */ $('.nav .links a').click(function(e){ e.preventDefault(); $('.nav .links li').removeClass('selected'); $(this).parent().addClass('selected'); $.ajax({ url: $(this).attr('href'), type: 'GET', dataType: 'html', cache: false }).done(function(jqxhr){ $('.sub .sub_content').html(jqxhr).parent().slideDown(300); $('.sub .sub_content form').submit(function(e){ var $button = $(this).find('button'); $button.attr('disabled', 'disabled').spin(spin_opts); e.preventDefault(); $.ajax({ url: $(this).attr('action'), type: $(this).attr('method'), dataType: 'html', cache: false, data: $(this).serialize() }).done(function(form_result){ if(form_result.indexOf('_green') > -1) { $('.sub .sub_content form').slideUp(400); $(''+form_result).hide().prependTo('.sub .sub_content .form-container').slideDown(400); } else { $(''+form_result).hide().prependTo('.sub .sub_content .form-container form').slideDown(400); } }).fail(function(){ $('

An unknown error occued.

').hide().prependTo('.sub .sub_content .form-container').slideDown(400); }).always(function(){ $button.removeAttr('disabled').spin(false); }); }); }); }); $('.sub_close').click(function(e){ e.preventDefault(); $(this).parent().slideUp(300, function(){ $(this).find('.sub_content').html(''); $('.nav .links li').removeClass('selected'); }); }); $('.sound').click(function(e){ e.preventDefault(); if(sound_enabled){ $(this).attr('class', 'sound sound_disabled').find('i').attr('class', 'icon-volume-off'); sound_enabled = false; } else { $(this).attr('class', 'sound sound_enabled').find('i').attr('class', 'icon-volume-on'); sound_enabled = true; } }); /* Game bar */ $('.player_container').waypoint('sticky'); /* QR Code and name */ $('#player_name').blur(function(e){ e.preventDefault(); var player_name = $(this).val(); $.ajax({ url: webroot+'action/nameplayer.php', data: 'secret='+playerhash+'&player_name='+player_name, type: 'POST', dataType: 'json' }).done(function(jqxhr){ if (jqxhr.status == 'error'){ show_error(jqxhr.message); } }).fail(function(){ show_error('There was a problem updating your player name. Please contact the admin if this keeps happening.'); }); }); $('.qrcode').click(function(e){ e.preventDefault(); if ($(this).parent().find('img').length > 0){ $(this).parent().find('div').show(); } else { $qrimg = $('
'); $qrimg.find('button').click(function(){ $(this).parent().hide(); }); $(this).parent().prepend($qrimg); } }); /* New game controls */ var presentHandler = function(e){ e.preventDefault(); if ($(this).hasClass('button_zero')){ consecutive_zeros++; console.log(consecutive_zeros); } else { consecutive_zeros = 0; } var player_balance = parseFloat($('.player .balance .val').text().substr(1)); var currentBalance = parseFloat($('.player .bet').val()); if (isNaN(currentBalance)){ currentBalance = 0; } if ($(this).text().substr(0, 1) == '+'){ var newval = parseFloat($(this).text()); newval = (newval+currentBalance).toFixed(4); } else if ($(this).text().substr(0, 1) == '-'){ var newval = parseFloat($(this).text()); newval = (currentBalance+newval).toFixed(4); } else if ($(this).text() == 'MAX'){ var newval = maxbet; } else if ($(this).text() == 'MIN'){ var newval = minbet; } else { var newval = parseFloat($(this).text()).toFixed(4); } if (newval == maxbet && newval > player_balance && player_balance > 0){ newval = player_balance; } $('.bet').val(parseFloat(newval)); if (consecutive_zeros >= 5){ edit_presets(); } } $('.bets button').bind('click', presentHandler); $('#start_game').click(function(){ //var bet = parseFloat($('#bet').val(), 10); //bet = (isNaN(bet))?0:bet; $(this).attr('disabled', 'disabled').spin(spin_opts); var bet = $('#bet').val(); var num_mines = $('input[name="num_mines"]:checked').val(); games.push(new Game(bet, undefined, num_mines)); }); /* Edit the preset buttons */ function edit_presets() { //return false; consecutive_zeros = 0; $('ul.bets li').not(':first').each(function(){ $(this).append('').find('button').hide(); }); $('ul.bets li:first button').text('Done').unbind('click').click(function(){ consecutive_zeros = 0; $('ul.bets li').not(':first').each(function(){ $(this).find('button').text($(this).find('input').val()).show(); $(this).find('button').removeClass('button_plus button_minus'); if ($(this).find('input').val().substr(0,1) == '+'){ $(this).find('button').addClass('button_plus'); } else if ($(this).find('input').val().substr(0,1) == '-'){ $(this).find('button').addClass('button_minus'); } $(this).find('input').remove(); //$(this).hide(); }); $(this).text('0').unbind('click').bind('click', presentHandler); //$(this).unbind('click'); }); } /* Money */ $('#refresh_balance').click(function(e){ e.preventDefault(); $this = $(this); $this.parent().siblings('.val').addClass('disabled').spin(spin_opts); busy = true; $.ajax({ url: webroot+'action/refresh_balance.php', data: 'secret='+playerhash, type: 'POST', dataType: 'json' }).done(function(jqxhr){ busy = false; $this.parent().siblings('.val').removeClass('disabled').spin(false); if (jqxhr.status == 'success'){ document.title = '฿'+jqxhr.balance+' - Satoshi Mines'; $('.player .balance .val').text('฿'+jqxhr.balance); if (jqxhr.balance > 0){ $('#cashout_balance').removeClass('disabled'); } else { $('#cashout_balance').addClass('disabled'); } } else if (jqxhr.status == 'error'){ show_error('There was a problem refreshing your balance: '+jqxhr.message); } }).fail(function(){ show_error('A problem occured when trying to refresh your balance. Please try again in a minute, and then contact the admin'); //$('').prependTo('.history').slideDown(); }); }); $('#cashout_balance').click(function(e){ e.preventDefault(); var currentBalance = parseFloat($('.player .balance .val').text().substr(1)); $('.full_cashout #amount').val(''+currentBalance); $('.full_cashout .cancel').click(function(e){ e.preventDefault(); $(this).parent().parent().slideUp(200); }); $('.full_cashout').slideDown(200); }); $('.full_cashout button').click(function(e){ e.preventDefault(); $this = $(this); $this.attr('disabled', 'disabled').spin(spin_opts); var payto_address = $('.full_cashout #payout_address').val(); var amount = $('.full_cashout #amount').val(); busy = true; $.ajax({ url: webroot+'action/full_cashout.php', data: 'secret='+playerhash+'&payto_address='+payto_address+'&amount='+amount, type: 'POST', dataType: 'json' }).done(function(jqxhr){ busy = false; if (jqxhr.status == 'success'){ //$('.player .balance .val').text('฿0.000000'); $('.player .balance .val').text('฿'+(parseFloat(jqxhr.balance)).toFixed(6)); $('.full_cashout').slideUp(200); show_success(jqxhr.message); } else if (jqxhr.status == 'error'){ show_error('A problem occured while trying to withdraw: '+jqxhr.message); } else { show_error('Unknown error.'); } }).fail(function(){ show_error('A problem occured when trying to cash out your bitcoins. Please try again in a minute, and then contact the admin'); }).always(function(){ $this.removeAttr('disabled').spin(false); }); }); });