Created
November 7, 2015 09:56
-
-
Save Kanol/71140e18df791579e8b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta charset=utf-8> | |
<style> | |
.q { | |
width: 100px; | |
height: 100px; | |
background: red; | |
border: solid; | |
} | |
.score { | |
position: absolute; | |
bottom: 0; | |
right: 0; | |
background: blue; | |
color: white; | |
} | |
.win { | |
position:absolute; | |
background: yellow; | |
color: grey; | |
font-size: 50; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="score"></div> | |
<div class="win"></div> | |
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> | |
<script> | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function showScore(score) { | |
var $score = $('.score'); | |
$score.text("Ваши очки: " + score); | |
} | |
function generate(a) { | |
for (var i = 0; i < a; i++) { | |
var html = '<div class="q"></div>'; | |
var el = $(html); | |
el.css('position', 'absolute'); | |
el.css('top', getRandomInt(1, h)); | |
el.css('left', getRandomInt(1, w)); | |
el.click(on_click); | |
$(document.body).append(el); | |
} | |
} | |
function winner(){ | |
var $winner = $('.win'); | |
$winner.css('bottom', h1); | |
$winner.css('left', w1-203); | |
$winner.text("YOU WIN, NIGGA"); | |
} | |
function hide(){ | |
$('.q').hide(); | |
} | |
var w = $(window).width() - 101; | |
var h = $(window).height() - 101; | |
var w1 = $(window).width()/2; | |
var h1 = $(window).height()/2; | |
var score = 0; | |
function on_click(e) { | |
var target = $(e.target); | |
target.hide(); | |
score += 1; | |
showScore(score); | |
hide(); | |
generate(10-score); | |
if(score==10){ | |
winner(); | |
} | |
} | |
generate(10); | |
showScore(score); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment