<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方式写键盘字母小游戏的更多相关文章

  1. C语言写的2048小游戏

    基于"基于C_语言的2048算法设计_颜冠鹏.pdf" 这一篇文献提供的思路 在中国知网上能找到 就不贴具体内容了 [摘 要] 针对2048的游戏规则,分析了该游戏的算法特点,对其 ...

  2. 用面向对象的编程方式实现飞机大战小游戏,java版

    概述 本文将使用java语言以面向对象的编程方式一步一步实现飞机大战这个小游戏 本篇文章仅供参考,如有写的不好的地方或者各位读者哪里没看懂可以在评论区给我留言 或者邮件8274551712@qq.co ...

  3. 几款用jQuery写的h5小游戏

    人人都说前端用来做游戏是一件很困难的事情,遇到这些js的逻辑性问题,是不是有点懵?其实,做完一款游戏之后就会发现,没啥难的地方,差不多都是换汤不换药,作为爱玩游戏的我,也总结收集了几款比较流行的小软件 ...

  4. C/C++编程笔记:C语言写推箱子小游戏,大一学习C语言练手项目

    C语言,作为大多数人的第一门编程语言,重要性不言而喻,很多编程习惯,逻辑方式在此时就已经形成了.这个是我在大一学习 C语言 后写的推箱子小游戏,自己的逻辑能力得到了提升,在这里同大家分享这个推箱子小游 ...

  5. 用python+pygame写贪吃蛇小游戏

    因为python语法简单好上手,前两天在想能不能用python写个小游戏出来,就上网搜了一下发现了pygame这个写2D游戏的库.了解了两天再参考了一些资料就开始写贪吃蛇这个小游戏. 毕竟最开始的练手 ...

  6. 无聊的周末用Java写个扫雷小游戏

    周末无聊,用Java写了一个扫雷程序,说起来,这个应该是在学校的时候,写会比较好玩,毕竟自己实现一个小游戏,还是比较好玩的.说实话,扫雷程序里面核心的东西,只有点击的时候,去触发更新数据这一步. Sw ...

  7. 原生js写的flybird小游戏

    游戏地址:http://zangzhihong.jusukeji.com/flybird/index.html html部分 <!DOCTYPE html>   <!-- This ...

  8. 利用while循环写的简单小游戏猜数字

    猜数字的大小游戏 C:\Users\Administrator>python Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:1 ...

  9. HttpWeb服务器之--用OO方式写

    虽然写的不是很好,但 最终解释权以及版权归13东倍所有! package com.web; import java.io.IOException; public class Test { public ...

随机推荐

  1. PHP中的数组方法及访问方法总结

    一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...

  2. mysql5.7慢查询开启配置

    1.问题 当然又被度娘(我冤枉)坑了噻,网友说配置文件写下面三行: log-slow-queries=D:\Program Files\mysql-5.7.11-winx64\data\low.log ...

  3. VS2008编译boost库

    一.下载首先从boost官方主页http://www.boost.org/下载最新版boost安装包,我用的版本是boost.1.49.0二.新建文件夹 如果是使用下载的安装包,那么请将boost安装 ...

  4. 第一章 andriod studio 安装与环境搭建

    原文 http://blog.csdn.net/zhanghefu/article/details/9286123 第一章   andriod studio 安装与环境搭建 一.Android Stu ...

  5. WPF学习:绑定

    原文 http://www.cnblogs.com/SouthAurora/archive/2010/06/30/1768464.html 一.绑定到元素对象 1.元素和元素(XAML.代码) 1.1 ...

  6. svn常见问题汇总

    has no ancestry information 经查,由于project/,01Dev/的权限被关闭了,把当前文件夹父目录(project/,01Dev/) 下的 .svn/ 目录删除就好了.

  7. perl /m修饰符使用说明

    高级用法: 多行匹配: grok正则和普通正则一样, 默认是不支持匹配回车换行的. perl的/m选项 The /m modifier allows ^ and $ to match immediat ...

  8. poj2909 || poj2262

    #include <stdio.h> #include <stdlib.h> #include<math.h> int isPri(int a, int b) { ...

  9. 普林斯顿大学算法课 Algorithm Part I Week 3 求第K大数 Selection

    问题 给定N个元素的数组,求第k大的数. 特例当k=0时,就是求最大值,当k=N-1时,就是求最小值. 应用顺序统计求top N排行榜 基本思想 使用快速排序方法中的分区思想,使得a[k]左侧没有更小 ...

  10. linux学习之(四)-用户、组的操作,给文件文件夹设置组,更改目录权限、文件权限

    命令帮助查看: man 命令(查看一个命令的详细帮助信息) 例:man useradd 或者用  -h   格式   命令 -h(查看一个命令的简要帮助) 例:useradd -h 用户: 在user ...