最高分的面板:

(function (window) {
'use strict';
function HighScore() {
this.canvas = new Canvas('highscore', 100, 70);
this.highScore = 0; this._init();
} HighScore.prototype = {
constructor: HighScore,
_init: function () {
//获取当前最高分
this.highScore = this._getScore();
this._render();
},
_render: function () {
this.canvas.drawText(this.highScore);
},
_getScore: function () {
return window.localStorage.getItem('high-score') || 0;
},
//存取值
_setScore: function (value) {
window.localStorage.setItem('high-score', value);
},
//检查的饭
checkScore: function (score) {
if (score > this.highScore) {
//覆盖
this.highScore = score;
this._setScore(score);
this._render();
}
} }; window.HighScore = HighScore;
})(window);

键盘操作的事件:

(function (window){
'use strict';
var keys = {
38: 'top',
39: 'right',
40: 'down',
37: 'left'
}; function keyboard(){
this.boad;
} keyboard.prototype={
constructor:keyboard,
init:function (board) {
var self=this; //注册事件 keydown 可以连续按
self.board = board;
document.addEventListener('keydown', function (evt) {
self.processKeyDown(evt);
});
}, processKeyDown:function (evt) {
//做相应事件的拦截
if(this.board.gameInst._state!=='playing'){
return;
}
if (keys[evt.keyCode]) {
this.press(keys[evt.keyCode]);
}
}, press: function (key) {
/** console.log(key);*/
//写一个标志性的变量
var refresh=false; switch (key) {
case 'top':
//方块的反转
this.board.shape.rotate();
if(this.board.validMove(0,0)){
refresh=true;
}
break;
case 'right':
if (this.board.validMove(1, 0)) {
this.board.shape.x += 1;
refresh=true;
}
break;
case 'down':
if (this.board.validMove(0, 1)) {
this.board.shape.y += 1;
refresh=true;
}
break;
case 'left':
if (this.board.validMove(-1, 0)) {
this.board.shape.x -= 1;
refresh=true;
}
break;
}
if(refresh){
this.board.refresh();
//重新绘制
this.board.shape.draw(this.board.context);
if (key === 'down') {
var self = this;
window.clearInterval(window.TetrisConfig.intervalId);
window.TetrisConfig.intervalId = window.setInterval(function () {
self.board.tick();
}, TetrisConfig.speed);
}
}
} };
window.keyboard=keyboard;
})(window);

等级的js:

(function (window) {
'use strict';
//自调用的函数
var levelArr=(function(){
var arr=[0];
//分数级别的计算 默认是个等级
for(var i=0;i<10;i++){
arr.push(Math.pow(2,i)*100);
}
return arr;
})(); //得分的面板
function Level() {
this.canvas = new Canvas('level', 100, 70);
//得分
this.level = 1; this._init();
} Level.prototype = {
constructor: Level,
_init: function () {
this._render();
},
//绘制得分
_render: function () {
this.canvas.drawText('Level'+this.level);
},
//检查界别的方法
checkLevel:function(score){
if(score>=levelArr[this.level]){
this.level++;
this._render();
//返回标示变量
return this.level;
}
return 0;
}
//分数的变化
/*** addScore:function(value){
this.score+=value;
//渲染
this._render();
}*/
}; window.Level=Level;
})(window);

下一方块的js:

(function (window) {
'use strict';
//得分的面板
function NextShape() {
this.canvas = new Canvas('nextshape', 100, 70);
this._init();
} NextShape.prototype = {
constructor: NextShape,
_init: function () {
this.rows=4;
this.cols=6; },
//进行渲染
render:function(shape){
this.canvas.clear();
//size加了参数
shape.draw(this.canvas.context,16);
}
}; window.NextShape=NextShape;
})(window);

