Новичок
Профиль
Группа: Участник
Сообщений: 1
Регистрация: 13.5.2017
Репутация: нет Всего: нет
|
Здрасти, может я не так понял что делается в этой теме на форуме, но мне нужен алгоритм выпадения числа, не могу понять откуда что берется, растолкуйте чайнику, пожалуйста. Я так понимаю все заложено здесь: Код | animateRoulette: function(digit, callback) {
var that = this, animation_time = 15000, sector = 360 / 15, circle_count = 10, deg, dx, normalize;
if(digit <= 7) { dx = (digit * 2 - 1); } else { dx = (digit - (14 - digit)); } if(digit == 0) { dx = 0; }
deg = that.markup.roulette.circle.data('deg');
normalize = deg == 0 ? 0 : 360 * (1 - (deg / 360) % 1);
deg = deg + normalize + 360 * circle_count - dx * sector;
that.markup.roulette.circle.data('deg', deg);
that.markup.roulette.circle.css({ "-webkit-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-moz-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-o-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", transition: "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-webkit-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-moz-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-ms-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-o-transform": "rotate3d(0, 0, 1, " + deg + "deg)", transform: "rotate3d(0, 0, 1, " + deg + "deg)" });
|
вот все полностью: Код | var App = App || {};
App.Games.double = {
GAME_STATE_WAIT: 'wait', GAME_STATE_GAME: 'game', GAME_STATE_PROCESS_WINNER: 'winner',
GAME_TIME: 30,
socket : undefined,
game: { id: null, hash: null, bank: 0, bets: [], state: null }, /*bet: { username: 'USER1', avatar: 'ab99f8d7008edafbb759787cfb0575df990da54b_full.jpg', amount: 34.56576878, type: 'zero' }*/
request: { sending: false, sending_time: 0 },
history: [4, 5, 1, 0, 4, 5, 9, 6, 7], history_limit: 9,
colors: {},
timer: undefined, interval_handler: undefined,
init: function() {
this.game.state = this.GAME_STATE_WAIT; this.timer = this.GAME_TIME;
var that = this;
this.socket = App.Sockets.sockets.double;
this.socket.on('newBet', function (bet) { App.Tools.log('double - newBet', bet); that.newBet(bet); });
this.socket.on('newGame', function (game) { App.Tools.log('double - newGame', game); that.newGame(game['id'], game['hash']); });
this.socket.on('startGame', function (game_id) { App.Tools.log('double - startGame', game_id); that.startGame(game_id); });
this.socket.on('digit', function (digit) { App.Tools.log('double - digit', digit); that.newDigit(digit); });
this._initMarkup();
this._initEvents();
this.preload();
},
sendBet: function(amount, type) {
if(amount > App.Balance.get()) { alert2('Не достаточно средств на балансе'); return; }
var that = this;
this.request.sending = true; this.request.sending_time = new Date().getTime();
App.Sockets.ping(function() {
var time = new Date().getTime(); if((time - that.request.sending_time) / 1000 > 10) { that.request.sending = false; return; }
$.ajax({ url: 'ajax/bet.php', type: 'POST', data: { amount: amount, type: type }, dataType: 'JSON', method:'POST', beforeSend: function() { that.markup.bets.buttons.addClass('double_bet_animation'); }, success: function(response){
if(response['status'] == 'error') { that.markup.bets.buttons.removeClass('double_bet_animation'); that.request.sending = false; alert2(response['message']); return; }
App.Balance.set(response['balance']);
App.Sockets.transfer('double.bet', response['bet']); if(response['start']) { App.Sockets.transfer('double.start', response['game_id']); }
that.markup.bets.buttons.removeClass('double_bet_animation'); that.markup.input.val('');
that.request.sending = false;
} });
});
},
newBet: function(bet) {
this.game.bank += bet['amount']; this.game.bets.push(bet);
this.renderStatistics(); this.renderBets();
App.Beeper.beep();
},
newGame: function(id, hash) {
this.game.id = id; this.game.hash = hash; this.game.bank = 0; this.game.bets = []; this.game.state = this.GAME_STATE_WAIT; this.timer = this.GAME_TIME;
},
startGame: function(game_id) {
if(this.game.id !== game_id) { return; }
if(this.game.state == this.GAME_STATE_GAME) { return; }
this.game.state = this.GAME_STATE_GAME;
var that = this;
this.interval_handler = window.setInterval(function(){
that.timer --;
if(that.timer < 1) { that.stopGame(); }
that.renderTimer();
}, 1000);
},
stopGame: function() {
window.clearInterval(this.interval_handler);
this.timer = 0; this.game.state = this.GAME_STATE_PROCESS_WINNER;
this.renderTimer(); this.markup.roulette.labels.winning.show();
},
newDigit: function(digit) {
if(this.game.state == this.GAME_STATE_GAME) { this.stopGame(); }
this.history.push(digit);
this.game.state = this.GAME_STATE_WAIT;
this.appendToHistory(digit);
this.animateRoulette(digit);
},
animateRoulette: function(digit, callback) {
var that = this, animation_time = 15000, sector = 360 / 15, circle_count = 10, deg, dx, normalize;
if(digit <= 7) { dx = (digit * 2 - 1); } else { dx = (digit - (14 - digit)); } if(digit == 0) { dx = 0; }
deg = that.markup.roulette.circle.data('deg');
normalize = deg == 0 ? 0 : 360 * (1 - (deg / 360) % 1);
deg = deg + normalize + 360 * circle_count - dx * sector;
that.markup.roulette.circle.data('deg', deg);
that.markup.roulette.circle.css({ "-webkit-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-moz-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-o-transition": "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", transition: "transform " + animation_time + "ms cubic-bezier(.32,.64,.45,1)", "-webkit-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-moz-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-ms-transform": "rotate3d(0, 0, 1, " + deg + "deg)", "-o-transform": "rotate3d(0, 0, 1, " + deg + "deg)", transform: "rotate3d(0, 0, 1, " + deg + "deg)" });
that.markup.roulette.labels.winning.show();
setTimeout(function () {
that.markup.roulette.labels.end.show(digit);
that.animateAppendToHistory(digit);
setTimeout(function () {
that.markup.roulette.labels.counter.show();
that.renderAll();
if(callback != undefined) { callback(); }
}, 4000);
that.markup.roulette.circle.css({ "-webkit-transition": "transform 0ms", "-moz-transition": "transform 0ms", "-o-transition": "transform 0ms", transition: "transform 0ms" });
}, 15000);
},
appendToHistory: function(digit) {
this.history.splice(0, 0, digit);
if(this.history.length > this.history_limit) {
this.history.splice(this.history_limit, this.history.length - this.history_limit);
}
},
preload: function() {
$.extend(this.game, App.boot['double']['game']); $.extend(this.history, App.boot['double']['history']); this.timer = App.boot['double']['timer']; $.extend(this.colors, App.boot['double']['colors']);
this.renderAll();
if(this.timer > 0 && this.timer < this.GAME_TIME) { this.startGame(this.game.id); }
if(this.timer == 0) { this.stopGame(); }
},
renderGame: function() {
this.markup.game_id.html(this.game.id); this.markup.game_hash.html(this.game.hash);
},
renderAll: function() {
this.renderGame(); this.renderStatistics(); this.renderBets(); this.renderTimer(); this.renderHistory();
},
renderBets: function() {
var markup = '';
for(var i = this.game.bets.length - 1; i >= 0; i--) {
markup += App.Tools.template(this.markup.bets.li, this.game.bets[i]);
}
this.markup.bets.container.empty().html(markup);
},
renderStatistics: function() {
var groups = { red: 0, black: 0, zero: 0 };
for(var i = 0; i < this.game.bets.length; i++) {
groups[ this.game.bets[i]['type'] ] += this.game.bets[i]['amount'];
}
this.markup.bank_tab.html(this.game.bank);
this.markup.statistics.red.html( groups.red ); this.markup.statistics.black.html( groups.black ); this.markup.statistics.zero.html( groups.zero );
var red_percent = parseInt(groups.red / this.game.bank * 100), zero_percent = parseInt(groups.zero / this.game.bank * 100), black_percent = parseInt(groups.black / this.game.bank * 100); this.markup.statistics.red_percent.css('width', red_percent > 0 ? (red_percent + '%') : 0); this.markup.statistics.zero_percent.css('width', zero_percent > 0 ? (zero_percent + '%') : 0); this.markup.statistics.black_percent.css('width', black_percent > 0 ? (black_percent + '%') : 0);
},
renderTimer: function() {
var timer_as_string = this.timer.toString();
while(timer_as_string.length < 3) { timer_as_string = '0' + timer_as_string; }
this.markup.timer.s1.html( timer_as_string.charAt(0) ); this.markup.timer.s2.html( timer_as_string.charAt(1) ); this.markup.timer.s3.html( timer_as_string.charAt(2) );
},
renderHistory: function() {
var markup = '', data, n;
n = this.history.length <= this.history_limit ? this.history.length : this.history_limit;
for(var i = 0; i < n; i++) {
data = { type: this.colors[ this.history[i] ], digit: this.history[i] };
markup += App.Tools.template(this.markup.history.item_template, data);
}
this.markup.history.container.empty().html(markup);
},
animateAppendToHistory: function(digit) {
var markup;
markup = App.Tools.template(this.markup.history.item_template, { type: this.colors[ digit ], digit: digit });
this.markup.history.container.prepend(markup);
var items = this.markup.history.container.children();
if(items.length > this.history_limit) { items[ items.length - 1 ].remove(); }
},
markup: { bank_tab: undefined, game_id: undefined, game_hash: undefined, input: undefined, input_buttons: undefined, bets: { buttons: undefined, container: undefined, li: undefined }, statistics: { red:undefined, zero: undefined, black: undefined, red_percent:undefined, zero_percent: undefined, black_percent: undefined }, timer:{ s1:undefined, s2:undefined, s3:undefined }, history: { container: undefined, item_template: undefined }, roulette: { circle: undefined, labels: { processing: undefined, winning: undefined, end: undefined, counter:undefined } } },
_initMarkup: function() {
var that = this;
this.markup.bank_tab = $('.game_switch').find('.sum_bet_2'); this.markup.game_id = $('.roulette_content .game_num'); this.markup.game_hash = $('.roulette_content #roundHash'); this.markup.input = $('.roulette_content .bonus_game_bet_input'); this.markup.input.data('amount', 0); this.markup.input_buttons = $('.roulette_content .bonus_game_calc_button_list li'); this.markup.statistics.red = $('.roulette_content .bonus_game_bet_value_container.red .bonus_game_bet_value'); this.markup.statistics.zero = $('.roulette_content .bonus_game_bet_value_container.zero .bonus_game_bet_value'); this.markup.statistics.black = $('.roulette_content .bonus_game_bet_value_container.black .bonus_game_bet_value'); this.markup.statistics.red_percent = $('.roulette_content .bonus_game_bet_value_container.red .bonus_game_bet_value_progress'); this.markup.statistics.zero_percent = $('.roulette_content .bonus_game_bet_value_container.zero .bonus_game_bet_value_progress'); this.markup.statistics.black_percent = $('.roulette_content .bonus_game_bet_value_container.black .bonus_game_bet_value_progress'); this.markup.bets.container = $('.roulette_content .game_bets_list'); this.markup.bets.li = $('.roulette_content .template_game_bets_list').html(); this.markup.bets.buttons = $('.roulette_content .place_bet_buttons li'); var timer = $('.roulette_content .roulette_counter .span_2'); this.markup.timer.s1 = timer.eq(0); this.markup.timer.s2 = timer.eq(1); this.markup.timer.s3 = timer.eq(2); this.markup.history.container = $('.roulette_content .game_roulette_history_list'); this.markup.history.item_template = $('.roulette_content .template_game_roulette_history_list').html(); this.markup.roulette.circle = $('.roulette_content .roulette_numbers'); this.markup.roulette.labels.processing = $('.roulette_content .bonus_game_pre_end.processing'); this.markup.roulette.labels.winning = $('.roulette_content .bonus_game_pre_end.winning'); this.markup.roulette.labels.end = $('.roulette_content .bonus_game_end'); this.markup.roulette.labels.counter = $('.roulette_content .roulette_counter');
var show = function() { $('.roulette_content .bonus_game_state').removeClass('front').addClass('back'); this.removeClass('back').addClass('front'); };
this.markup.roulette.circle.data('deg', 0); this.markup.roulette.labels.processing.show = function() { show.call(this); }; this.markup.roulette.labels.winning.show = function() { show.call(this); }; this.markup.roulette.labels.counter.show = function() { show.call(this); }; this.markup.roulette.labels.end.show = function(digit) { this.removeClass('red').removeClass('black').removeClass('zero').addClass(that.colors[digit]).html(digit); show.call(this); };
},
_initEvents: function() {
var that = this;
this.markup.input_buttons.on('click', function(){
var bet_amount = 0;
if($(this).data('cost') == 'all') {
bet_amount = App.Balance.get();
} else if($(this).data('cost') == 'clear_bet') { bet_amount = 0; } else {
var current_amount = parseInt(that.markup.input.val()); if(isNaN(current_amount)) { current_amount = 0; } bet_amount = current_amount + parseInt($(this).data('cost'));
}
if(bet_amount > App.Balance.get()) { alert2('На балансе не достаточно средств'); return; }
that.markup.input.val(bet_amount);
});
this.markup.bets.buttons.on('click', function(){
var amount = parseInt(that.markup.input.val()), type = $(this).data('betType');
if(isNaN(amount)) { alert2('Сперва укажите сумму ставки'); return; }
that.sendBet(amount, type);
});
}
};
|
|