Function module: Program design:
1. You can select the game time and display the countdown 1. Define global variables
2. You can select the number of English letters to appear 2. Control the game time function
3. Statistical scores 3. Animation effect
4. Menu option 4. Set the time when the letter picture appears
5. Judgment function
6. Game menu
7. Game time option
8. Display game time
9. Game difficulty options
10. Game score
First, the renderings: (PS: The art is flawed)
Main code design:
//-------全局变量-------
var data={
"10":["




"14":["




"18":["




"22":["




"26":["




"30":["




"34":["


};
var datas=new Array();//随机出现的 class样式以数组中偶数存储,图片以数组中奇数存储
var now=new Date();
var Image; //随机出现图片
var Divs;//随机出现层
var count=0;//积分系统
var key;//键盘的值
var amounts=1;//出现字母图片的个数
var gametime=30;//控制游戏的时间
var gametimes;//时间为0
var gametimess=30;//显示时钟变量
var time1;//setInterval变量
var time2=5000;//设定setInterval的时间
var time3;
var tab;//用来记录,传递tabindex焦点位置的值
//--------这样写为了兼容FF浏览器-------
var plug = {
addEvent:function(o,e,f){
if(o.addEventListener){
o.addEventListener(e,f,false);
}
else if(o.attachEvent){
o.attachEvent("on"+e,f);
}
}
}
plug.addEvent(window,"load",function(){Focus()});//兼容FF浏览器
//------1.控制游戏时间函数--------
function Gametime(){
for(gametimes=gametime;gametimes>=0;gametimes--) {
window.setTimeout('Show(' + gametimes + ')',(gametime-gametimes+2) * 1000);
}
}
function Show(gametimes){
if(gametimes==0){
clearInterval(time1);//停止游戏
alert("游戏结束!你的得分为:"+count);
$("#main").empty();//清除main中的div
$(".gameapply").empty();
$("#select1").empty();
$("#select2").empty();
count=0;//得分清空为0
Score();//让分数框显示为0
Focus();//重新生成菜单选项
}
}
//---------2.动画效果---------
function fun(){
datas.length=0;
for(var i=0;i
datas.push(Image);//图片以数组中偶数存储,从零开始
Divs=parseInt(Math.random() * 8)+1;//随机出现层的class样式即层的不同位置
datas.push(Divs);//样式以数组中奇数存储
var time=parseInt(Math.random() * 2000)+3000;//完成动画的时间
if(timevar $divs=$("
$("#main").append($divs);
//-----JQ animation function----
$(".divPop" Divs). animate(
{"top":$(window).height() - $(".divPop" Divs).height() - $(".divPop" Divs).position().top},time, function(){$("#main").empty()})
}
}
}
//--------3. Set the letter picture to appear Time ------
function sets(){
time1 = setInterval(fun,time2);
}
//---------4. Bind keyboard ---------
//---------Compatible with FF browser---------
document.onkeydown = function keydown(e){
e = e||window.event;
var key = e.charCode||e.keyCode
select(key)
}
//--------- 5. Judgment function---------
function select(key){
if(key==13){
switch(tab){
case 0:Gametime() ;Gametimeselect();time3=setInterval(countdown,1000);sets();$("#select").hide(2000);break;//Start the game
case 1:Gametime();Gametimeselect() ;time3=setInterval(countdown,1000);sets();$("#select").hide(2000);break;//Start the game
case 2:alert("Game options can be set on the left" );break;
case 3:window.opener=null;window.open('','_self');window.close();break;//Exit the game
case 4:window.opener= null;window.open('','_self');window.close();break;//Exit the game
}
}
for(var j=0;j
$(".divPop" datas[j 1]).hide();//The key values are equal, hide the layer
delete datas[j]; //In order to avoid having Duplicate letters, so every time a (key==datas[j] 55) is traversed in the array, this value must be deleted
count =10;
Score();
break;
}
}
}
//---------6. Game menu-------
function Focus(){
//----- ----Initialize the game interface--------
var $selects=$("
$(".gameapply").append($selects);
for( var i=30;i$("#select1").append('')
}
for(var j=1;j$("#select2").append('')
}
//---------Get the focus of the first input at the beginning--------
$(".inputs:first").trigger("focus").addClass ("input1");
tab=1;//Because Enter cannot be entered in the first focus, the keyboard input event needs to be called
var tabIndex=1;
//----- -----Get the number of tr rows and the number of inputs--------
$("#tables").find("tr").each(function(r) {
$ (this).find("input").attr("tabindex", r 1);//tabindex is the value of the focus position, the initial value is assigned to 1, and the traversal is 1-2-3-4
}) ;
//---------Response to input keyboard up and down operations
$("#tables .inputs").bind("keydown", function(e){
tabIndex = parseInt($(this).attr("tabindex"));//Get the value of the current tabindex focus
switch(e.which){
case 38://up
tabIndex-=1;
tab=tabIndex;
break;
case 40://down
tabIndex =1;
tab=tabIndex;
break;
default:
return ;
}
//--------Determine the value of tabIndex focus
if (tabIndex > 0 && tabIndex $(".inputs[tabindex= " tabIndex "]").focus().addClass("input1"); //The current input gets focus
for(var i=0;i{
if( i==tabIndex){
break;
}
else{
$(this).removeClass("input1");
}
}
keydown();
return false;
}
return true;
});
}
//--------7. Game time options------ ---
function Gametimeselect(){
var option=document.getElementById("select1");
for(var i=0;i
gametime=option.options[i].text;
gametimess=gametime;
}
}
}
//---- -8. Display game time -------
function countdown(){
var timesshows=document.getElementById("timeshow");
if(timeshows){//If the web page speed is very fast If it is slow, the control may not be loaded when the timer is running
if(gametimessclearInterval(time3);//Stop the timer
}
else{
timeshows. value=gametimess;
gametimess--;
}
}
}
//--------9. Game difficulty options---------
function Gameselectamount(){
var option=document.getElementById("select2");
for(var i=0;i
amounts=option.options[i].text;
}
}
}
//---------10. Game score- ----------
function Score(){
var sum=document.getElementById("sum");
sum.value=count;
if(count== 0){ //Initialize the text box score to 0
sum.value=count;
}
}
Summary: Since the time interval is relatively long, the code has not been optimized. There is one place that is not done very well, that is, the time interval between letters appearing is too long. If you are interested, you can try to fix it. The code is for reference only
Online demo:http://demo.jb51.net/js/2011/StarWars/
Package download: http://www.jb51.net /jiaoben/40902.html

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
