Created
August 21, 2012 07:17
-
-
Save ynonp/3413047 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
| /** | |
| ืืฉืืงืื ืืฆื ืืช ืืืืฆื ืืืคื ืืกืืืจืืคืื | |
| ืืืฉืืง ืืืฆืืื ืขื ืืืกื 4 ืขืฆืืื, ืืืืฉืชืืฉ ืฆืจืื ืืืืืจ ืืช ืืืืฆื ืืืคื. | |
| ืื ืืกืฃ, ืขื ืืืกื ืืืฆื ืื ืืื ืชืืฆืืืช. | |
| ืืงืื ืืชืืจ ืืืฉื ืืื ืืืช ืขืฆืืื ืืืขืืื. ืื ื ืืืืืจืื ืืืืืืงื ืืื ืืื ืืืืืื ืืื ืืคืขืืืื ืฉืฆืจืืืื ืืืืคืืข ืขื ืืืกื: | |
| ืืืืช ืฉืฆืจืื ืืืืืฅ ืขืืื ืืื ืื ืฆื | |
| 3 ืืืืืืช ืฉืืืืฆื ืขืืืื ืืืจืืช ืืืคืกื | |
| ืคืื ื ืฉื ืชืืฆืืืช | |
| ืื ืืื ืืืืืืืืงืืื ืื ืื ืืช ืขืฆืื, ืืืืืืช ืืฆืืจื ืืขืืื ืืช ืืืืืืืงืืื ืืืืจืื ืืืืจืืขืื. | |
| ืื ืืกืฃ, ืืื ืืื ืืืืืืืืงืืื ืืฉ ืืืืืช ืืฆืืืจ ืืช ืขืฆืื ืขื ืืืกื - ืคืื ืงืฆืืืช render | |
| ืืื ืืืืืืฃ ืืช ืืชืืื ื ืืฆืืจื ืื ืืืฆืื - ืคืื ืงืฆืืืช update | |
| */ | |
| (function() { | |
| /** | |
| ืืืืืืืงื ืืจืืฉืื ืืชืืื ืืช ืืื ืืื ืื ืงืืืืช. ืืืื ืืืืืง ืืช ืื ืืงืื ืื ืืืื, | |
| ืืืกืคืง ืคืื ืงืฆืืืช ืืืืกืืฃ ืื ืืืคืก ื ืืงืื, ืื ืืฆืืืจ ืืช ืขืฆืื ืขื ืืืกื | |
| ืืื ืื ื ืขืืืื ืื ืืืฆืจืื ืืช ืืื ืื ืงืืืืช, ืืื ืจืง ืืืืืจืื ืชืื ืืช (ืคืื ืงืฆืืื) ืฉืชืืื ืืืฆืืจ | |
| ืืืืืช ื ืงืืืืช ืืืืฉื ืืชืืื ืืช. ืืืฆืืจื ืขืฆืื ืชืชืืฆืข ืืืืฆืขืืช ืงืจืืื ื | |
| new Score() | |
| ืืืืฉื | |
| */ | |
| var Score = function() { | |
| this.value = 0; | |
| this.increase = function() { | |
| this.value += 1; | |
| }; | |
| this.zero = function() { | |
| this.value = 0; | |
| }; | |
| /** | |
| ืืฉืืื ื ืงืืืืช ืืฆืืืจ ืืช ืขืฆืื ืขื ืืืกื ืืื ืืืคืฉ ืืืื ื ืขื ืงืืืก | |
| score | |
| ืืชืืชืื ืจืืฉื ืฉืืจืช ืืงืกื ืืืืืืช ืืช ืื ืืงืื ืื ืืืื | |
| */ | |
| this.render = function() { | |
| $('.score').html('Player score: <span>' + this.value + '</span>') | |
| }; | |
| }; | |
| ////////////////////////////////////////////////////// | |
| /** | |
| ืืืืจืช ืืืฉืชื ืื ืืืืืืืืืื: | |
| ืจืฉืืืช ืืฉืืงื ืื ืืืืืจืช ืืืืืช ืืขืจื ืจืืง, | |
| ืืื ืื ืงืืืืช ืืืืืจ ืืืืืช ืืืืืืงื ืืืฉ ืืกืื Score | |
| */ | |
| var players = []; | |
| var score = new Score(); | |
| ////////////////////////////////////////////////////// | |
| /** | |
| ืืขืฆืืื ืืืืื ืฉืืืคืืขื ืื ืืฉืืงื ืื: ืื ืฆื ืืืคืกืื | |
| ืืงืื ืฉื ืฉื ืืื ืื ืืืื. | |
| ืืื ืืฉ ืื ื ืฉื ื ืืืจืื ืืขื ืืื ืื - ืื ืื ืืืฆืื, ืืื ืืืืืช ืืืฆืื ืืช ืขืฆืื ืขื ืืืกื | |
| ืื ืืกืฃ ืืืืื, ืฉืืงื ืื ืฆื ืื ืชืืื ืืืืืฆืืช ืืืื ืฆืจืื ืืืืืช ืืฉืืืืฆืื ืขืืื ืืื ืืืชืืื ืกืืืื | |
| ืืฉืืง ืืืฉ. | |
| ืื ืืืืง ืืจืืฉืื ืืืงืืฉ ืืื ืืืฆืื. ืื ื ืืืืืจืื ืืขืจื ืฉื ืชืืื ืืช ืจืงืข | |
| ืืืื ืคืขืืืช ืฉืขืืช ืืืืืคืื ืืช ืชืืื ืช ืืจืงืข - ืื ืื ืฉืืืืฆืจ ืืช ืืื ืืืฆืื. | |
| ืืคืื ืงืฆืืื update ื ืงืจืืช ืืืงืื ืืืืฆืื ื. ืื ืื ืืื ืืืฆืืืช ืืืฉืืง ืืกืื ืืจื ืืช | |
| ืืืงืื ืื ืื ืืกืคืจ ืฉืขืื ืื ืืืงืืื. | |
| ืคืื ืงืฆืืืช render ืฉืืฆืืื ืืช ืืฉืืงื ืขื ืืืกื ืขืืฉื ืขืื ืืืจ ืื ืืกืฃ ืืืฆืื - | |
| ืืื ืงืืฉืจืช ืคืื ืงืฆืืืช ืืืคืื ืืืืืฆื. | |
| ืื ืืฉืืืฉืื ืืืืฅ ืขื ืืืืืช ืืงืจื ืืงืื ืืคืื ืงืฆืื | |
| clicked_on | |
| */ | |
| var Winner = function() { | |
| var backgrounds = [ | |
| '-8px -5px;', | |
| '-52px -6px;', | |
| '-94px -6px;', | |
| '-139px -5px;' | |
| ]; | |
| var background_idx = 0; | |
| this.update = function() { | |
| // Choose the next image from the array | |
| // ( % means modulus, so the numbers go: 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, ... ) | |
| var next_image = | |
| backgrounds[background_idx % backgrounds.length]; | |
| // update the css | |
| $('div.winner').css('background-position', next_image); | |
| // and increase the index | |
| background_idx += 1; | |
| }; | |
| // When the winner is clicked on, we increase the score and start a new round | |
| this.clicked_on = function() { | |
| score.increase(); | |
| start_new_round(); | |
| }; | |
| this.render = function() { | |
| $('div.container').append('<div class="winner"></div>'); | |
| $('div.container div').last().click( this.clicked_on ); | |
| }; | |
| }; | |
| var Looser = function() { | |
| backgrounds = [ | |
| '-4px -55px;', | |
| '-53px -56px', | |
| '-98px -55px', | |
| '-143px -55px' | |
| ]; | |
| var background_idx = 0; | |
| // When the looser is clicked on, we zero the score and start a new round | |
| this.clicked_on = function() { | |
| score.zero(); | |
| start_new_round(); | |
| }; | |
| this.update = function() { | |
| var next_image = | |
| backgrounds[background_idx % backgrounds.length]; | |
| $('div.looser').css('background-position', next_image); | |
| background_idx += 1; | |
| }; | |
| this.render = function() { | |
| $('div.container').append('<div class="looser"></div>'); | |
| $('div.container div').last().click( this.clicked_on ); | |
| }; | |
| }; | |
| ///////////////////////////////////////////////////// | |
| /** | |
| ืืืืง ืืืืจืื ืืชืืื ืืช ืืื ืืงืื ืืจืืฉื ืฉืืคืขืื ืืช ืืชืืื ืืช | |
| ืืคืื ืงืฆืืืช start_new_round | |
| ืคืื ืงืฆืืื ืื ื ืงืจืืช ืืชืืืืช ืืืฉืืง, ืืื ืืื ืื ืกืืืื. ืืื ืืืคืกืช ืืช ืืื ืืืฉืืง, | |
| ืืืจืืื 4 ืฉืืงื ืื ืืืฉืื (3 ืืคืกืืืื ืืื ืฆื) | |
| ืืืฆืืื ืืืชื ืขื ืืื ืืืฉืืง ืืืืฉ ืืืืฆืขืืช ืงืจืืื ื render | |
| ืื ืืกืฃ ืืื ืื ืืืกืืคื ืืช ืื ืืฉืืงื ืื ืืืขืจื ืืื ืฉื ืืื ืืืคืขืื ืขืืืื ืืช ืืื ืืืฆืื | |
| */ | |
| var start_new_round = function() { | |
| players = []; | |
| $('div.container').html(''); | |
| var winning_idx = Math.floor( Math.random() * 4 ); | |
| for ( var i=0; i < 4; i++ ) { | |
| var next; | |
| if ( i === winning_idx ) { | |
| next = new Winner(); | |
| } else { | |
| next = new Looser(); | |
| } | |
| players.push( next ); | |
| next.render(); | |
| } | |
| score.render(); | |
| }; | |
| // On page load | |
| $(function() { | |
| /* | |
| ืืฉืืขืืื ื ืืขื, ืืชืืืืื ืกืืืื ืืืฉ ืืื ืืชืืืืื ืฉืขืื ืืื ืืืฆืื | |
| ืืื 200 ืืืื ืฉื ืืืช ืืงืื ืขืืืจ ืขื ืื ืืฉืืงื ืื ืืืขืจื ืืืคืขืื ืืช ืคืื ืงืฆืืืช | |
| update | |
| ืฉืืื ืืื ืฉืืชืืื ื ืขื ืื ืฉืืงื ืชืชืืืฃ | |
| */ | |
| start_new_round(); | |
| setInterval(function() { | |
| for ( var i=0; i < players.length; i++ ) { | |
| players[i].update(); | |
| } | |
| }, 200); | |
| }); | |
| }()); |
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
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
| "http://www.w3.org/TR/html4/loose.dtd"> | |
| <html> | |
| <head> | |
| <title>Ultimate RedSpotter (Free)</title> | |
| <meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=0" /> | |
| <style> | |
| div.container { | |
| width:150px; | |
| margin:0 auto; | |
| } | |
| div.container div { | |
| background: url('billyblaze.png') no-repeat -139px -5px; | |
| width: 16px; | |
| height: 32px; | |
| float: left; | |
| margin:20px; | |
| } | |
| div.container div.winner { | |
| background: url('billyblaze.png') no-repeat -139px -5px; | |
| } | |
| div.score { | |
| clear:both; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| </div> | |
| <div class="score"> | |
| </div> | |
| <script src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js"></script> | |
| <script src="game.js"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment