使用 vue3 来实现俄罗斯方块

Related tags

Vue.js tetris-vue3
Overview

Tetris-vue3

使用 vue3 实现俄罗斯方块

单机版本实现 联机版本实现

实现原理

采用了 Functional Core, Imperative Shell 模式来实现

提高了可测试性

业务核心逻辑和视图逻辑拆分

可以移植到任意 UI 库

todo

  • 游戏重来

收获

  • 应用程序从 0 到 1 的全过程

  • 用户故事来描述你的程序需求点

  • tasking 的方式来管理你的开发进度

  • vue3 最新的 setup script 语法糖的应用

  • 使用单元测试提高开发效率

  • 设计模式的应用

    • 策略模式

    • 工厂模式

  • 重构技巧 (写出好代码 )

Tasking

单机

  • 用户进入游戏的时候可以看到游戏开始页面

  • 用户点击 startGame 可以开始游戏

  • 用户在开始游戏的时候可以看到掉落的方块

  • 方块掉落到最下面边界的时候就会停下来

  • 方块掉落到其他方块的时候也会停下来

  • 方块掉落的停下来的时候就会有新的方块掉下来

    • 新的方块是随机产生的
  • 用户可以操作方向键让正在掉落的方块移动,但是不会超过边界

    • 左方向键向左

    • 右方向键向右

  • 用户用方块凑满了一行的话,会消除当前凑满的行,并且会看到上面的行会掉落下来

  • 当方块超出最上面边界的时候,用户会看到游戏结束的提示

  • 用户可以操作空格键来旋转正在掉落的方块?

  • 用户可以操作方向键下,来加速正在掉落的方块掉落的速度?

联机

  • 用户可以看到对手的游戏界面

  • 用户通过对手的游戏界面看到的掉落的方块需要和对手正在掉落的方块一样

  • 用户可以看到对手的所有游戏操作

    方块的向下移动

    方块的向左移动

    方块的向右移动

    方块旋转

  • 用户消行了,对手会增加一行(这个行不可以被消除)

  • 用户游戏结束了,对手会收到游戏获胜的提示

双人对战

通过 websocket 来同步玩家的动作,来实现双人对战模式

同步的动作

  • gameOver (游戏结束)

    • to other
      • gameWon
  • eliminateLine (消除行)

    • to self

      • syncAddLine (同步 dival 视图)
    • to other

      • addLine (让其他玩家加行)
  • moveBoxToDown (向下移动 box)

    • to other
      • moveBoxToDown
  • moveBoxToLeft (向左移动 box)

    • to other
      • moveBoxToLeft
  • moveBoxToRight (向右移动 box)

    • to other
      • moveBoxToRight
  • rotateBox (旋转 box)

    • to other
      • rotateBox
  • createBox (创建 box)

    • to other
      • createBox
You might also like...

🎉🎉使用Vite + Vue3 + TypeScript + Element-plus + Mock开发的后台管理系统🎉🎉

