All Projects → timmyLan → tetris

timmyLan / tetris

Licence: MIT License
轻松10步用es6写出俄罗斯方块🎉

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Labels

Projects that are alternatives of or similar to tetris

tetran
Tetris-style game written in FORTRAN-95
Stars: ✭ 19 (-36.67%)
Mutual labels:  tetris
tetris-game
⭐ A simple tetris game developed with freecodecamp. http://tetris-game.surge.sh/
Stars: ✭ 15 (-50%)
Mutual labels:  tetris
Tetris
A (incomplete) terminal Tetris. Written in Haskell.
Stars: ✭ 26 (-13.33%)
Mutual labels:  tetris
combatris
A "perfect" implementation of an old classic
Stars: ✭ 20 (-33.33%)
Mutual labels:  tetris
Retrogamer-Compose
Retro games implemented using Jetpack Compose
Stars: ✭ 113 (+276.67%)
Mutual labels:  tetris
playing-mario-with-deep-reinforcement-learning
An implementation of (Double/Dueling) Deep-Q Learning to play Super Mario Bros.
Stars: ✭ 55 (+83.33%)
Mutual labels:  tetris
Tetris
Tetris game (Fork)
Stars: ✭ 21 (-30%)
Mutual labels:  tetris
tetris-ai
A Tetris AI written in JavaScript that uses a genetic algorithm
Stars: ✭ 22 (-26.67%)
Mutual labels:  tetris
solution-finder
Tetris: Find perfect clears, combos, T-spins
Stars: ✭ 76 (+153.33%)
Mutual labels:  tetris
nvim-tetris
Bringing emacs' greatest feature to neovim - Tetris!
Stars: ✭ 114 (+280%)
Mutual labels:  tetris
AWKTC
AWKTC is Workable Klutzy Time-wasting Command
Stars: ✭ 44 (+46.67%)
Mutual labels:  tetris
WpfTetris
MVVM based Tetris application sample on WPF
Stars: ✭ 24 (-20%)
Mutual labels:  tetris
mimstris
A falling block puzzle game created using React and Redux.
Stars: ✭ 129 (+330%)
Mutual labels:  tetris
TETRIS
俄罗斯方块demo
Stars: ✭ 15 (-50%)
Mutual labels:  tetris
Tetris AR
An AR Tetris (unity3d+vuforia)
Stars: ✭ 14 (-53.33%)
Mutual labels:  tetris
tetris-grid
◼️Lightweight and simple CSS grid
Stars: ✭ 16 (-46.67%)
Mutual labels:  tetris
PYTRIS
tetris made with pygame
Stars: ✭ 26 (-13.33%)
Mutual labels:  tetris
Tetris
☕️A tetris game written in Java, suitable for beginners to practice.
Stars: ✭ 22 (-26.67%)
Mutual labels:  tetris
fumen-for-mobile-ts
Tetris diagram editor for mobile
Stars: ✭ 14 (-53.33%)
Mutual labels:  tetris
CppTetris
Tetris made within an hour
Stars: ✭ 104 (+246.67%)
Mutual labels:  tetris

目的

  • 为熟悉es6增加趣味性
  • 提高开发动力
  • balabalabala....编不下去了

注意

俄罗斯方块用es6写,无经过babel转es5,示例请用支持es6的chrome
俄罗斯方块用es6写,无经过babel转es5,示例请用支持es6的chrome.
俄罗斯方块用es6写,无经过babel转es5,示例请用支持es6的chrome.

##实现

第零步:构思俄罗斯方块的形状&规则

  • 形状 俄罗斯方块 每个方块都可看作一个二维数组,需要填充的部分为1,留空为0.
  • 规则
    • 上方向键 ===> 方块顺时针形变
    • 左方向键 ===> 方块向左移动
    • 右方向键 ===> 方块向右移动
    • 空格键 ===> 方块加速下落
    • 方块掉落自动掉落
    • 方块集齐满一排消除
    • 方块到顶部视为失败

第一步:让方块出现&动起来

在`document.body`添加一个方块,并绑定`document.onkeydown`,让方块跟随键盘方向键动起来.

第二步:让方块在规定画布上动起来

在`document.body`添加一个画布,每次方块运动前判断对应方向能否移动

边界设定

第三步:根据数组矩阵画出俄罗斯方块

  • 根据数组矩阵判断值为1的下标,利用得到的下标对各个小方块进行定位,从而得出一整块俄罗斯方块.
  • 判断能否移动则根据绘制出的俄罗斯方块取最值,根据最值比对边界即可. 偏移量最值比较
  • 矩阵判断&最值与边界对比js
  • 本步骤示例

第四步:俄罗斯方块形变

第五步:俄罗斯方块自由下落

第六步:俄罗斯方块消除

  • 每次俄罗斯方块下落结束时,判断每一行小方块个数
  • 方块个数等于画布宽度/方块,则取出该行方块集合并从document.body消除
  • 消除后将高度高于该消除行的方块掉落一个方块高度 方块消除
  • 消除行js
  • 本步骤示例

第七步:加速下落

  • 方块在按空格键的时候,下落2个单位的BLOCK_SIZE,也就是40px
  • 需要在canMove函数中添加displacement(位移)参数标识方块下落的位移量
  • 判断方块是否到达最高位置,需要加上位移量的距离
  • 加速下落js
  • 本步骤示例

第八步:判断游戏GG

第九步:增加随机下落方块

第十步:增加游戏信息

传送门

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].