HTML5最新经典俄罗斯方块游戏插件

简介: HTML5最新经典俄罗斯方块游戏插件

这是一款最新的经典 HTML5 俄罗斯方块游戏插件。该插件使用html5和Blockrain.js来制作,它具有使用简单、响应式、可定制、速度快、有积分记录和自动游戏的特点。

tx001411.png

预览 下载

基本使用方法
可以使用任何一个元素来作为游戏窗口(一个div、article 或 figure 等等都可以),并确保通过CSS设置了该元素的宽度和高度。可以为元素设置任何的class,demo中设置为.game。

<div class="game" style="width:250px; height:500px;"></div>
AI 代码解读

然后在页面中引入 jQuery和blockrain.jquery.js文件。接下可以通过$('.game').blockrain()方法调用俄罗斯方块插件。建议添加blockrain.css到页面中,它提供了一些俄罗斯方块界面的样式,当然你也可以自定义界面样式。

<!-- The stylesheet should go in the <head>, or be included in your CSS -->
<link rel="stylesheet" src="blockrain.css">

<!-- jQuery and Blockrain.js -->
<script src="jquery.js"></script>
<script src="blockrain.js"></script>
<script>
    $('.game').blockrain();
</script>
AI 代码解读

你还可以使俄罗斯方块游戏连续自动游戏。

$('.game').blockrain({
    autoplay: true, autoplayRestart: true });
AI 代码解读

游戏主题

Blockrain 有许多“即插即用”的主题。你也可以在BlockrainThemes中添加自定义的主题。你可以对主题进行多项设置,甚至可以定制纹理(基于Base64编码)。

{
   
  background: '#000000', // The main background color.
  backgroundGrid: '#101010', // You can draw a small background grid as well.
  primary: null, // Color of the falling blocks. This overrides the standard block color.
  secondary: null, // Color of the placed blocks. This overrides the standard block color.
  stroke: null, // Border color for the blocks.
  innerStroke: null, // A small border inside the blocks to give some texture.

  // The following are the colors of each piece
  blocks: {
   
    line:     '#fa1e1e',
    square:   '#f1fa1e',
    arrow:    '#d838cb',
    rightHook:'#f5821f',
    leftHook: '#42c6f0',
    rightZag: '#4bd838',
    leftZag:  '#fa1e1e'
  }
}
AI 代码解读

下面是一个自定义纹理的retro主题(vim)的例子:

{
   
  background: '#000000',
  backgroundGrid: 'data:image/png;base64,iVBORw0KGgoAAA{AND SO ON}',
  primary: '#C2FFAE',
  secondary: '#C2FFAE',
  stroke: '#000000',
  strokeWidth: 3,
  innerStroke: null
}
AI 代码解读

可用的主题有:

  • candy
  • modern
  • retro
  • vim
  • monochrome
  • gameboy
  • aerolab

你可以通过修改这些主题来制作更好的效果。

可用参数
Blockrain有很多参数可以帮助定制俄罗斯方块游戏:

{
   
  autoplay: false, // Let a bot play the game
  autoplayRestart: true, // Restart the game automatically once a bot loses
  showFieldOnStart: true, // Show a bunch of random blocks on the start screen (it looks nice)
  theme: null, // The theme name or a theme object
  blockWidth: 10, // How many blocks wide the field is (The standard is 10 blocks)
  autoBlockWidth: false, // The blockWidth is dinamically calculated based on the autoBlockSize. Disabled blockWidth. Useful for responsive backgrounds
  autoBlockSize: 24, // The max size of a block for autowidth mode
  difficulty: 'normal', // Difficulty (normal|nice|evil).
  speed: 20, // The speed of the game. The higher, the faster the pieces go.

  // Copy
  playText: 'Let\'s play some Tetris',
  playButtonText: 'Play',
  gameOverText: 'Game Over',
  restartButtonText: 'Play Again',
  scoreText: 'Score',

  // Basic Callbacks
  onStart: function(){
   },
  onRestart: function(){
   },
  onGameOver: function(score){
   },

  // When a line is made. Returns the number of lines, score assigned and total score
  onLine: function(lines, scoreIncrement, score){
   }
}
AI 代码解读

方法

Blockrain有很多实用的控制游戏的方法。$game 代表你的游戏对象选择器(例如:js $('.game') )

