// 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');
//$('
This guess could not be completed at this time.
').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'){
//$('
'+jqxhr.message+'
').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');
//$('
This guess could not be completed at this time.
').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){
$('