ANA SAYFA | FORUM | BLOG | SİTENİZ İÇİN | İÇERİK EKLE | EN YENİLER | EN POPÜLERLER | EN BEĞENİLENLER | REKLAM | İLETİŞİM
Arama:
Tüm kategorilerde Google Forumda JAVAScript Araçlar
// ÖZELLEŞTİR
E-posta:
Şifre:
Üye Ol
|
Şifremi Unuttum
>> ARŞİVİMİZ FORUM AÇILDI! (0 yorum)>> Ramazan Bayramınız kutlu olsun (2 yorum)>> Kurban Bayramı (0 yorum)>> 10 Kasım (1 yorum)>> CUMHURİYET BAYRAMI (0 yorum)
// EN YENİLER
// EN POPÜLER
// Anasayfa » JAVASCRIPT» Oyunlar ve Eğlence
Oy:
>> Arşivimiz Forum'da Bemmu typing speed tester (ing) ile ilgili açılmış konuları ara>> Veya bu içerik ile ilgili yeni bir konu aç
<!-- (c) Bemmu Sepponen, 2005-2006 Feel free to copy portions of the source for your own use or reference. If you put this game on your own site you have to provide a link back to the page speed.bemmu.com. The link must be visible and cannot be a norel link. --> <html> <head> <style> body { background: black; color: #55FF55; font-family: "lucida console", arial, sans-serif; font-weight: bold;} </style> </head> <body onload="onload();"> <input id="txt" type=text size=120 style="position: absolute; top: 400px;"> <div id="name" style="position: absolute; top: 370px; left: 270px"></div> <div id="score" style="position: absolute; top: 370px; left: 20px">Score: 0</div> <div id="lives" style="position: absolute; top: 370px; left: 500px">Lives: 10</div> <script> // Browser check ie = 0; if (navigator.appVersion.indexOf("MSIE")!=-1){ ie = 1; } // Move words from a newline-delimited dictionary to an easier to read array. dictionary = "cow\nbull\ncalf\nhorse\nfoal\nsow\npig\nsheep\nlamb\ngoat\nkid\ncat\nkitten\ndog\npuppy\ncub\nreindeer\nhen\ncock\nchicken\ngoose\nturkey\nduck\nwolf\nfox\nelk\nswallow\nswan\nlark\n"; // later replaced by PHP var dict = dictionary.split("\n"); // The horizontinal areas in this script are called "slots". At one time there can // be only one moving div inside such a slot. In the divs array the array id is the // slot id. var score, max, initialSpeed, rednessBoundary, randomDelay, tooFar; var oneTickJump, speed, speedDecrement, lowerSpeedBoundary, scoreAddition; var slotSpacing, arrivalSpeed, ticksToNext, lives, cleared; function initVars() { score = 0; max = 16; divs = new Array(max); initialSpeed = 150; rednessBoundary = 450; randomDelay = 20; tooFar = 550; oneTickJump = 7; speed = initialSpeed; speedDecrement = 25; lowerSpeedBoundary = 100; scoreAddition = 3; slotSpacing = 20; arrivalSpeed = 50; // It takes this many ticks for next text to come ticksToNext = 1; // How many ticks until next text lives = 10; cleared = 0; } function arvonimi(score) { if (score >= 10000) return "CHEATER :D"; if (score >= 1000) return "!! God !!"; if (score >= 900) return "Divine!"; if (score >= 800) return "Supreme!"; if (score >= 700) return "You rule!"; if (score >= 600) return "Whoa!"; if (score >= 500) return "Fantastic"; if (score >= 400) return "Great"; if (score >= 300) return "Good"; if (score >= 200) return "Pretty good"; if (score >= 100) return "Beginner"; return "Type!"; } // Refreshes the score display function updateScore() { document.getElementById("score").innerHTML = "Score: " + score; document.getElementById("name").innerHTML = arvonimi(score); } // The user entered some text and pressed enter function enter() { // Get inputted text and clear the field var txt; if (document.getElementById) { txt = document.getElementById("txt").value; } else { txt = document.all["txt"].value; } // Special case for high score board if (lives == 0 && txt == "start") gameOverEnter(); // Did the inputted text match some text on the screen? matched = -1; for (i = 0; i < max; i++) { if (divs[i] != null) { if (divs[i].easyText.toLowerCase() == txt.toLowerCase()) { matched = i; } } } // If so, disable text and add some score & increase speed. if (matched != -1) { ticksToNext = 3; document.body.removeChild(divs[matched]); divs[matched] = null; score += scoreAddition + Math.floor(txt.length * 1.5); updateScore(); if (speed > lowerSpeedBoundary) { speed -= speedDecrement; } cleared++; if (cleared > 1) arrivalSpeed = 30; if (cleared > 5) arrivalSpeed = 20; if (cleared > 9) arrivalSpeed = 15; if (cleared > 12) arrivalSpeed = 12; if (cleared > 15) arrivalSpeed = 8; if (cleared > 25) arrivalSpeed = 7; if (cleared > 30) arrivalSpeed = 6; if (cleared > 35) arrivalSpeed = 5; if (cleared > 50) arrivalSpeed = 4; if (cleared > 60) arrivalSpeed = 3; if (cleared > 70) arrivalSpeed = 2; if (cleared > 80) arrivalSpeed = 1; } document.getElementById("txt").value = ""; } function newText(str, slot) { // Create a new div and put it in the slot div = document.createElement("div"); div.innerHTML = str; div.easyText = str; div.style['position'] = "absolute"; div.easyLeft = 15; div.style['left'] = div.easyLeft + "px"; div.style['top'] = 20+slot*slotSpacing + "px"; divs[slot] = div; // Add the div to the DOM hierarchy to make it visible document.body.appendChild(div); } // Enter pressed while game over function gameOverEnter() { document.body.removeChild(div); initVars(); setTimeout("tick()", initialSpeed); updateScore(); document.getElementById("txt").focus(); // ... todo } function gameOver() { // Clear all text for (var i = 0; i < max; i++) { if (divs[i] != null) { document.body.removeChild(divs[i]); } } div = document.createElement("div"); div.innerHTML = "<center>Click <a href=\"javascript:gameOverEnter()\">HERE</a> to play<br>Or type \"start\"</center>"; div.style['position'] = "absolute"; div.style['left'] = "220px"; div.style['top'] = "170px"; document.body.appendChild(div); // TODO actual highscore board return; // Init some dummy scores var names = new Array(10); var scores = new Array(10); for (i = 0; i < 10; i++) { names[i] = "Kettunen"; scores[i] = (1000 - i * 100); } // Shift high scores around new score var newNames = new Array(10); var newScores = new Array(10); mySlot = -1; for (i = 9; i >= 0; i--) { if (score > scores[i]) { newNames[i] = names[i-1]; newScores[i] = scores[i-1]; } else { if (mySlot == -1) mySlot = i + 1; newNames[i] = names[i]; newScores[i] = scores[i]; } } if (score > scores[0]) mySlot = 0; if (mySlot != -1) { newNames[mySlot] = '<input type=text id=name size=20 value="-- type here --">'; newScores[mySlot] = score; for (i = 9; i >= 0; i--) { names[i] = newNames[i]; scores[i] = newScores[i]; } } // Display high scores html = "High scores<p>"; for (i = 0; i < 10; i++) { html += scores[i] + ' ' + names[i] + ' (' + arvonimi(scores[i]) + ')<br>'; } div = document.createElement("div"); div.innerHTML = html; div.style['position'] = "absolute"; div.style['left'] = "200px"; div.style['top'] = "50px"; document.body.appendChild(div); } function randomNewText() { // Abort if all slots are taken allSlotsTaken = true; for (i = 0; i < max; i++) { if (divs[i] == null) allSlotsTaken = false; } if (allSlotsTaken == true) return; // Find random empty slot do { var slot = Math.floor(Math.random() * max); } while (divs[slot] != null); // Select random text which is not already in play do { var i = Math.floor(Math.random() * dict.length); inPlay = false; for (j = 0; j < max; j++) { if (divs[j] != null && divs[j].easyText.toLowerCase() == dict[i].toLowerCase()) { inPlay = true; } } } while (inPlay == true); newText(dict[i], slot); } function tick() { if (lives == 0) return; // Move all divs to the right for (i = 0; i < max; i++) { if (divs[i] != null) { divs[i].easyLeft += oneTickJump; divs[i].style['left'] = divs[i].easyLeft + "px"; } } // If a div gets near the edge, make it red. for (i = 0; i < max; i++) { if (divs[i] != null) { if (divs[i].easyLeft >= rednessBoundary) { divs[i].style['color'] = "red"; } } } // If a div got too far to the right, disable it. for (i = 0; i < max; i++) { if (divs[i] != null) { if (divs[i].easyLeft >= tooFar) { document.body.removeChild(divs[i]); divs[i] = null; // Decrease lives, die if lives reach zero. lives--; document.getElementById("lives").innerHTML = "Lives: " + lives; if (lives == 0) { gameOver(); } } } } // Create a new piece of text if it's time has come if (--ticksToNext == 0) { if (lives > 0) randomNewText(); ticksToNext = arrivalSpeed + Math.floor(Math.random() * randomDelay); } setTimeout("tick()", speed); } function keyDown(DnEvents) { if (ie) { k=window.event.keyCode; } else { k=DnEvents.which; } if (k == 13 || k == 37 || k == 38 || k == 39) enter(); } function onload() { initVars(); lives = 0; gameOver(); if (document.getElementById) { document.getElementById("txt").focus(); } else { document.all["txt"].focus(); } document.onkeydown = keyDown; setTimeout("tick()", initialSpeed); } </script> </body> </html>/
Kodu Kopyala
Hata Bildir | Tavsiye Et
Bu içeriğe oy verin:
Yorumlar / Yeni Yorum Yaz
ANA SAYFA | İÇERİK EKLE | YENİ EKLENENLER | EN POPÜLERLER | EN BEĞENİLENLER | REKLAM | DESTEKLEYENLER | İLETİŞİM
JAVAScript İndir © 2004 - 2008Web Tasarımı: Emir Emiroğlu | Kodlama: Can "FiNaRFiN" HANHAN , Korkut TAHAOĞLU, Göktuğ İÇÖZ