H5实现俄罗斯方块(三)的更多相关文章

  1. H5版俄罗斯方块(2)---游戏的基本框架和实现

    前言: 上文中谈到了H5版俄罗斯方块的需求和目标, 这次要实现一个可玩的版本. 但饭要一口一口吃, 很多东西并非一蹴而就. 本文将简单实现一个可玩的俄罗斯方块版本. 下一步会引入AI, 最终采用coc ...

  2. H5版俄罗斯方块(3)---游戏的AI算法

    前言: 算是"long long ago"的事了, 某著名互联网公司在我校举行了一次"lengend code"的比赛, 其中有一题就是"智能俄罗斯方 ...

  3. 俄罗斯方块(三):"流动"的方块

    问题的提出: 俄罗斯方块允许90度的坡,是不是有点不够科学#(滑稽) 想办法加一种会“滑坡”的方块 本文两大部分: 详细的描绘是怎样的“流动” 写代码,并整合进游戏 本文基于我写的 俄罗斯方块(一): ...

  4. H5版俄罗斯方块(1)---需求分析和目标创新

    前言: 俄罗斯方块和五子棋一样, 规则简单, 上手容易. 几乎每个开发者, 都会在其青春年华时, 签下"xx到此一游". 犹记得大一老师在布置大程作业的时候提过: "什么 ...

  5. H5版俄罗斯方块(4)---火拼对战的雏形

    前言: 勿忘初心, 本系列的目标是实现一款类似QQ"火拼系列"的人机对战版俄罗斯方块. 在完成了基本游戏框架和AI的算法探索后, 让我们来尝试一下人机大战雏形编写. 本系列的文章链 ...

  6. H5实现俄罗斯方块(一)

    这几天一直忙于公司的项目,涉及到流程问题,(有时间会写成博客的)...一直没有更新... 为了更加巩固js的基础,自己封装类似于JQuery的操作库来对dom进行操作. 一:前度页面的绘制. < ...

  7. H5学习第三周

    今天主要总结弹性布局 flex使用 1.给父容器添加display flex/inline-flex;属性 2.父容器可以使用的属性值有 >>>flex-direction 属性决定 ...

  8. 03 (H5*) Vue第三天

    目录: 1:Vue-resource中的全局配置. 2:Vue动画2部曲 3:animate动画 4:钩子函数动画 5:组件三部曲,推荐使用template标签来创建组件模板 1:Vue-resour ...

  9. 13 (H5*) JS第三天 数组、函数

    目录 1:数组的定义和创建方式 2:数组的总结 3:for循环遍历数组 4:数组的案例 5:冒泡排序 6:函数的定义 7:函数的参数 8:函数的返回值 复习 <script> /* * * ...

随机推荐

  1. bat 命令分行写

    myprog parameter parameter parameter parameter parameter parameter parameter parameter parameter par ...

  2. Sqrt(x) - LintCode

    examination questions Implement int sqrt(int x). Compute and return the square root of x. Example sq ...

  3. centos 7

    vmlinuz initrd=initrd.img linux dd quiet vmlinuz initrd=initrd.img inst.stage2=hd:/dev/sdb4 quiet 关I ...

  4. Open source packages on self-driving car

    Autoware https://github.com/CPFL/Autoware.git Open-source software for urban autonomous driving &quo ...

  5. SQL*Loader实验笔记【二】

      所有SQL*Loader实验笔记 实验案例总结(1-7):     SQL*Loader实验笔记[一] 实验案例总结(8-13):   SQL*Loader实验笔记[二] 实验案例总结(14-19 ...

  6. unittest框架介绍

    1.test fixture(测试框架) 测试准备前要做的工作和测试执行完成后要做的工作,例如测试前需要把数据初始化,测试完成后需要把测试环境中需要关的东西都关掉.主要包括setUp()和tearDo ...

  7. 新建web工程Jdk怎么不是自己安装的, 是自带的

    需要在eclipse中配置默认的jdk环境的,不要用它默认的那个,这个不能用的http://blog.csdn.net/clj198606061111/article/details/11881575 ...

  8. 转帖-[教程] Win7精简教程(简易中度)2016年8月-0day

    [教程] Win7精简教程(简易中度)2016年8月 0day 发表于 2016-8-19 16:08:41  https://www.itsk.com/thread-370260-1-1.html ...

  9. bootstrap系列学习(一)

    最近的一个项目中,正好使用到bootstrap布局前台页面,随便记录一下,个人遇到的一些问题. 一,jquery 版本 使用bootstrap3.0,刚开始没有 按照官网上教程,用了习惯的jquery ...

  10. Code Simplicity–The Science of Software Development 书摘

    Chapter1 Introduction That is the art and talent involved in programming—reducing complexity to simp ...