游戏html登录注册,HTML5 点击开锁小游戏(反应能力测试)

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

// Initialize rotationDegrees()

(function($) {

$.fn.rotationDegrees = function() {

var matrix = this.css("-webkit-transform") ||

this.css("-moz-transform") ||

this.css("-ms-transform") ||

this.css("-o-transform") ||

this.css("transform");

if (typeof matrix === 'string' && matrix !== 'none') {

var values = matrix.split('(')[1].split(')')[0].split(',');

var a = values[0];

var b = values[1];

var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));

} else {

var angle = 0;

}

return angle;

};

}(jQuery));

jQuery.fn.rotate = function(degrees) {

$(this).css({

'-webkit-transform': 'rotate(' + degrees + 'deg)',

'-moz-transform': 'rotate(' + degrees + 'deg)',

'-ms-transform': 'rotate(' + degrees + 'deg)',

'transform': 'rotate(' + degrees + 'deg)'

});

return $(this);

};

// End of rotationDegrees()

//

// Initialize random points on the circle, change # of digits left

function initializare($param) {

var angle = Math.floor((Math.random() * 720) - 360);

$("#circle2").rotate(angle);

$("#container > p").html($param);

$("#container > p").append("

digits left
");

}

// End of initializare()

//

$(document).ready(function() {

// Click counter -> %2 == 0 is clockwise, %2 != 0 is counter-clockwise

var counter = 0;

// Digits counter, decreases to 0, where the player wins

var pointcounter = 10;

// Above mentioned initialization function takes # of digits left as a parameter, to display it

initializare(pointcounter);

// Let's store the randomly generated angle of the point in a variable

var angle = $("#circle2").rotationDegrees();

// Initial circle spin, on page load

$("#circle").rotate(2880);

$('#circle').click(function() {

// Current rotation stored in a variable

var unghi = $(this).rotationDegrees();

// If current rotation matches the random point rotation by a margin of +- 25, the player "hit" it and continues

if (unghi > angle - 25 && unghi < angle + 25) {

pointcounter--;

// If game over, hide the game, display end of game options

if (!pointcounter) {

$("#circle").addClass("hidden");

$("#circle2").addClass("hidden");

$("#container > p").addClass("hidden");

$("#retry").removeClass("hidden");

}

// Else, add another point and remember its new angle of rotation

else initializare(pointcounter);

angle = $("#circle2").rotationDegrees();

}

// Else, the player "missed" and is brought to end of game options

else {

$("#circle").addClass("hidden");

$("#circle2").addClass("hidden");

$("#container > p").addClass("hidden");

$("#retry").removeClass("hidden");

}

// No of clicks ++

counter++;

// Orientation based on click parity

if (counter % 2) {

$(this).rotate(-1800);

} else $(this).rotate(1800);

});

$('#retry').click(function() {

$("#circle").removeClass("hidden");

$("#circle2").removeClass("hidden");

$("#container > p").removeClass("hidden");

$("#retry").addClass("hidden");

pointcounter = 10;

initializare(pointcounter);

angle = $("#circle2").rotationDegrees();

$("#circle").rotate(2440);

counter = 0;

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值