// Start the game
$game.blockrain('start');

// Restart the game
$game.blockrain('restart');

// Trigger a game over
$game.blockrain('gameover');
// Pause
$game.blockrain('pause');

// Resume
$game.blockrain('resume');
// Enable or Disable Autoplay (true|false)
$game.blockrain('autoplay', true);
// Enable or Disable Controls (true|false)
$game.blockrain('controls', true);
// Change the theme. 

// You can provide a theme name...
$game.blockrain('theme', 'vim');

// Or a theme object. **Check out src/blockrain.jquery.themes.js** for examples.
$game.blockrain('theme', {
   
  background: '#ffffff',
  primary: '#ff7b00',
  secondary: '#000000'
});
// Return the current score
var score = $game.blockrain('score');
AI 代码解读
目录
打赏
0
9
10
0
64
分享
相关文章
html5掷骰子跳棋游戏源码
html5掷骰子跳棋游戏源码
419 1
html5掷骰子跳棋游戏源码
HTML 插件详解
HTML中的插件如Flash、Java applets和ActiveX控件曾广泛用于扩展网页功能,但因安全性问题和跨浏览器兼容性不佳而逐渐被淘汰。现代替代方案包括HTML5的`&lt;audio&gt;`、`&lt;video&gt;`、`&lt;canvas&gt;`和SVG等,以及WebAssembly和各种JavaScript API(如WebRTC和WebGL),这些新技术不仅提升了网页性能和安全性,还改善了用户体验。建议开发者优先采用HTML5和相关API。
(html在线预览cad图纸插件)网页CAD绘制条形码、二维码的教程
本文介绍了如何在mxcad中绘制条形码和二维码。对于条形码,首先根据应用场景选择合适的编码标准(如CODE39、EAN13等),通过编码规则将数据转换为二进制,并利用`McDbHatch`绘制条和空的组合,同时支持自定义实体及属性管理。 对于二维码,因其能存储更多信息且具备更强纠错能力,采用开源库QRCode.js进行编码处理,再通过`McDbHatch`绘制黑白矩阵,同样封装成自定义实体以便管理和扩展。文中还给出了完整的绘制流程与效果展示,包括创建二维码对象、设置参数、调用绘制方法以及最终的效果图。整个过程体现了灵活运用API与第三方库来实现复杂图形绘制的能力。
|
3月前
HTML在线扫雷游戏网页源码
HTML在线扫雷游戏网页源码是一款基于HTML+CSS+JavaScript开发的在线扫雷小游戏单页源码,为用户提供了一个无需安装即可在浏览器中直接玩的扫雷游戏。该游戏的源码不仅包含了完整的游戏逻辑,还具备丰富的界面设计和用户交互功能,使得玩家能够轻松上手并享受扫雷带来的乐趣。
163 22
|
4月前
利用html2canvas插件自定义生成名片信息并保存图片
这是一个利用html2canvas插件自定义生成名片信息并保存图片,自定义上传头像,自定义输入个人信息内容,自定义图片名称,并将生成的图片保存到本地
94 1
利用html2canvas插件自定义生成名片信息并保存图片
HTML5 拖放在游戏中的应用
HTML5的拖放功能在游戏开发中广泛应用,尤其在创建交互式网页游戏时。它支持多种场景,如拖动角色或物品、选择和装备物品、拼图或配对游戏以及自定义界面布局。通过简单的HTML和JavaScript代码,可实现流畅的拖放交互,并提供视觉反馈,增强用户体验。此外,还需考虑设备兼容性和数据管理,确保游戏在不同设备和浏览器上都能良好运行。总之,HTML5拖放功能使网页游戏更生动有趣。
|
8月前
WordPress插件介绍页源码单页Html源码
WordPress插件介绍页源码单页Html源码
113 2
WordPress插件介绍页源码单页Html源码
文本,Vue实现打印的方式,打印机的种类有多少,浏览器打印html,右键,2打印插件,3指令打印,vue-print-nb
文本,Vue实现打印的方式,打印机的种类有多少,浏览器打印html,右键,2打印插件,3指令打印,vue-print-nb
|
9月前
切方块游戏 HTML5+jQuery【附源码】
切方块游戏 HTML5+jQuery【附源码】
77 0