Vite-Vue-Admin 介绍 Cli 配置 vue3.X vuex@4 vue-router@4 vite@2 typescript mock 内置 element-plus 二开封装 upload-file (文件上传,支持指定文件格式,文件大小) powerful-table (多功能表格

Dec 17, 2022

A simple, customization star rating component for your vue3 projects

A simple, customization star rating component for your vue3 projects

vue3-star-ratings A simple, customizable component for star ratings Documentation Features Uses svg for the stars, so it can scale without quality los

Oct 7, 2022

vite2.7 + vue3.2 + ts + eslint + prettier

vite-vue-template 一个vue3项目模板 主要依赖 vite 2.7.2 vue 3.2.25 typescript eslint prettier 准备 Windows系统下将编辑器 行尾(eol) 设置为 LF('\n') vscode配置: { "files.eol":

Sep 13, 2022

⏳ vue3 + electron + ts + vite = mini template

v3-electron 🥳 Electron16 + Vue3 + Vite2 运行项目 # enter the project directory cd v3-electron # install dependency yarn # develop yarn dev # build exe

Nov 11, 2022

A text replacer component for vue3.

A text replacer component for Vue 3. Requires Vue 3 as peer-dependency. Installation Install it from npm. npm install vue3-replacer pnpm add vue3-rep

Feb 19, 2022

vite+vue3.2+setup+elementPlus+eslint+js+stylelint

前期准备工作,npm包和vscode配置 !!!很重要,关乎整个Vue3开发阶段的代码提示 Volar使用 使用Vue3开发需要禁用vscode插件Vetur 然后安装 Volar(Vue Language Features),这样Vue3代码提示即使是使用js开发也非常友好 如果volar没有任何

Feb 8, 2022

vue3 + vite + typescript template

Vue 3 + Typescript + Vite This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 script setu

Aug 1, 2022

A simple Vue3, Nuxt3 and Tailwind3 Starter Template

Nuxt 3 + Tailwind CSS 3 Starter This is a minimal starter template for Nuxt 3 projects with Tailwind CSS 3. It includes a simple template pages/index.

Feb 11, 2022

A API documentation generator for Vue3 single file component.

doc-vue A API documentation generator for Vue3 single file component. Table of Contents Installation Write API Description Command Line Usage Programm

Oct 20, 2022

Vue3 SSR prod-ready multi-languages template

Vue3 SSR prod-ready multi-languages template

vue3-ssr-template About This template is a prod ready starter for your Vue SSR application where you can do what you want at any level, client or serv

Mar 11, 2022
Owner
阿崔cxr
积极主动 - 以终为始 - 要事第一
阿崔cxr
🎉🎉使用Vite + Vue3 + TypeScript + Element-plus + Mock开发的后台管理系统🎉🎉

Vite-Vue-Admin 介绍 Cli 配置 vue3.X vuex@4 vue-router@4 vite@2 typescript mock 内置 element-plus 二开封装 upload-file (文件上传,支持指定文件格式,文件大小) powerful-table (多功能表格

PengXiaoShuai 103 Dec 17, 2022
A simple, customization star rating component for your vue3 projects

vue3-star-ratings A simple, customizable component for star ratings Documentation Features Uses svg for the stars, so it can scale without quality los

Abiodun Olunu 14 Oct 7, 2022
vite2.7 + vue3.2 + ts + eslint + prettier

vite-vue-template 一个vue3项目模板 主要依赖 vite 2.7.2 vue 3.2.25 typescript eslint prettier 准备 Windows系统下将编辑器 行尾(eol) 设置为 LF('\n') vscode配置: { "files.eol":

shaaaaaaaa 5 Sep 13, 2022
⏳ vue3 + electron + ts + vite = mini template

v3-electron ?? Electron16 + Vue3 + Vite2 运行项目 # enter the project directory cd v3-electron # install dependency yarn # develop yarn dev # build exe

UNPany 8 Nov 11, 2022
A text replacer component for vue3.

A text replacer component for Vue 3. Requires Vue 3 as peer-dependency. Installation Install it from npm. npm install vue3-replacer pnpm add vue3-rep

Kadir Yazıcı 4 Feb 19, 2022
vite+vue3.2+setup+elementPlus+eslint+js+stylelint

前期准备工作,npm包和vscode配置 !!!很重要,关乎整个Vue3开发阶段的代码提示 Volar使用 使用Vue3开发需要禁用vscode插件Vetur 然后安装 Volar(Vue Language Features),这样Vue3代码提示即使是使用js开发也非常友好 如果volar没有任何

null 2 Feb 8, 2022
vue3 + vite + typescript template

Vue 3 + Typescript + Vite This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 <script setu

BrowLi 6 Aug 1, 2022
A API documentation generator for Vue3 single file component.

doc-vue A API documentation generator for Vue3 single file component. Table of Contents Installation Write API Description Command Line Usage Programm

annnhan 36 Oct 20, 2022
Vue3 SSR prod-ready multi-languages template

vue3-ssr-template About This template is a prod ready starter for your Vue SSR application where you can do what you want at any level, client or serv

null 9 Mar 11, 2022
基于vue3.0-ts-Element集成的简洁/实用后台模板!《带预览地址》vue-admin;vue+admin;vue-element;vue+element;vue后台管理;vue3.0-admin;vue3.0-element。

一、基于vue3.0+ts+Element通用后台admin模板 二、在线预览地址:http://admin.yknba.cn/ 三、下载使用: 1、克隆代码 通过git将代码克隆到本地;或者使用下载安装包模式进行下载。 2、进入目录 进入项目的根目录:vue3.0-ts-admin 3、安装依

null 64 Dec 16, 2022