JavaScript 타이핑 게임 코드
기능 모듈: 프로그램 설계:
1. 게임 시간 선택 및 카운트다운 표시 1. 전역 변수 정의
2. 영문자 수 선택 2. 게임 시간 기능 제어
🎜> 3. 통계 점수 3. 애니메이션 효과
4. 메뉴 옵션 4. 글자 그림이 나타나는 시간 설정
5. 판정 기능
6. 게임 메뉴
7. 게임 시간 옵션
8. 게임 시간 표시
9. 게임 난이도 옵션
10. 게임 점수
🎜>
//-------全局变量------- var data={ "10":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/A.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"11":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/B.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"12":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/C.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"13":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/D.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "14":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/E.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"15":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/F.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"16":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/G.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"17":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/H.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "18":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/I.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"19":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/J.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"20":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/K.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"21":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/L.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "22":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/M.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"23":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/N.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"24":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/O.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"25":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/P.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "26":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/Q.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"27":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/R.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"28":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/S.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"29":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/T.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "30":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/U.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"31":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/V.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"32":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/W.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"33":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/X.gif'/ alt="JavaScript 타이핑 게임 코드" >"], "34":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/Y.gif'/ alt="JavaScript 타이핑 게임 코드" >"],"35":["<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/291/249/701/1486350190844834.png" class="lazy" src='images/Z.gif'/ alt="JavaScript 타이핑 게임 코드" >"] }; 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<amounts;i++){ Image=parseInt(Math.random() * 26)+10;//随机出现字母图片 datas.push(Image);//图片以数组中偶数存储,从零开始 Divs=parseInt(Math.random() * 8)+1;//随机出现层的class样式即层的不同位置 datas.push(Divs);//样式以数组中奇数存储 var time=parseInt(Math.random() * 2000)+3000;//完成动画的时间 if(time<5000){ var $divs=$("<div class='divPop"+Divs+"'>"+data[Image]+"</div>"); $("#main").append($divs); //-----JQ动画函数---- $(".divPop"+Divs).animate( {"top":$(window).height() - $(".divPop"+Divs).height() - $(".divPop"+Divs).position().top},time,function(){$("#main").empty()}) } } } //--------3.设定字母图片出现的时间------ function sets(){ time1 = setInterval(fun,time2); } //---------4.绑定键盘--------- //---------兼容FF浏览器--------- document.onkeydown = function keydown(e){ e = e||window.event; var key = e.charCode||e.keyCode select(key) } //---------5.判断函数--------- function select(key){ if(key==13){ switch(tab){ case 0:Gametime();Gametimeselect();time3=setInterval(countdown,1000);sets();$("#select").hide(2000);break;//开始游戏 case 1:Gametime();Gametimeselect();time3=setInterval(countdown,1000);sets();$("#select").hide(2000);break;//开始游戏 case 2:alert("可以在左侧设置游戏选项");break; case 3:window.opener=null;window.open('','_self');window.close();break;//退出游戏 case 4:window.opener=null;window.open('','_self');window.close();break;//退出游戏 } } for(var j=0;j<datas.length;j=j+2){//为了让data1里面样式和图片的值不重复(即奇数跟偶数的不可能重复,m的值或者k的值要相差一定的值) if(key==datas[j]+55){ $(".divPop"+datas[j+1]).hide();//key值相等,隐藏该层 delete datas[j]; //为了避免有重复的字母,所以数组里面每遍历到一个(key==datas[j]+55)都要删除这个值 count+=10; Score(); break; } } } //---------6.游戏菜单------- function Focus(){ //---------初始化游戏界面-------- var $selects=$("<div id='select'><table id=\"tables\"><tr><td><input class=\"inputs\" type=\"text\"value=\"游戏开始\"/></td></tr><tr><td><input class=\"inputs\" type=\"text\" value=\"游戏选项\"/></td></tr><tr><td><input class=\"inputs\" type=\"text\" value=\"退出游戏\"/></td></tr></table></div>"); $(".gameapply").append($selects); for(var i=30;i<=300;i=i+30){ $("#select1").append('<option>' + i+ '</option>') } for(var j=1;j<=9;j++){ $("#select2").append('<option>' + j+ '</option>') } //---------开始时取得第一个input的焦点-------- $(".inputs:first").trigger("focus").addClass("input1"); tab=1;//因为第一个焦点是没法输入Enter,所以要调用键盘输入事件 var tabIndex=1; //----------获取tr行数,input个数-------- $("#tables").find("tr").each(function(r) { $(this).find("input").attr("tabindex", r+1);//tabindex为焦点位置的值,赋初值为1,遍历为1-2-3-4 }); //---------响应input的键盘上下操作 $("#tables .inputs").bind("keydown", function(e){ tabIndex = parseInt($(this).attr("tabindex"));//取得当前tabindex焦点的值 switch(e.which){ case 38://向上 tabIndex-=1; tab=tabIndex; break; case 40://向下 tabIndex+=1; tab=tabIndex; break; default: return; } //--------判断tabIndex焦点的值 if (tabIndex > 0 && tabIndex < 4) { $(".inputs[tabindex=" + tabIndex + "]").focus().addClass("input1");//当前input获取焦点 for(var i=0;i<=4;i++) { if(i==tabIndex){ break; } else{ $(this).removeClass("input1"); } } keydown(); return false; } return true; }); } //--------7.游戏时间选项--------- function Gametimeselect(){ var option=document.getElementById("select1"); for(var i=0;i<option.length;++i){ if(option[i].selected) { gametime=option.options[i].text; gametimess=gametime; } } } //-----8.显示游戏时间------- function countdown(){ var timeshows=document.getElementById("timeshow"); if(timeshows){//如果网页速度很慢的话,可能定时器运行的时候控件还没有加载 if(gametimess<0){ clearInterval(time3);//停止计时器 } else{ timeshows.value=gametimess; gametimess--; } } } //--------9.游戏难度选项--------- function Gameselectamount(){ var option=document.getElementById("select2"); for(var i=0;i<option.length;++i){ if(option[i].selected) { amounts=option.options[i].text; } } } //---------10.游戏得分----------- function Score(){ var sum=document.getElementById("sum"); sum.value=count; if(count==0){ //初始化文本框分数为0 sum.value=count; } }

