H5实现俄罗斯方块(一)
这几天一直忙于公司的项目,涉及到流程问题,(有时间会写成博客的)。。。一直没有更新。。。
为了更加巩固js的基础,自己封装类似于JQuery的操作库来对dom进行操作。
一:前度页面的绘制。
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>俄罗斯方块</title>
<link rel="stylesheet" href="css/index.css">
</head> <body>
<div class="start-container">
<p><button id="btn-start">开始游戏</button></p>
<p><button id="btn-setting">设置</button></p>
</div>
<div class="game-container">
<div class="timer-panel">
<div class="panel-header">
使用时间
</div>
<div class="panel-body">
<canvas id="timer"></canvas>
</div>
</div>
<div class="help-panel">
<div class="panel-body">
<p>↑ 翻转方块</p>
<p>↓ 加速下落</p>
<p>→ 向右移动</p>
<p>← 向左移动</p>
</div>
</div>
<div class="level-panel">
<div class="panel-header">
当前级别
</div>
<div class="panel-body">
<canvas id="level"></canvas>
</div>
</div>
<div class="game-main-panel">
<canvas id="c_game_main"></canvas>
</div>
<div class="next-panel">
<div class="panel-header">
下一方块
</div>
<div class="panel-body">
<canvas id="nextshape"></canvas>
</div>
</div>
<div class="setting-panel">
<div class="panel-body">
<button id="btn-game-pause">暂停</button><br><br><button id="btn-game-setting">设置</button>
</div>
</div>
<div class="score-panel">
<div class="panel-header">
当前得分
</div>
<div class="panel-body">
<canvas id="score"></canvas>
</div>
</div>
<div class="high-score-panel">
<div class="panel-header">
最高得分
</div>
<div class="panel-body">
<canvas id="highscore"></canvas>
</div>
</div>
</div>
<div class="modal-dialog">
<div class="modal-body">
<label for="ck-sound">启用声音</label>
<input type="checkbox" id="ck-sound">
<br>
<br>
<button id="btn-dialog-close">关闭</button>
</div>
</div>
<script src="vendor/howler.min.js"></script>
<script src="js/config.js"></script>
<script src="js/ResourceManager.js"></script>
<script src="js/Canvas.js"></script>
<script src="js/Keyboard.js"></script>
<script src="js/Score.js"></script>
<script src="js/Timer.js"></script>
<script src="js/Level.js"></script>
<script src="js/NextShape.js"></script>
<script src="js/HighScore.js"></script>
<script src="js/Block.js"></script>
<script src="js/Shape.js"></script>
<script src="js/Board.js"></script>
<script src="js/Tetris.js"></script>
<script src="js/app.js"></script>
</body> </html>
对应的css样式:
*{
box-sizing: border-box;
}
html,body,div{
margin: 0;
padding: 0;
} body{
background: #000;
color: #fff;
} .game-container, .start-container{
position: relative;
box-sizing: content-box;
height: 600px;
width: 590px;
margin: 0 auto;
margin-top: 50px;
border: 1px solid green;
} .game-container{
display: none;
} .start-container{
background: url(../images/bg_start.png);
background-size: cover;
width: 390px;
padding-top: 280px;
box-sizing: border-box;
} .start-container p{
text-align: center;
margin-top: 40px;
} .start-container p button{
width: 200px;
height: 50px;
line-height: 50px;
font-size: 20px;
font-family: 微软雅黑;
border: 0;
border-radius: 50%;
outline: none;
cursor: pointer;
background: lightblue;
} .start-container p button:hover{
background: lightcoral;
} .game-main-panel{
position: absolute;
left: 100px;
top: 0;
width: 390px;
height: 600px;
border-left: 1px solid green;
border-right: 1px solid green;
}
.timer-panel{
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
}
.help-panel{
position: absolute;
top: 150px;
left: 0;
width: 100px;
}
.level-panel{
position: absolute;
left: 0;
bottom: 0;
width: 100px;
height: 100px;
}
.next-panel{
position: absolute;
right: 0;
top: 0;
width: 100px;
height: 100px;
}
.setting-panel{
position: absolute;
top: 150px;
right: 0;
width: 100px;
}
.score-panel{
position: absolute;
right: 0;
bottom: 120px;
width: 100px;
height: 100px;
}
.high-score-panel{
position: absolute;
right: 0;
bottom: 0;
width: 100px;
height: 100px;
}
.panel-header{
height: 30px;
line-height: 30px;
padding-left: 5px;
font-size: 18px;
color:#fff;
background: lightsalmon;
}
.panel-body{
text-align: center;
line-height: 70px;
}
.help-panel .panel-body,
.setting-panel .panel-body{
line-height: normal;
}
.timer-panel, .next-panel, .score-panel{
border-bottom: 1px solid green;
} .modal-dialog{
display: none;
} .modal-dialog .modal-body{
position: fixed;
height: 300px;
width: 390px;
top: 50%;
margin-top: -150px;
left: 50%;
margin-left: -195px;
background: #000;
z-index: 100;
text-align: center;
} .modal-dialog::after{
content: '';
position: fixed;
top:0;
right: 0;
bottom: 0;
left: 0;
background: rgba(255,255,255,0.3);
}
H5实现俄罗斯方块(一)的更多相关文章
- H5版俄罗斯方块(2)---游戏的基本框架和实现
前言: 上文中谈到了H5版俄罗斯方块的需求和目标, 这次要实现一个可玩的版本. 但饭要一口一口吃, 很多东西并非一蹴而就. 本文将简单实现一个可玩的俄罗斯方块版本. 下一步会引入AI, 最终采用coc ...
- H5版俄罗斯方块(3)---游戏的AI算法
前言: 算是"long long ago"的事了, 某著名互联网公司在我校举行了一次"lengend code"的比赛, 其中有一题就是"智能俄罗斯方 ...
- H5版俄罗斯方块(1)---需求分析和目标创新
前言: 俄罗斯方块和五子棋一样, 规则简单, 上手容易. 几乎每个开发者, 都会在其青春年华时, 签下"xx到此一游". 犹记得大一老师在布置大程作业的时候提过: "什么 ...
- H5版俄罗斯方块(4)---火拼对战的雏形
前言: 勿忘初心, 本系列的目标是实现一款类似QQ"火拼系列"的人机对战版俄罗斯方块. 在完成了基本游戏框架和AI的算法探索后, 让我们来尝试一下人机大战雏形编写. 本系列的文章链 ...
- H5实现俄罗斯方块(四)
图片加载的js: (function (window) { 'use strict'; //定义缓存的Map对象 var cacheMap = new Map(); //资源的总数量 var reso ...
- H5实现俄罗斯方块(三)
最高分的面板: (function (window) { 'use strict'; function HighScore() { this.canvas = new Canvas('highscor ...
- H5版俄罗斯方块(5)---需求演进和产品迭代
前言: 产品的形态是不断迭代的, 从粗糙到精致, 从简易到立体. 有了最初的技术积累和时间思考后, 终于明确了该游戏的方向. 我想说的是: 技术不是重点, 产品/用户体验才是核心议题. 结合朋友的游戏 ...
- H5实现俄罗斯方块(二)
对应的js 1.封装操作dom的js: (function (document) { //游戏的实例 var gameInst; /**封装一个返回原型的DOM对象 */ function DomOb ...
- 自己写了个H5版本的俄罗斯方块
在实习公司做完项目后,实在无聊.就用H5写了几个游戏出来玩一下.从简单的做起,就搞了个经典的俄罗斯方块游戏. 先上效果: 上面的数字是得分,游戏没有考虑兼容性,只在chrome上测试过,不过大部分现代 ...
随机推荐
- la----3695 City Game(最大子矩阵)
Bob is a strategy game programming specialist. In his new city building game the gaming environment ...
- HDU 1171(01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- CSS3 Media Queries
Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码: <link href="css/reset.css" rel= ...
- gitlab配置邮件通知
配置用户提交评论.添加issue等的邮件通知: Gitlab邮件提醒方便跟踪项目进度,在这里介绍两种方式,一种是用系统的sendmail发送邮件,另一种是GMAIL的stmp来发送邮件 第一种 用系统 ...
- 源代码解读Cas实现单点登出(single sign out)功能实现原理
关于Cas实现单点登入(single sing on)功能的文章在网上介绍的比较多,想必大家多多少少都已经有所了解,在此就不再做具体介绍.如果不清楚的,那只能等我把single sign on这块整理 ...
- BroadcastReceiver接收系统广播消息
Android常用的广播Action常量: ACTION_TIME_CHANGED:系统时间被改变. ACTION_DATE_CHANGED:系统日期被改变. ACTION_TIMEZONE_CHAN ...
- MySQL使用随笔
001 查看版本 mysql --version mysql > select version(); mysql > status; 002 新建MySQL用户.授权 insert int ...
- ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置
核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...
- 使用 JavaScript 修改浏览器 URL 地址栏
现在的浏览器里,有一个十分有趣的功能,你可以在不刷新页面的情况下修改浏览器URL;在浏览过程中.你可以将浏览历史储存起来,当你在浏览器点击后退按钮的时候,你可以冲浏览历史上获得回退的信息,这听起来并不 ...
- C# 子窗体点击按钮产生的新子窗体放在父窗体里
情景展示: 父窗体Form1,左边是按钮,右边是panel(放置子窗体) 父窗体点击按钮,在panel显示第一个子窗体AA, AA有个按钮,点击按钮,是第二个子窗体ZZ, 怎样将AA的子窗体ZZ也显示 ...