Pages
Home
Who I am
Star War
Word Game
Snake Game
Tetris Game
Plane Rider
Sudoku
Casino
Word Game
time :
0
Powered by
Mostafa Rastgar
Source:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script> <script type="text/javascript"> (function($) { $.wordGame = { bank:[], current:null, scene:null, sceneContainer:null, faults:null, correct:null, blackList:null, currentTime:0, createScene:function() { $.wordGame.sceneContainer = $('<div></div>').css({"border-color":"black", "border-width":"1px", "border-style":"solid", "width":"300px", "text-align":"center"}).appendTo("#wordGameDiv"); $.wordGame.scene = $('<div></div>').appendTo($.wordGame.sceneContainer); $.wordGame.createBtn('q'); $.wordGame.createBtn('w'); $.wordGame.createBtn('e'); $.wordGame.createBtn('r'); $.wordGame.createBtn('t'); $.wordGame.createBtn('y'); $.wordGame.createBtn('u'); $.wordGame.createBtn('i'); $.wordGame.createBtn('o'); $.wordGame.createBtn('p'); $("<br/>").appendTo($.wordGame.sceneContainer); $.wordGame.createBtn('a'); $.wordGame.createBtn('s'); $.wordGame.createBtn('d'); $.wordGame.createBtn('f'); $.wordGame.createBtn('g'); $.wordGame.createBtn('h'); $.wordGame.createBtn('j'); $.wordGame.createBtn('k'); $.wordGame.createBtn('l'); $("<input type='button'/>").css({width:"20px"}).val("#").attr({title:"show answer"}).appendTo($.wordGame.sceneContainer).click(function() { alert("answer is '" + $.wordGame.bank[$.wordGame.current] + "'"); $.wordGame.init(); }); $("<br/>").appendTo($.wordGame.sceneContainer); $.wordGame.createBtn('z'); $.wordGame.createBtn('x'); $.wordGame.createBtn('c'); $.wordGame.createBtn('v'); $.wordGame.createBtn('b'); $.wordGame.createBtn('n'); $.wordGame.createBtn('m'); $("<input type='button'/>").css({width:"60px"}).val("clear").appendTo($.wordGame.sceneContainer).click(function() { $.wordGame.init(); }); $("<br/>").appendTo($.wordGame.sceneContainer); $("<span></span>").html("time : ").appendTo($.wordGame.sceneContainer); $("<span id='timer'></span>").appendTo($.wordGame.sceneContainer); $.wordGame.triggerTimer(); $.wordGame.init(); }, createBtn:function(ch) { $("<input type='button'/>").css({width:"20px"}).val(ch).appendTo($.wordGame.sceneContainer).click(function() { $.wordGame.check(ch); }); }, check:function(ch) { var currentWord = $.wordGame.bank[$.wordGame.current]; var lastIndex = -1; if (!$.wordGame.existInBlackList(ch)) { $.wordGame.blackList.push(ch); if (currentWord.indexOf(ch) < 0) { $("#fault" + $.wordGame.faults ++).html(ch); if ($.wordGame.faults > currentWord.length) { alert("you lose ... the answer is '" + $.wordGame.bank[$.wordGame.current] + "'. try again"); $.wordGame.init(); } } else { while ((lastIndex = currentWord.indexOf(ch, lastIndex)) > -1) { $("#span" + lastIndex).html(ch); lastIndex ++; $.wordGame.correct ++; } if ($.wordGame.correct == currentWord.length) { alert("you win after " + $.wordGame.currentTime + " seconds."); $.wordGame.init(); } } } }, existInBlackList:function(ch) { for (var i = 0; i < $.wordGame.blackList.length; i++) { if ($.wordGame.blackList[i] == ch) { return true; } } return false; }, offerNewWord:function() { $.wordGame.current = $.wordGame.suggestCurrent(); var currentWord = $.wordGame.bank[$.wordGame.current]; for (var i = 0; i < currentWord.length; i++) { $("<span id='span" + i + "'></span>").css({"border-bottom-style":"solid", "border-bottom-width":"1px", "border-bottom-color":"black"}).appendTo($.wordGame.scene).html(" "); $("<span></span>").appendTo($.wordGame.scene).html(" "); } $("<br/>").appendTo($.wordGame.scene); for (var i = 0; i < currentWord.length; i++) { $("<span id='fault" + i + "'></span>").appendTo($.wordGame.scene).html(" "); $("<span></span>").appendTo($.wordGame.scene).html(" "); } }, suggestCurrent:function() { return (new Date()).getTime() % $($.wordGame.bank).size(); }, triggerTimer:function() { $("#timer").html($.wordGame.currentTime); setTimeout(function() { $.wordGame.triggerTimer(); }, 1000); $.wordGame.currentTime ++; }, reset:function() { if ($.wordGame.scene) { $.wordGame.scene.html(""); } $.wordGame.blackList = []; $.wordGame.bank = ["maintain", "snub", "endure", "wrath", "expose", "legend", "ponder", "resign", "drastic", "wharf", "amend", "ballot", "unearch", "depart", "coincide", "water", "horse", "clear", "cancel", "picture", "debtor", "placard", "bank", "student", "teacher", "transparent", "scald", "heir", "head", "dwindle", "surplus", "traitor", "walk", "deliberate", "vandal", "abide", "unify", "summit", "heed", "refer", "distress", "diminish", "maximum", "flee", "bulnerable", "signify", "mythology", "provide", "colleague", "loyalty", "outlaw", "promote", "undernourished", "illustrate", "disclose", "excessive", "disaster", "censor", "culprit", "juvenile", "bait", "insist", "fierce", "detest", "sneer", "scowl", "encourage", "consider", "vermin", "wail", "symbol", "authority", "neutral", "trifle", "plea", "weary", "collide", "confirm", "verify", "anticipate", "dilemma", "detour", "merit", "transmit", "relieve", "baffle", "unruly", "rival", "biolent", "brutal", "opponent", "brawl", "duplicate", "vicious", "whirling", "underdog", "thrust", "bewildered", "ignite", "frank"]; $.wordGame.current = $.wordGame.suggestCurrent(); $.wordGame.faults = 0; $.wordGame.correct = 0; $.wordGame.currentTime = 0; }, init:function() { $.wordGame.reset(); $.wordGame.offerNewWord(); } }; })(jQuery); $(function() { $.wordGame.createScene(); }); </script> <div id="wordGameDiv" align="center"></div> <br/> <br/> <br/> <div align="center">Powered by <a href="mailto:mostafarastgar@gmail.com">Mostafa Rastgar</a></div>
Home
Subscribe to:
Posts (Atom)