JavaScript 타이핑 게임 코드와 관련된 더 많은 글은 PHP 중국어 홈페이지를 주목해주세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











기사는 JavaScript 라이브러리 작성, 게시 및 유지 관리, 계획, 개발, 테스트, 문서 및 홍보 전략에 중점을 둡니다.

이 기사는 브라우저에서 JavaScript 성능을 최적화하기위한 전략에 대해 설명하고 실행 시간을 줄이고 페이지로드 속도에 미치는 영향을 최소화하는 데 중점을 둡니다.

프론트 엔드 개발시 프론트 엔드 열지대 티켓 인쇄를위한 자주 묻는 질문과 솔루션, 티켓 인쇄는 일반적인 요구 사항입니다. 그러나 많은 개발자들이 구현하고 있습니다 ...

이 기사는 브라우저 개발자 도구를 사용하여 효과적인 JavaScript 디버깅, 중단 점 설정, 콘솔 사용 및 성능 분석에 중점을 둡니다.

기술 및 산업 요구에 따라 Python 및 JavaScript 개발자에 대한 절대 급여는 없습니다. 1. 파이썬은 데이터 과학 및 기계 학습에서 더 많은 비용을 지불 할 수 있습니다. 2. JavaScript는 프론트 엔드 및 풀 스택 개발에 큰 수요가 있으며 급여도 상당합니다. 3. 영향 요인에는 경험, 지리적 위치, 회사 규모 및 특정 기술이 포함됩니다.

이 기사는 소스 맵을 사용하여 원래 코드에 다시 매핑하여 미니어링 된 JavaScript를 디버그하는 방법을 설명합니다. 소스 맵 활성화, 브레이크 포인트 설정 및 Chrome Devtools 및 Webpack과 같은 도구 사용에 대해 설명합니다.

Console.log 출력의 차이의 근본 원인에 대한 심층적 인 논의. 이 기사에서는 Console.log 함수의 출력 결과의 차이점을 코드에서 분석하고 그에 따른 이유를 설명합니다. � ...

동일한 ID로 배열 요소를 JavaScript의 하나의 객체로 병합하는 방법은 무엇입니까? 데이터를 처리 할 때 종종 동일한 ID를 가질 필요가 있습니다 ...
