用OO方式写键盘字母小游戏
<html>
<head>
<title>0.0</title>
<script>
window.onload=function Test(){
alert("游戏提示,本游戏没有关卡限制,每次得分超过整百时,进入下一关,点击确定开始游戏吧!");
var game=new Game();
game.start();
}
var times;
var words;
var down=2;
var fen=100;
var createCharDiv=new Array();
function Game(){
//alert("coming game()");
words=new Array("A","B","C","D","E","F","G","H","I","J","K","L","N","M","O","P","Q","R","S","T","U","V","W","Z","X","Y");
var createBackground=new CreateBackground();
var createScore=new CreateScore();
//var createCharDiv=new CreateCharDiv();
this.start=function(){
for(var i=0;i<5;i++){
createCharDiv[i]=new CreateCharDiv();
}
times=setInterval(function(){
for(var i=0;i<5;i++){
createCharDiv[i].move();
}
},50);
document.onkeydown=keydown;
function keydown(e){
var real=String.fromCharCode(e.which);
//alert(real);
for(var i=0;i<5;i++){
if(createCharDiv[i].divHTML()==real){
//alert("zhong");
createScore.addScore();
createCharDiv[i].againTop();
}
}
}
}
}
function CreateBackground(){
//alert("coming CreateBackground()");
var newBackground;
function initBackground(){
//alert("coming initBackground()");
newBackground=document.createElement("div");
//alert(newBackground);
newBackground.style.width="500px";
newBackground.style.height="600px";
newBackground.style.border="3px solid black";
newBackground.style.position="absolute";
//newBackground.style.background="pink";
document.body.appendChild(newBackground);
}
initBackground();
}
function CreateScore(){
//alert("1");
var scoreboard;
var score=0;
function initScore(){
//alert("2");
scoreboard=document.createElement("div");
scoreboard.style.width="100px";
scoreboard.style.height="20";
scoreboard.style.top="10px";
scoreboard.style.left="405px";
scoreboard.style.position="absolute";
scoreboard.style.border="3px solid black";
scoreboard.style.background="green";
scoreboard.innerHTML="得分:"+score;
document.body.appendChild(scoreboard);
//alert(scoreboard);
}
initScore();
this.addScore=function(){
score+=10;
scoreboard.innerHTML="";
scoreboard.innerHTML="得分:"+score;
if(score==fen){
alert("亲,即将进入下一关,请做好准备!");
down++;
fen+=100;
//alert("fen"+fen);
for(var i=0;i<5;i++){
createCharDiv[i].againTop();
}
}
}
}
function CreateCharDiv(){
//alert("CreateCharDiv()");
var newDiv;
var numbs=0;
function initCharDiv(){
//alert("initCharDiv()");
num=parseInt(Math.random()*words.length);
//alert(words.length);
newDiv=document.createElement("div");
newDiv.style.width="30px";
newDiv.style.height="30px";
newDiv.style.border="1px solid black";
newDiv.style.position="absolute";
newDiv.style.top="20px";
//规定范围内取随机数 *(上限-下限+1)+下限
//newDiv.style.left=parseInt(Math.random()*480)+"px";
newDiv.style.left=parseInt(Math.random()*(470-20+1)+20)+"px";
newDiv.style.background="red";
newDiv.innerHTML=words[num];
document.body.appendChild(newDiv);
}
initCharDiv();
this.move=function(){
//alert("move()");
newDiv.style.top=parseInt(newDiv.style.top)+down;
if(parseInt(newDiv.style.top)>580){
clearInterval(times);
alert("oh oh oh , game over !");
}
}
this.divHTML=function(){
return newDiv.innerHTML;
}
this.againTop=function(){
newDiv.style.display="none";
initCharDiv();
}
}
</script>
</head>
<body>
</body>
</html>
用OO方式写键盘字母小游戏的更多相关文章
- C语言写的2048小游戏
基于"基于C_语言的2048算法设计_颜冠鹏.pdf" 这一篇文献提供的思路 在中国知网上能找到 就不贴具体内容了 [摘 要] 针对2048的游戏规则,分析了该游戏的算法特点,对其 ...
- 用面向对象的编程方式实现飞机大战小游戏,java版
概述 本文将使用java语言以面向对象的编程方式一步一步实现飞机大战这个小游戏 本篇文章仅供参考,如有写的不好的地方或者各位读者哪里没看懂可以在评论区给我留言 或者邮件8274551712@qq.co ...
- 几款用jQuery写的h5小游戏
人人都说前端用来做游戏是一件很困难的事情,遇到这些js的逻辑性问题,是不是有点懵?其实,做完一款游戏之后就会发现,没啥难的地方,差不多都是换汤不换药,作为爱玩游戏的我,也总结收集了几款比较流行的小软件 ...
- C/C++编程笔记:C语言写推箱子小游戏,大一学习C语言练手项目
C语言,作为大多数人的第一门编程语言,重要性不言而喻,很多编程习惯,逻辑方式在此时就已经形成了.这个是我在大一学习 C语言 后写的推箱子小游戏,自己的逻辑能力得到了提升,在这里同大家分享这个推箱子小游 ...
- 用python+pygame写贪吃蛇小游戏
因为python语法简单好上手,前两天在想能不能用python写个小游戏出来,就上网搜了一下发现了pygame这个写2D游戏的库.了解了两天再参考了一些资料就开始写贪吃蛇这个小游戏. 毕竟最开始的练手 ...
- 无聊的周末用Java写个扫雷小游戏
周末无聊,用Java写了一个扫雷程序,说起来,这个应该是在学校的时候,写会比较好玩,毕竟自己实现一个小游戏,还是比较好玩的.说实话,扫雷程序里面核心的东西,只有点击的时候,去触发更新数据这一步. Sw ...
- 原生js写的flybird小游戏
游戏地址:http://zangzhihong.jusukeji.com/flybird/index.html html部分 <!DOCTYPE html> <!-- This ...
- 利用while循环写的简单小游戏猜数字
猜数字的大小游戏 C:\Users\Administrator>python Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:1 ...
- HttpWeb服务器之--用OO方式写
虽然写的不是很好,但 最终解释权以及版权归13东倍所有! package com.web; import java.io.IOException; public class Test { public ...
随机推荐
- Oracle中字段的修改操作语法
对字段操作 操作方法 更新字段名 alter table TABLE_NAME rename column column_old to column_new; 添加字段 alter table T ...
- android anim 动画效果
动画效果编程基础--AnimationAndroid 动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效 ...
- JavaScript基本概念(数组)
1.数组方法 /** * join(str) * 将数组元素转换为字符串并使用参数中的字符串将各字符串链接起来 */ var a = [1, 2, 3]; a.join(); // "1,2 ...
- CSS自学笔记(16):CSS3 用户界面
CSS3中,也新增了一些关于用户界面的属性,这些属性可以重设元素或者盒子的尺寸.轮廓等等. 新增的部分属性的浏览器支持情况 属性 浏览器支持 resize IE Firefox Chrome Safa ...
- 4x4矩阵键盘扫描
4x4矩阵键盘扫描 Windows 10 IoT Core 是微软针对物联网市场的一个重要产品,与以往的Windows版本不同,是为物联网设备专门设计的,硬件也不仅仅限于x86架构,同时可以在ARM架 ...
- 当Evernote结合MindManager
最近潜心研究Evernote(印象笔记)在数据存储和GTD规划方面的运用,感觉到的震撼和惊艳,一如当初开始接触MindManager的时候! 我非常喜欢这个SaaS的软件,以至于我将我国际版的Ever ...
- leftpad填充函数;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- iOS动画技术笔记
概述 在IOS开发中,实现动画操作的地方有很多,典型的是在视图控制器的segue操作时.在同一个视图控制器类中,加载切换不同的视图时,也需要动画效果,还有一些视图对象有动画效果会更好. 插一句,在IO ...
- POJ2229 Sumsets 【递归】
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 13210 Accepted: 5300 Descrip ...
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
this bundle is invalid . new apps and app updates submitted to the app store must be built with publ ...