Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Public/Client JS
- var socket = null;
- var identifier = null;
- $(document).ready(function() {
- var currentNum = 0;
- function roll(num) {
- var numWidth = 1050/15;
- var layout = [1, 14, 2, 13, 3, 12, 4, 0, 11, 5, 10, 6, 9, 7, 8];
- function getMoves() {
- let to = layout.indexOf(num);
- let at = layout.indexOf(currentNum);
- if(to > at)
- {return (to - at);}
- else
- {return (layout.length - at + to);}
- }
- var currentPos = parseInt($('#case').css( "background-position" ).split(" ")[0].slice(0, -2));
- currentPos ? null : currentPos = 0;
- $('#case').animate({
- "background-position": currentPos-2100-(getMoves()*numWidth),
- }, 3000);
- currentNum = num;
- setTimeout(function() {
- if($("#past .ball").length >= 10)
- {
- $("#past .ball").first().remove();
- }
- if (num == 0)
- {
- $(".ball").last().after("<div class='ball ball-0'>" + num + "</div>");
- }
- else if (num <= 7)
- {;
- $(".ball").last().after("<div class='ball ball-1'>" + num + "</div>");
- }
- else
- {
- $(".ball").last().after("<div class='ball ball-8'>" + num + "</div>");
- }
- $.each($('.list-group-item'), function (index, value) {
- $(this).remove();
- });
- }, 3000);
- }
- identifier = $('meta[name="identifier"]').attr('content');
- if(!socket)
- {
- if(!identifier)
- {
- console.log("User not logged in.");
- }
- else
- {
- socket = io("localhost:8000");
- socket.on('connect', function(msg) {
- console.log("Connected!");
- socket.emit('authenticate', identifier);
- });
- }
- }
- else
- {
- console.log("Connection already exists.");
- }
- socket.on('roll', function(rolledNumber)
- {
- roll(rolledNumber);
- //$('#banner').html(timer + '<span style="font-size:17px">S</span>')
- });
- socket.on('updateTime', function(timer)
- {
- $(".timer").width((timer/20)*100+"%");
- //$('#banner').html(timer + '<span style="font-size:17px">S</span>')
- });
- socket.on('users', function(num)
- {
- $('.users-online').html(num);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement