diff --git a/.github/ISSUE_TEMPLATE/work-scene.md b/.github/ISSUE_TEMPLATE/work-scene.md
deleted file mode 100644
index d9c84cb..0000000
--- a/.github/ISSUE_TEMPLATE/work-scene.md
+++ /dev/null
@@ -1,13 +0,0 @@
----
-name: 工作场景
-about: 工作场景常见问题汇总
----
-
-## 问题描述
-简短的描述问题
-
-## 解决方案
-列出具体的解决方案(不用解释原理,如果有多种要标明优缺点)
-
-## 参考链接
-列出方案的具体原理
\ No newline at end of file
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
deleted file mode 100644
index f11f7af..0000000
--- a/.github/workflows/main.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-name: CI
-
-on: push
-
-jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
-
- - uses: actions/setup-node@v3.3.0
- with:
- node-version: '16'
-
- - uses: pnpm/action-setup@v2.2.2
- with:
- version: 6.0.2
-
- - name: Run a multi-line script
- run: |
- pnpm install
- pnpm run build:all
-
- - name: Deploy
- if: success()
- uses: crazy-max/ghaction-github-pages@v3.0.0
- with:
- build_dir: docs
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 70d36b3..f11ba8f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,3 @@
*.pptx
*.ppt
-test.*
-.vscode/
-node_modules/
-note.*
-.vscode/
-*.log
-docs/
\ No newline at end of file
+test.*
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..aef8443
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "liveServer.settings.port": 5501
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 022c04f..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 - 2022 hans000
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7fc3e23
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+# 前端的一些小案例
+
+## game案例
+- [拼图游戏](https://github.com/haima16/JavaScript/tree/master/game/puzzle/test)
+- [扫雷游戏](https://github.com/haima16/JavaScript/blob/master/game/%E6%89%AB%E9%9B%B7/index.1.html)
+
+## canvas案例
+- 添加了clock案例
+- 添加了飞机大战游戏(canvas/plane)
+
+
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane-2/assets/plane.gif b/assets/plane.gif
similarity index 100%
rename from packages/game-vanilla/src/plane-2/assets/plane.gif
rename to assets/plane.gif
diff --git a/packages/test-vanilla/src/real-clock/assets/01.gif b/canvas/clock/assets/01.gif
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/01.gif
rename to canvas/clock/assets/01.gif
diff --git a/packages/test-vanilla/src/real-clock/assets/1562655110920.png b/canvas/clock/assets/1562655110920.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1562655110920.png
rename to canvas/clock/assets/1562655110920.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1562655288739.png b/canvas/clock/assets/1562655288739.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1562655288739.png
rename to canvas/clock/assets/1562655288739.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563160983379.png b/canvas/clock/assets/1563160983379.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563160983379.png
rename to canvas/clock/assets/1563160983379.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161557373.png b/canvas/clock/assets/1563161557373.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161557373.png
rename to canvas/clock/assets/1563161557373.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161728608.png b/canvas/clock/assets/1563161728608.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161728608.png
rename to canvas/clock/assets/1563161728608.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161743001.png b/canvas/clock/assets/1563161743001.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161743001.png
rename to canvas/clock/assets/1563161743001.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563162034809.png b/canvas/clock/assets/1563162034809.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563162034809.png
rename to canvas/clock/assets/1563162034809.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563162284953.png b/canvas/clock/assets/1563162284953.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563162284953.png
rename to canvas/clock/assets/1563162284953.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563163445573.png b/canvas/clock/assets/1563163445573.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563163445573.png
rename to canvas/clock/assets/1563163445573.png
diff --git a/packages/test-vanilla/src/real-clock/index.html b/canvas/clock/index.html
similarity index 100%
rename from packages/test-vanilla/src/real-clock/index.html
rename to canvas/clock/index.html
diff --git a/packages/test-vanilla/src/real-clock/js/scene.js b/canvas/clock/js/scene.js
similarity index 100%
rename from packages/test-vanilla/src/real-clock/js/scene.js
rename to canvas/clock/js/scene.js
diff --git a/packages/test-vanilla/src/real-clock/readme.md b/canvas/clock/readme.md
similarity index 100%
rename from packages/test-vanilla/src/real-clock/readme.md
rename to canvas/clock/readme.md
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561965869970.png b/canvas/digit-clock/assets/1561965869970.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561965869970.png
rename to canvas/digit-clock/assets/1561965869970.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561967339261.png b/canvas/digit-clock/assets/1561967339261.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561967339261.png
rename to canvas/digit-clock/assets/1561967339261.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561968289250.png b/canvas/digit-clock/assets/1561968289250.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561968289250.png
rename to canvas/digit-clock/assets/1561968289250.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1563187094573.png b/canvas/digit-clock/assets/1563187094573.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1563187094573.png
rename to canvas/digit-clock/assets/1563187094573.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1563188102881.png b/canvas/digit-clock/assets/1563188102881.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1563188102881.png
rename to canvas/digit-clock/assets/1563188102881.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-15-41.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 15-15-41.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-15-41.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 15-15-41.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-57-38.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 15-57-38.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-57-38.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 15-57-38.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 16-05-50.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 16-05-50.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 16-05-50.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 16-05-50.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-07-01 14-58-10.gif b/canvas/digit-clock/assets/Honeycam 2019-07-01 14-58-10.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-07-01 14-58-10.gif
rename to canvas/digit-clock/assets/Honeycam 2019-07-01 14-58-10.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/digit-clock.gif b/canvas/digit-clock/assets/digit-clock.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/digit-clock.gif
rename to canvas/digit-clock/assets/digit-clock.gif
diff --git a/packages/test-vanilla/src/digital-clock/convert.html b/canvas/digit-clock/convert.html
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/convert.html
rename to canvas/digit-clock/convert.html
diff --git a/packages/test-vanilla/src/digital-clock/index.html b/canvas/digit-clock/index.html
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/index.html
rename to canvas/digit-clock/index.html
diff --git a/packages/test-vanilla/src/digital-clock/js/ball.js b/canvas/digit-clock/js/ball.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/ball.js
rename to canvas/digit-clock/js/ball.js
diff --git a/packages/test-vanilla/src/digital-clock/js/chunk.js b/canvas/digit-clock/js/chunk.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/chunk.js
rename to canvas/digit-clock/js/chunk.js
diff --git a/packages/test-vanilla/src/digital-clock/js/scene.js b/canvas/digit-clock/js/scene.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/scene.js
rename to canvas/digit-clock/js/scene.js
diff --git a/packages/test-vanilla/src/digital-clock/js/tile.js b/canvas/digit-clock/js/tile.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/tile.js
rename to canvas/digit-clock/js/tile.js
diff --git a/packages/test-vanilla/src/digital-clock/readme.md b/canvas/digit-clock/readme.md
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/readme.md
rename to canvas/digit-clock/readme.md
diff --git "a/packages/test-vanilla/src/digital-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html" "b/canvas/digit-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
similarity index 100%
rename from "packages/test-vanilla/src/digital-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
rename to "canvas/digit-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
diff --git a/packages/game-vanilla/src/plane-2/assets/1563245324770.png b/canvas/plane/assets/1563245324770.png
similarity index 100%
rename from packages/game-vanilla/src/plane-2/assets/1563245324770.png
rename to canvas/plane/assets/1563245324770.png
diff --git a/canvas/plane/assets/plane.gif b/canvas/plane/assets/plane.gif
new file mode 100644
index 0000000..59009f0
Binary files /dev/null and b/canvas/plane/assets/plane.gif differ
diff --git a/packages/game-vanilla/src/plane-2/index.html b/canvas/plane/index.html
similarity index 100%
rename from packages/game-vanilla/src/plane-2/index.html
rename to canvas/plane/index.html
diff --git a/packages/game-vanilla/src/plane-2/js/bullet.js b/canvas/plane/js/bullet.js
similarity index 96%
rename from packages/game-vanilla/src/plane-2/js/bullet.js
rename to canvas/plane/js/bullet.js
index aee384c..639e516 100644
--- a/packages/game-vanilla/src/plane-2/js/bullet.js
+++ b/canvas/plane/js/bullet.js
@@ -18,6 +18,8 @@ class Bullet extends Sprite {
}
createParticle() {
let p = new Particle();
+ p.sizeX = .5;
+ p.sizeY = .5;
p.vx = Math.random() - .5;
p.vy = Math.random() - .5;
p.color = `#${Math.random().toString(16).substr(3, 6)}`;
diff --git a/packages/game-vanilla/src/plane-2/js/enemy.js b/canvas/plane/js/enemy.js
similarity index 97%
rename from packages/game-vanilla/src/plane-2/js/enemy.js
rename to canvas/plane/js/enemy.js
index b9212d0..a2cdc9e 100644
--- a/packages/game-vanilla/src/plane-2/js/enemy.js
+++ b/canvas/plane/js/enemy.js
@@ -12,8 +12,8 @@ class Enemy extends Sprite {
this.bulletCB = 2000
this.attackTime = -1
this.boomConfig = new Map([
- [2, [1.2, 1, 0.5]],
- [3, [1.6, 1.6, 1]]
+ [2, [1.5, 1, 0.5]],
+ [3, [2, 2, 1]]
])
}
collide(bullets, w, h) {
diff --git a/packages/game-vanilla/src/plane-2/js/pane.js b/canvas/plane/js/pane.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/pane.js
rename to canvas/plane/js/pane.js
diff --git a/canvas/plane/js/particle.js b/canvas/plane/js/particle.js
new file mode 100644
index 0000000..0a8f42a
--- /dev/null
+++ b/canvas/plane/js/particle.js
@@ -0,0 +1,14 @@
+class Particle extends Sprite {
+ constructor() {
+ super();
+ this.life = 1000;
+ }
+ update() {
+ if (new Date() - this.birth > this.life) {
+ this.alive = false;
+ }
+ this.posX += this.vx;
+ this.posY += this.vy;
+ this.render();
+ }
+}
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane-2/js/player.js b/canvas/plane/js/player.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/player.js
rename to canvas/plane/js/player.js
diff --git a/packages/game-vanilla/src/plane-2/js/scene.js b/canvas/plane/js/scene.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/scene.js
rename to canvas/plane/js/scene.js
diff --git a/packages/game-vanilla/src/plane-2/js/sprite.js b/canvas/plane/js/sprite.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/sprite.js
rename to canvas/plane/js/sprite.js
diff --git a/packages/game-vanilla/src/plane-2/js/stage.js b/canvas/plane/js/stage.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/stage.js
rename to canvas/plane/js/stage.js
diff --git a/packages/game-vanilla/src/plane-2/readme.md b/canvas/plane/readme.md
similarity index 100%
rename from packages/game-vanilla/src/plane-2/readme.md
rename to canvas/plane/readme.md
diff --git a/desktop.ini b/desktop.ini
new file mode 100644
index 0000000..d957fd1
--- /dev/null
+++ b/desktop.ini
@@ -0,0 +1,4 @@
+[ViewState]
+Mode=
+Vid=
+FolderType=Generic
diff --git a/packages/game-vanilla/src/plane/index.html b/game/plane/index.html
similarity index 100%
rename from packages/game-vanilla/src/plane/index.html
rename to game/plane/index.html
diff --git a/packages/game-vanilla/src/plane/js/player.js b/game/plane/js/player.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/player.js
rename to game/plane/js/player.js
diff --git a/packages/game-vanilla/src/plane/js/scene.js b/game/plane/js/scene.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/scene.js
rename to game/plane/js/scene.js
diff --git a/packages/game-vanilla/src/plane/js/sprite.js b/game/plane/js/sprite.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/sprite.js
rename to game/plane/js/sprite.js
diff --git a/packages/code-list/readme.md b/game/plane/readme.md
similarity index 100%
rename from packages/code-list/readme.md
rename to game/plane/readme.md
diff --git a/game/puzzle/game.js b/game/puzzle/game.js
new file mode 100644
index 0000000..692b1fd
--- /dev/null
+++ b/game/puzzle/game.js
@@ -0,0 +1,185 @@
+(function () {
+ function Puzzle(data) {
+ this.scale = data.scale || 3;
+ this.container = data.container;
+ this.space = null;
+ }
+ Puzzle.prototype = {
+ init() {
+ let { scale } = this;
+ this.tiles = [];
+ this.map = Array.from({ length: scale* scale }, (e, i) => i);
+ this.val = this.map.toString();
+ while (1) {
+ this.shuffle(this.map);
+ if (this.valid(this.map)) {
+ break;
+ }
+ }
+ this.initDom();
+ this.bindEvent();
+ return this;
+ },
+ bindEvent() {
+ let self = this;
+ window.addEventListener('click', (e) => {
+ let tag = e.target;
+ if (tag !== self.space &&
+ tag.nodeName === 'LI' &&
+ tag.classList.contains('item')) {
+
+ if (tag.pos === self.space.pos + self.scale) {
+ self.moveUp();
+ } else if (tag.pos === self.space.pos - self.scale) {
+ self.moveDown();
+ } else if (tag.pos === self.space.pos - 1) {
+ self.moveRight();
+ } else if (tag.pos === self.space.pos + 1) {
+ self.moveLeft();
+ }
+ if (self.finished()) {
+ setTimeout(() => {
+ alert('ok');
+ }, 500);
+ }
+ }
+ })
+ window.addEventListener('keyup', (e) => {
+ let code = e.keyCode;
+ switch (code) {
+ // left
+ case 37:
+ self.moveLeft();
+ break;
+ // up
+ case 38:
+ self.moveUp();
+ break;
+ // right
+ case 39:
+ self.moveRight();
+ break;
+ // down
+ case 40:
+ self.moveDown();
+ break;
+ default:
+ break;
+ }
+ if (self.finished()) {
+ setTimeout(() => {
+ alert('ok');
+ }, 500);
+ }
+ })
+ },
+ finished() {
+ return this.map.toString() === this.val;
+ },
+ setOffset(node, pos) {
+ let { scale, container } = this;
+ let w = container.offsetWidth / scale;
+ node.style.transform = `translate(${pos % scale * w}px, ${(pos / scale | 0) * w}px)`;
+ },
+ initDom() {
+ let { map, scale, container } = this;
+ let self = this;
+ let f = document.createDocumentFragment();
+ let w = container.offsetWidth / scale;
+ map.forEach((e, i) => {
+ let li = document.createElement('LI');
+ li.classList.add('item');
+ li.data = e;
+ li.pos = i;
+ li.style.width = `${w}px`;
+ li.style.height = `${w}px`;
+ li.innerHTML = e;
+ self.setOffset(li, i);
+ let dx = (-e % scale | 0) * w;
+ let dy = (-e / scale | 0) * w;
+ li.style.backgroundPosition = `${dx}px ${dy}px`;
+ if (e === map.length - 1) {
+ li.style.backgroundImage = 'url()';
+ self.space = li;
+ }
+ self.tiles[e] = li;
+ f.appendChild(li);
+ })
+ container.appendChild(f);
+ },
+ /**
+ * @param {li node} tag
+ */
+ exchange(tag) {
+ this.setOffset(tag, this.space.pos);
+ this.setOffset(this.space, tag.pos);
+ this.setOffset(tag, this.space.pos);
+ this.setOffset(this.space, tag.pos);
+ [tag.pos, this.space.pos] = [this.space.pos, tag.pos];
+ [this.map[tag.pos], this.map[this.space.pos]] = [this.map[this.space.pos], this.map[tag.pos]];
+ },
+ moveDown() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if (pos - scale >= 0) {
+ this.exchange(tiles[map[pos - scale]]);
+ }
+ },
+ moveRight() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if (pos % scale !== 0) {
+ this.exchange(tiles[map[pos - 1]]);
+ }
+ },
+ moveUp() {
+ let { map, tiles, scale, space } = this;
+ let len = scale* scale;
+ let pos = space.pos;
+ if (pos + scale < len) {
+ this.exchange(tiles[map[pos + scale]]);
+ }
+ },
+ moveLeft() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if ((pos + 1) % scale !== 0) {
+ this.exchange(tiles[map[pos + 1]]);
+ }
+ },
+ shuffle(arr) {
+ let len = arr.length;
+ for (let i = 0; i < len; i++) {
+ let m = Math.random() * (len - i) | 0;
+ [arr[len - i - 1], arr[m]] = [arr[m], arr[len - i - 1]];
+ }
+ return arr;
+ },
+ valid(arr) {
+ let count = 0;
+ mergeSort(arr);
+ return count % 2 === 0;
+ function merge(left, right) {
+ let tmp = [];
+ while (left.length && right.length) {
+ if (left[0] > right[0]) {
+ tmp.push(left.shift());
+ count++;
+ } else {
+ tmp.push(right.shift());
+ }
+ }
+ return tmp.concat(left, right);
+ }
+ function mergeSort(arr) {
+ let len = arr.length;
+ if (len === 1) return arr;
+ let mid = len / 2 | 0;
+ let left = arr.slice(0, mid);
+ let right = arr.slice(mid);
+ return merge(mergeSort(left), mergeSort(right));
+ }
+ }
+ }
+ window.Puzzle = Puzzle;
+}())
\ No newline at end of file
diff --git a/game/puzzle/img/1.jpg b/game/puzzle/img/1.jpg
new file mode 100644
index 0000000..8537d81
Binary files /dev/null and b/game/puzzle/img/1.jpg differ
diff --git a/game/puzzle/index.html b/game/puzzle/index.html
new file mode 100644
index 0000000..e99daca
--- /dev/null
+++ b/game/puzzle/index.html
@@ -0,0 +1,84 @@
+
+
+
+
+ demo by hans
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/game/puzzle/test/\346\213\274\345\233\276.mp4" "b/game/puzzle/test/\346\213\274\345\233\276.mp4"
new file mode 100644
index 0000000..481bd06
Binary files /dev/null and "b/game/puzzle/test/\346\213\274\345\233\276.mp4" differ
diff --git a/packages/game-vanilla/src/boom/index.1.html "b/game/\346\211\253\351\233\267/index.1.html"
similarity index 100%
rename from packages/game-vanilla/src/boom/index.1.html
rename to "game/\346\211\253\351\233\267/index.1.html"
diff --git a/packages/game-vanilla/src/boom/index.html "b/game/\346\211\253\351\233\267/index.html"
similarity index 100%
rename from packages/game-vanilla/src/boom/index.html
rename to "game/\346\211\253\351\233\267/index.html"
diff --git a/package.json b/package.json
deleted file mode 100644
index 1b50e3d..0000000
--- a/package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "name": "javascript-note",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "clean:dependency": "rimraf node_modules && rimraf node_modules packages/*/node_modules",
- "dev:work-list-react": "pnpm run dev --filter \"work-list-react\"",
- "dev:test-react": "pnpm run dev --filter \"test-react\"",
- "build:all": "pnpm run build --filter \"!test-react\" --filter \"!code-list\" --filter \"!logic-list\""
- },
- "keywords": [],
- "author": "hans0000",
- "private": true,
- "license": "ISC",
- "devDependencies": {
- "ts-node": "^10.8.2",
- "typescript": "^4.7.4"
- }
-}
diff --git a/packages/code-list/.npmrc b/packages/code-list/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/code-list/src/ant-patch-matcher.ts b/packages/code-list/src/ant-patch-matcher.ts
deleted file mode 100644
index 992bfab..0000000
--- a/packages/code-list/src/ant-patch-matcher.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-
-function pathMatch(pattern: string, path: string) {
- let regStr = ''
- for (let i = 0; i < pattern.length; i++) {
- const ch = pattern[i]
- if ('^$+()[]{}'.includes(ch)) {
- continue
- }
- if (ch === '?') {
- regStr += '[\\S]'
- continue
- }
- if (ch === '*') {
- if (pattern[i + 1] === ch) {
- regStr += `${regStr.at(-1) === '/' ? '?' : '' }[\\S]{0,}`
- i++
- } else {
- regStr += '[^/]{0,}'
- }
- continue
- }
- if (ch === '.') {
- regStr += '\\' + ch
- continue
- }
- regStr += ch
- }
- return new RegExp(`^${regStr}$`).test(path)
-}
-
-// function assertTrue(value) { console.log(value === true) }
-// function assertFalse(value) { console.log(value === false) }
-
-// assertTrue(pathMatch("/foo/bar/**x{}x[]", "/foo/bar")) ;
-
-// assertTrue(pathMatch("https://jex.im/regulex/", "https://jex.im/regulex/"));
-// assertTrue(pathMatch("com/**/*.jsp", "com/abc.jsp"));
-// assertTrue(pathMatch("com/{ filename: \\w+ }.jsp", "com/abc.jsp2"));
-
-// // test exact matching
-// assertTrue(pathMatch("test", "test"));
-// assertTrue(pathMatch("/test", "/test"));
-// assertTrue(pathMatch("http://example.org", "http://example.org")); // SPR-14141
-// assertFalse(pathMatch("/test.jpg", "test.jpg"));
-// assertFalse(pathMatch("test", "/test"));
-// assertFalse(pathMatch("/test", "test"));
-// // test matching with ?'s
-// assertTrue(pathMatch("t?st", "test"));
-// assertTrue(pathMatch("??st", "test"));
-// assertTrue(pathMatch("tes?", "test"));
-// assertTrue(pathMatch("te??", "test"));
-// assertTrue(pathMatch("?es?", "test"));
-// assertFalse(pathMatch("tes?", "tes"));
-// assertFalse(pathMatch("tes?", "testt"));
-// assertFalse(pathMatch("tes?", "tsst"));
-// // test matching with *'s
-// assertFalse(pathMatch("*.*", "tsttst"));
-// assertTrue(pathMatch("*", "test"));
-// assertTrue(pathMatch("test*", "test"));
-// assertTrue(pathMatch("test*", "testTest"));
-// assertTrue(pathMatch("test/*", "test/Test"));
-// assertTrue(pathMatch("test/*", "test/t"));
-// assertTrue(pathMatch("test/*", "test/"));
-// assertTrue(pathMatch("*test*", "AnothertestTest"));
-// assertTrue(pathMatch("*test", "Anothertest"));
-// assertTrue(pathMatch("*.*", "test."));
-// assertTrue(pathMatch("*.*", "test.test"));
-// assertTrue(pathMatch("*.*", "test.test.test"));
-// assertTrue(pathMatch("test*aaa", "testblaaaa"));
-// assertFalse(pathMatch("test*", "tst"));
-// assertFalse(pathMatch("test*", "tsttest"));
-// assertFalse(pathMatch("test*", "test/"));
-// assertFalse(pathMatch("test*", "test/t"));
-// assertFalse(pathMatch("test/*", "test"));
-// assertFalse(pathMatch("*test*", "tsttst"));
-// assertFalse(pathMatch("*test", "tsttst"));
-// assertFalse(pathMatch("test*aaa", "test"));
-// assertFalse(pathMatch("test*aaa", "testblaaab"));
-// // test matching with ?'s and /'s
-// assertTrue(pathMatch("/?", "/a"));
-// assertTrue(pathMatch("/?/a", "/a/a"));
-// assertTrue(pathMatch("/a/?", "/a/b"));
-// assertTrue(pathMatch("/??/a", "/aa/a"));
-// assertTrue(pathMatch("/a/??", "/a/bb"));
-// assertTrue(pathMatch("/?", "/a"));
-// // test matching with **'s
-// assertTrue(pathMatch("/foo/bar/**", "/foo/bar")) ;
-// assertTrue(pathMatch("/**", "/testing/testing"));
-// assertTrue(pathMatch("/*/**", "/testing/testing"));
-// assertTrue(pathMatch("/**/*", "/testing/testing"));
-// assertTrue(pathMatch("/bla/**/bla", "/bla/testing/testing/bla"));
-// assertTrue(pathMatch("/bla/**/bla", "/bla/testing/testing/bla/bla"));
-// assertTrue(pathMatch("/**/test", "/bla/bla/test"));
-// assertTrue(pathMatch("/bla/**/**/bla", "/bla/bla/bla/bla/bla/bla"));
-// assertTrue(pathMatch("/bla*bla/test", "/blaXXXbla/test"));
-// assertTrue(pathMatch("/*bla/test", "/XXXbla/test"));
-// assertFalse(pathMatch("/bla*bla/test", "/blaXXXbl/test"));
-// assertFalse(pathMatch("/*bla/test", "XXXblab/test"));
-// assertFalse(pathMatch("/*bla/test", "XXXbl/test"));
-// assertFalse(pathMatch("/????", "/bala/bla"));
-// assertFalse(pathMatch("/**/*bla", "/bla/bla/bla/bbb"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/"));
-// assertTrue(pathMatch("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg"));
-// assertTrue(pathMatch("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing/"));
-// assertTrue(pathMatch("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing"));
-// assertTrue(pathMatch("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertFalse(pathMatch("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertFalse(pathMatch("/x/x/**/bla", "/x/x/x/"));
-// assertTrue(pathMatch("", ""));
-
diff --git a/packages/code-list/src/list-to-tree.js b/packages/code-list/src/list-to-tree.js
deleted file mode 100644
index df7ae76..0000000
--- a/packages/code-list/src/list-to-tree.js
+++ /dev/null
@@ -1,26 +0,0 @@
-
-const list = [
- { id: '1', nextId: '2' },
- { id: '2', nextId: '3' },
- { id: '3', nextId: '4' },
- { id: '4', nextId: '5' },
- { id: '5', nextId: '6' },
- { id: '6', nextId: null },
- // { id: '6', nextId: '1' },
-]
-
-
-function toTree(list) {
- const result = []
- const map = list.reduce((acc, item) => (acc[item.id] = item, acc), {})
- list.forEach(item => {
- const parent = map[item.nextId]
- if (parent) {
- const children = parent.children || (parent.children = [])
- children.push(item)
- } else {
- result.push(item)
- }
- })
- return result
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts" "b/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts"
deleted file mode 100644
index 8a81d0a..0000000
--- "a/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts"
+++ /dev/null
@@ -1,37 +0,0 @@
-function clsx1(object: Record) {
- return Object.keys(object).filter(key => !!object[key]).join(' ')
-}
-
-
-
-console.log(clsx1({
- foo: true,
- bar: false,
- baz: true,
-}))
-
-// foo baz
-
-function clsx(...args: Array | string | null | undefined>) {
- return args.reduce((acc, item) => {
- if (item) {
- if (typeof item === 'object') {
- Object.keys(item).forEach(key => {
- if (item[key]) {
- acc.push(key)
- }
- })
- } else {
- acc.push(item)
- }
- }
- return acc
- }, []).join(' ')
-}
-
-console.log(clsx('foo', {
- bar: true,
- baz: false,
-}))
-
-// foo bar
\ No newline at end of file
diff --git a/packages/code-list/src/schedule.js b/packages/code-list/src/schedule.js
deleted file mode 100644
index 2c885cd..0000000
--- a/packages/code-list/src/schedule.js
+++ /dev/null
@@ -1,45 +0,0 @@
-class Scheduler {
- constructor(limit = 2) {
- this.running = []
- this.pending = []
- this.limit = limit
- }
- add(task) {
- if (this.running.length === this.limit) {
- new Promise(resolve => this.pending.push(() => this.execute(task, resolve)))
- } else {
- new Promise(resolve => this.execute(task, resolve))
- }
- }
- execute(task, resolve) {
- this.running.push(task)
- task().then(() => {
- resolve()
- this.running = this.running.filter(item => item !== task)
- if (this.pending.length) {
- this.pending.shift()()
- }
- })
- }
-}
-
-const createTask = (msg, delay) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- console.log(msg);
- resolve(msg)
- }, delay)
- })
-}
-
-// const scheduler = new Scheduler()
-// scheduler.add(() => createTask(1, 1000))
-// scheduler.add(() => createTask(2, 4000))
-// scheduler.add(() => createTask(3, 1000))
-// scheduler.add(() => createTask(4, 1000))
-// scheduler.add(() => createTask(5, 1000))
-
-Promise.race([createTask(1, 1000), createTask(2, 200)]).then(data => {
- console.log('data', data);
-})
-
diff --git "a/packages/code-list/src/url\347\233\270\345\205\263.ts" "b/packages/code-list/src/url\347\233\270\345\205\263.ts"
deleted file mode 100644
index 7269249..0000000
--- "a/packages/code-list/src/url\347\233\270\345\205\263.ts"
+++ /dev/null
@@ -1,19 +0,0 @@
-
-function getOrigin(url: string) {
- return url.replace(/([^/])\/[^/].*/, '$1')
-}
-
-console.log(getOrigin('https://foo.com/?#%'))
-console.log(getOrigin('https://172.18.0.2/foo/bar'))
-
-// https://foo.com
-// https://172.18.0.2
-
-
-function isWholeUrl(url: string) {
- return /^http(s?):\/\//.test(url)
-}
-
-function isAbsoluteUrl(url: string) {
- return /^\//.test(url)
-}
diff --git "a/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js" "b/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js"
deleted file mode 100644
index 3488731..0000000
--- "a/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js"
+++ /dev/null
@@ -1,105 +0,0 @@
-
-const foo = [
- { id: 'a', value: 'a', nextIds: ['b', 'c', 'd'] },
- { id: 'b', value: 'b', nextIds: ['e'] },
- { id: 'c', value: 'c', nextIds: ['e'] },
- { id: 'd', value: 'd', nextIds: ['f', 'g', 'gg', 'ggg'] },
- { id: 'e', value: 'e', nextIds: ['h', 'ee', 'eee'] },
- { id: 'ee', value: 'ee', nextIds: ['hh'] },
- { id: 'eee', value: 'eee', nextIds: ['hh'] },
- { id: 'f', value: 'f', nextIds: ['i'] },
- { id: 'g', value: 'g', nextIds: ['i'] },
- { id: 'gg', value: 'gg', nextIds: ['i'] },
- { id: 'ggg', value: 'ggg', nextIds: ['i'] },
- { id: 'h', value: 'h', nextIds: ['hh'] },
- { id: 'hh', value: 'hh', nextIds: ['k'] },
- { id: 'i', value: 'i', nextIds: ['j'] },
- { id: 'j', value: 'j', nextIds: ['k'] },
- { id: 'k', value: 'k', nextIds: [] },
-]
-
-function createGraph(data) {
- const rootId = data[0].id
- const map = createMap(data)
- data.forEach(e => {
- const item = map[e.id]
- item.children = []
- item.nextIds.forEach(id => {
- item.children.push(map[id])
- })
- })
- return map[rootId]
-}
-function createMap(data) {
- return data.reduce((s, k) => {
- s[k.id] = k
- return s
- }, {})
-}
-
-const width = 100, height = 50
-
-function calcLocation(graph) {
- let root = graph
- root.left = 0
- root.top = 0
- let minOffset = 0
- const stack = [graph]
- while (stack.length) {
- const node = stack.shift()
- if (!node.children.length) {
- continue
- }
- stack.push(...node.children)
- const len = node.children.length
- const offset = width * (len - 1) / 2
- let sumPosX = 0
- node.children.forEach((item, index) => {
- const left = node.left - offset + width * (index + (len - 1) / 2)
- item.list ? item.list.push(left) : (item.list = [left])
- item.left = calcAvg(item.list)
- sumPosX += item.left
- item.top = node.top + height
- minOffset = Math.min(item.left, minOffset)
- })
- if (len > 1) {
- // node.left = sumPosX / node.children.length
- }
- }
- return { root, minOffset }
-}
-
-function calcAvg(list) {
- return list.reduce((s, v) => s += v) / list.length
-}
-
-function getList() {
- const { root, minOffset } = calcLocation(createGraph(foo))
- const result = []
- const lines = []
- const stack = [root]
- while (stack.length) {
- const node = stack.shift()
- const last = result[result.length - 1]
- if (last && last.id === node.id) {
- continue
- }
- node.children.forEach(child => {
- lines.push({
- x1: child.left - minOffset,
- y1: child.top,
- x2: node.left - minOffset,
- y2: node.top
- })
- })
- result.push({
- left: node.left - minOffset,
- top: node.top,
- value: node.value,
- id: node.id,
- nextIds: node.nextIds,
- })
- stack.push(...node.children)
- }
- return [result, lines]
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js" "b/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js"
deleted file mode 100644
index d98868b..0000000
--- "a/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js"
+++ /dev/null
@@ -1,214 +0,0 @@
-class Tile {
- static WIDTH = 50
- static HEIGHT = 50
- static PADDIGN_X = 20
- static PADDIGN_Y = 10
- constructor(scene, id, posX, posY, value) {
- this.scene = scene
- this.posX = posX
- this.posY = posY
- this.id = id
- this.prev = null
- this.next = null
- this.value = value
- this.color = `#${Math.random().toString(16).substr(3, 6)}`
- }
- render() {
- let { WIDTH: w, HEIGHT: h, PADDIGN_X: x, PADDIGN_Y: y } = Tile
- let { ctx } = this.scene
- ctx.fillStyle = this.color
- ctx.fillRect(this.posX, this.posY, w, h)
- ctx.fillStyle = '#fff'
- ctx.font = "20px Georgia"
- ctx.fillText(this.value, this.posX + 15, this.posY + 25)
- }
- update() {
- this.render()
- }
-}
-
-class Line {
- constructor(scene, parent, child, mode = 'x') {
- this.scene = scene
- this.parent = parent
- this.child = child
- this.mode = mode
- }
- render() {
- let { WIDTH: w, HEIGHT: h, PADDIGN_X: px, PADDIGN_Y: py } = Tile
- let { posX: sx, posY: sy } = this.parent
- let { posX: ex, posY: ey } = this.child
- let { ctx } = this.scene
- ctx.beginPath()
- if (this.mode === 'x') {
- ctx.moveTo(sx + w, sy + h / 2)
- ctx.lineTo(ex - px / 2, sy + h / 2)
- ctx.lineTo(ex - px / 2, ey + h / 2)
- ctx.lineTo(ex, ey + h / 2)
- } else {
- ctx.moveTo(sx + w / 2, sy + h)
- ctx.lineTo(sx + w / 2, ey - py / 2)
- ctx.lineTo(ex + w / 2, ey - py / 2)
- ctx.lineTo(ex + w / 2, ey)
- }
- ctx.stroke()
- ctx.closePath()
- }
- update() {
- this.render()
- }
-}
-
-class Scene {
- static WIDTH = 500
- static HEIGHT = 500
- constructor(ctx, data, mode = 'x') {
- this.data = data
- this.mode = mode
- this.ctx = ctx
- this.init()
- }
- init() {
- this.tiles = []
- this.lines = []
- this.markX = 0
- this.markY = 0
- this.tree = this.buildTree(this.data)
- this.calcTree(this.tree)
- this.calcLocation()
- this.getList()
- this.update()
- }
- createMap(data) {
- return data.reduce((s, k) => {
- s[k.id] = k
- return s
- }, {})
- }
- // isExist(node) {
- // return this.tiles.some(tile => tile.id === node.id)
- // }
- calcLocation() {
- let root = this.tree
- // root.left = 0
- // root.top = 0
- let minOffset = 0
- const stack = [this.tree]
- while (stack.length) {
- const node = stack.shift()
- stack.push(...node.children)
- // const len = node.children.length
- // const offset = width * (len - 1) / 2
- node.children.forEach((item, index) => {
- const posX = node.posX - item.posX
- item.list ? item.list.push(posX) : (item.list = [posX])
- // item.posX = this.calcAvg(item.list)
- // item.top = node.top + height
- // minOffset = Math.min(item.left, minOffset)
- })
- }
- return { root, minOffset }
- }
- getList() {
- // const { root, minOffset } = this.calcLocation()
- const stack = [this.tree]
- while (stack.length) {
- const node = stack.shift()
- const last = this.tiles[this.tiles.length - 1]
- if (last && last.id === node.id) {
- continue
- }
- node.children.forEach((child) => {
- this.lines.push(new Line(this, node, child, this.mode))
- })
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- stack.push(...node.children)
- }
- }
- buildTree(data) {
- const rootId = data[0].id
- const map = this.createMap(data)
- data.forEach(e => {
- const item = map[e.id]
- item.children = []
- item.nextIds.forEach(id => {
- item.children.push(map[id])
- })
- })
- return map[rootId]
- }
- calcTree(data) {
- this.mode === 'x'
- ? this.calcTreeX(data)
- : this.calcTreeY(data)
- }
- calcAvg(list) {
- return list.reduce((s, v) => s += v) / list.length
- }
- calcTreeY(node, max = 0, par = null) {
- let children = node.children
- if (children && children.length) {
- this.markY++
-
- // 操作子节点
- let X = children.reduce((r, e) => {
- r += this.calcTreeY(e, max, node)
- return r
- }, max)
-
- // 操作根节点
- this.markY--
- // node.list ? node.list.push(par.posX) : (node.list = [par.posX])
- node.posX = X / children.length
-
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
-
- // core
- return node.posX
- }
- // 操作根节点
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
- // core
- this.markX++
- return node.posX
- }
- calcTreeX(node, max = 0, par = null) {
- let children = node.children
- if (children && children.length) {
- this.markX++
-
- // 操作子节点
- let Y = children.reduce((r, e) => {
- r += this.calcTreeX(e, max, node)
- return r
- }, max)
-
- // 操作根节点
- this.markX--
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = Y / children.length
-
- // core
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- par && this.lines.push(new Line(this, par, node, this.mode))
- return node.posY
- }
- // 操作根节点
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
-
- // core
- this.lines.push(new Line(this, par, node, this.mode))
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- this.markY++
- return node.posY
- }
- update() {
- let { WIDTH: w, HEIGHT: h } = Scene
- this.ctx.clearRect(0, 0, w, h)
- this.tiles.forEach(e => e.update())
- this.lines.forEach(e => e.update())
- // requestAnimationFrame(this.update.bind(this))
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\217\221\345\270\203\350\256\242\351\230\205.js" "b/packages/code-list/src/\345\217\221\345\270\203\350\256\242\351\230\205.js"
deleted file mode 100644
index 793f3cf..0000000
--- "a/packages/code-list/src/\345\217\221\345\270\203\350\256\242\351\230\205.js"
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * EventBus的使用场景更像是一种广播
- * 当我们向EventBus发送一个事件,则该事件将会传递给多个该事件的订阅者
- *
- */
-function EventBus() {
- this.handle = {}
- this.on = (type, fn) => {
- this.handle[type] ? this.handle[type].push(fn) : this.handle[type] = [fn]
- }
- this.off = (type, fn) => {
- if (fn) {
- this.handle[type] = this.handle[type].filter(e => e !== fn)
- } else {
- delete this.handle[type]
- }
- }
- this.emit = (type) => {
- this.handle[type] && this.handle[type].forEach(e => e())
- }
-}
-let fn1 = (name='Li') => {
- console.log(1, name);
-}
-let fn2 = (age=18) => {
- console.log(1, age);
-}
-let bus = new EventBus()
-bus.on('click', fn1)
-bus.on('click', fn2)
-
-// bus.on('dbclick', () => {
-// console.log(2);
-// })
-bus.off('click')
-console.log(1, bus.handle);
-
-// bus.emit('click')
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts" "b/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts"
deleted file mode 100644
index 6ab35f8..0000000
--- "a/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts"
+++ /dev/null
@@ -1,6 +0,0 @@
-function formatSize(value: number) {
- const mapUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
- const index = Math.log2(value) / 10 | 0
- const size = value / Math.pow(1024, index)
- return size.toFixed(2) + mapUnit[index]
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts" "b/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts"
deleted file mode 100644
index 451cdc1..0000000
--- "a/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts"
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-/**
- * 开头结尾不能有-
- * 不能有两个以上的--
- * 数字、字母和-
- * 2-40个字符
- */
-const reg = /^(?!-)(?!.*-$)(?!.*--.*)[a-z\d-]{2,40}$/i
diff --git "a/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts" "b/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts"
deleted file mode 100644
index 15bbf38..0000000
--- "a/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts"
+++ /dev/null
@@ -1,42 +0,0 @@
-
-function isNull(val: any) {
- return val === undefined || val === null
-}
-
-/**
- * 不严谨,比如页面嵌套iframe就是不同的context环境,用Object.getPrototypeOf(obj) === Object.prototype返回的是false
- *
- */
-function isPlainObject(obj: any) {
- if (typeof obj !== 'object' || obj === null) {
- return false
- }
-
- return Object.getPrototypeOf(obj) === Object.prototype;
-}
-
-// 为什么redux不使用Object.prototype.toString判断Plain Object?
-// Object.prototype.toString判断对象的类型是不严谨的,Symbol.toStringTag可以修改toString的输出
-
-function test() {
- const a = {}
- console.log(Object.prototype.toString.call(a))
- // @ts-ignore
- a[Symbol.toStringTag] = 'Foo'
- console.log(Object.prototype.toString.call(a))
-}
-
-// [object Object]
-// [object Foo]
-
-
-
-// redux v4.0.0的 isPlainObject
-// function isPlainObject(obj: any) {
-// if (typeof obj !== 'object' || obj === null) return false
-// let proto = obj
-// while (Object.getPrototypeOf(proto) !== null) {
-// proto = Object.getPrototypeOf(proto)
-// }
-// return Object.getPrototypeOf(obj) === proto
-// }
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245sum.js" "b/packages/code-list/src/\345\274\202\346\255\245sum.js"
deleted file mode 100644
index 79fcf04..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245sum.js"
+++ /dev/null
@@ -1,19 +0,0 @@
-// 给定一个asyncAdd函数,实现asyncSum
-function asyncAdd(a, b, callback) {
- setTimeout(() => callback(null, a + b), 1000);
-}
-
-async function asyncSum(...args) {
- if (args.length === 1) {
- return args[0]
- }
- const [a, b, ...restArgs] = args
- const result = await new Promise((resolve, reject) => {
- asyncAdd(a, b, (err, result) => {
- err ? reject(err) : resolve(result)
- })
- })
- return asyncSum(result, ...restArgs)
-}
-
-asyncSum(1, 2, 3).then(console.log)
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js" "b/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js"
deleted file mode 100644
index e61d530..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js"
+++ /dev/null
@@ -1,32 +0,0 @@
-const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
-
-const log = console.log
-
-const subFlow = createFlow([() => delay(1000).then(() => log("c"))]);
-
-createFlow([
- () => log("a"),
- () => log("b"),
- subFlow,
- [() => delay(1000).then(() => log("d")), () => log("e")],
-]).run(() => {
- console.log("done");
-});
-// 需要按照 a,b,延迟1秒,c,延迟1秒,d,e, done 的顺序打印
-
-function createFlow(tasks = []) {
- const sources = tasks.flat()
- const run = async (callback) => {
- while (sources.length) {
- const task = sources.shift()
- await (task.run ? task.run() : task())
- }
- if (callback) {
- callback()
- }
- }
-
- return {
- run
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js" "b/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js"
deleted file mode 100644
index 9e2ad30..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js"
+++ /dev/null
@@ -1,122 +0,0 @@
-
-// function fetchLimit(promiseList, limit = 3) {
-// const data = []
-// const runningList = promiseList.slice(0, limit)
-// const pendingList = promiseList.slice(limit)
-
-// const handle = (task, resolve) => {
-
-// }
-
-// return new Promise((resove) => {
-// pendingList.forEach(p => {
-// p.then(msg => {
-// data.push(msg)
-// })
-// })
-// resove(data)
-// })
-// }
-
-// const createTask = (msg, delay) => {
-// return new Promise((resolve) => {
-// setTimeout(() => {
-// console.log(msg);
-// resolve(msg)
-// }, delay)
-// })
-// }
-
-// fetchLimit([
-// createTask('1', 1000),
-// createTask('2', 1000),
-// createTask('3', 1000),
-// createTask('4', 1000),
-// createTask('5', 1000),
-// createTask('6', 1000),
-// ]).then(data => {
-// console.log(data);
-// })
-
-// function limit(count, array, iterateFunc) {
-// const tasks = []
-// const doingTasks = []
-// let i = 0
-// const enqueue = () => {
-// // 递归出口
-// if (i === array.length) {
-// return Promise.resolve()
-// }
-// const task = Promise.resolve().then(() => iterateFunc(array[i++]))
-// tasks.push(task)
-// const doing = task.then(() => doingTasks.splice(doingTasks.indexOf(doing), 1))
-// doingTasks.push(doing)
-// const res = doingTasks.length >= count ? Promise.race(doingTasks) : Promise.resolve()
-// return res.then(enqueue)
-// };
-// return enqueue().then(() => Promise.all(tasks))
-// }
-
-// // test
-// const timeout = i => new Promise(resolve => setTimeout(() => resolve(i), i))
-
-// limit(2, [1000, 1000, 1000, 1000], timeout).then((res) => {
-// console.log(res)
-// })
-
-const createTask = (msg, delay) => {
- return () => new Promise((resolve) => {
- setTimeout(() => {
- console.log(msg);
- resolve(msg)
- }, delay)
- })
-}
-
-// function asyncConcurrenceLimit(tasks, limit = 2) {
-// let count = 0
-// const result = []
-// const handle = (tasks) => {
-// while (tasks.length && limit >= count) {
-// count++
-// const task = tasks.shift()
-// task().then(res => {
-// result.push(res)
-// handle(tasks)
-// }).catch(() => {
-// tasks.unshift(task)
-// }).finally(() => {
-// count--
-
-// })
-// }
-// }
-// return handle(tasks)
-// }
-const t1 = createTask('task 1', 1000)
-const t11 = createTask('task 1', 1000)
-const t111 = createTask('task 1', 1000)
-const t2 = createTask('task 2', 4000)
-const t3 = createTask('task 3', 2000)
-const t4 = createTask('task 4', 5000)
-
-asyncConcurrenceLimit([t1, t11, t111, t2, t3, t4]).then(console.log)
-
-function asyncConcurrenceLimit(array, limit = 2) {
- const tasks = []
- const doingTasks = []
- let i = 0
- const handle = () => {
- // 递归出口
- if (i === array.length) {
- return Promise.resolve()
- }
- const task = array[i++]()
- tasks.push(task)
- const doing = task.then(() => doingTasks.splice(doingTasks.indexOf(doing), 1))
- doingTasks.push(doing)
- const res = doingTasks.length >= limit ? Promise.race(doingTasks) : Promise.resolve()
- return res.then(handle)
- }
- return handle().then(() => Promise.all(tasks))
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js" "b/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js"
deleted file mode 100644
index d866e41..0000000
--- "a/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js"
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 惰性函数
- * 惰性载入表示函数执行的分支只会在函数第一次掉用的时候执行,在第一次调用过程中,
- * 该函数会被覆盖为另一个按照合适方式执行的函数,这样任何对原函数的调用就不用再经过执行的分支了。
- */
-
-// 普通函数
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- element.addEventListener(type, fun, false);
- } else if(element.attachEvent){
- element.attachEvent('on' + type, fun);
- } else{
- element['on' + type] = fun;
- }
-}
-
-// 使用覆盖当前函数方式实现
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- addEvent = (type, element, fun) => element.addEventListener(type, fun, false);
- } else if (element.attachEvent) {
- addEvent = (type, element, fun) = element.attachEvent('on' + type, fun);
- } else {
- addEvent = (type, element, fun) => element['on' + type] = fun;
- }
-}
-
-// 使用IIFE方式实现
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- element.addEventListener(type, fun, false);
- } else if(element.attachEvent){
- element.attachEvent('on' + type, fun);
- } else{
- element['on' + type] = fun;
- }
-}
diff --git "a/packages/code-list/src/\346\211\213\345\206\231instanceof.js" "b/packages/code-list/src/\346\211\213\345\206\231instanceof.js"
deleted file mode 100644
index 7535293..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231instanceof.js"
+++ /dev/null
@@ -1,16 +0,0 @@
-
-function instanceof$(inst, base) {
- let proto = inst.__proto__
- const baseProto = base.prototype
- while (proto) {
- if (baseProto === proto) {
- return true
- }
- proto = proto.__proto__
- }
- return false
-}
-
-const a = []
-console.log(instanceof$(a, Array));
-console.log(a instanceof Array);
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\211\213\345\206\231new.js" "b/packages/code-list/src/\346\211\213\345\206\231new.js"
deleted file mode 100644
index 709a85d..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231new.js"
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 思路
- * 1. 创建空对象
- * 2. 设置原型链
- * 3. 让构造函数this指向改对象
- * 4. 判断结果返回对象
- * @param {*} func 构造函数
- */
-function new$(func, ...args) {
- if (typeof func !== 'function') {
- throw new TypeError('参数期望是构造函数')
- }
- // const obj = {}
- // obj.__proto__ = func.prototype
- const obj = Object.create(func.prototype)
- const result = func.apply(obj, args)
- return result && typeof result === 'object' ? result : obj
-}
-
-// 测试
-function Person(name) {
- this.name = name
-}
-Person.prototype.sayName = function() {
- console.log(`My name is ${this.name}`)
-}
-const me = new$(Person, 'Jack')
-me.sayName()
-console.log(me)
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\211\213\345\206\231promise.js" "b/packages/code-list/src/\346\211\213\345\206\231promise.js"
deleted file mode 100644
index a3f4369..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231promise.js"
+++ /dev/null
@@ -1,201 +0,0 @@
-const PENDIGN = 'pending'
-const RESOLVED = 'resolved'
-const REJECTED = 'rejected'
-
-class MyPromise {
- constructor(executor) {
- this.status = PENDIGN
- this.data = undefined
- this.callbacks = []
-
- const resolve = (value) => {
- if (this.status === PENDIGN) {
- this.data = value
- this.status = RESOLVED
- setTimeout(() => {
- this.callbacks.forEach(({ onfulfilled }) => onfulfilled())
- })
- }
- }
- const reject = (reason) => {
- if (this.status === PENDIGN) {
- this.data = reason
- this.status = REJECTED
- setTimeout(() => {
- this.callbacks.forEach(({ onrejected }) => onrejected())
- })
- }
- }
- try {
- executor(resolve, reject)
- } catch(e) {
- reject(e)
- }
- }
- catch(onrejected) {
- return this.then(undefined, onrejected)
- }
- then(onfulfilled, onrejected) {
- onfulfilled = typeof onfulfilled === 'function' ? onfulfilled : () => this.data
- onrejected = typeof onrejected === 'function' ? onrejected : () => { throw this.data }
-
- return new MyPromise((resolve, reject) => {
- const handle = (callback) => {
- try {
- const result = callback(this.data)
- result instanceof MyPromise ? result.then(resolve, reject) : resolve(result)
- } catch (error) {
- reject(error)
- }
- }
-
- if (this.status === PENDIGN) {
- this.callbacks.push({
- onfulfilled: () => handle(onfulfilled),
- onrejected: () => handle(onrejected),
- })
- } else {
- setTimeout(() => {
- this.status === RESOLVED ? handle(onfulfilled) : handle(onrejected)
- })
- }
- })
- }
-}
-MyPromise.resolved = (value) => {
- return new MyPromise((resolved) => {
- resolved(value)
- })
-}
-MyPromise.rejected = (reason) => {
- return new MyPromise((_, rejected) => {
- rejected(reason)
- })
-}
-MyPromise.all = (promiseList) => {
- let count = 0
- const result = []
- return new MyPromise((resolve, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- result[i] = value
- count++
- if (count === promiseList.length) {
- resolve(result)
- }
- }).catch(err => {
- reject(err)
- return
- })
- }
- })
-}
-MyPromise.race = (promiseList) => {
- return new MyPromise((resolved, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- resolved(value)
- return
- }).catch(err => {
- reject(err)
- return
- })
- }
- })
-}
-MyPromise.allSettled = (promiseList) => {
- let count = 0
- const result = []
- return new MyPromise((resolve, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- result[i] = { status: 'fulfilled', value, }
- count++
- if (count === promiseList.length) {
- resolve(result)
- }
- }).catch(reason => {
- result[i] = { status: 'rejected', reason, }
- count++
- if (count === promiseList.length) {
- reject(result)
- }
- })
- }
- })
-}
-
-const createTask = (task, delay = 1000, flag = false) => {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log('task', task);
- flag ? reject(`reject ${task}`) : resolve(task)
- }, delay);
- })
-}
-
-// MyPromise.all([
-// createTask(1, 1000),
-// createTask(2, 2000),
-// createTask(3, 1000),
-// ]).then(result => {
-// console.log(result);
-// })
-// Promise.race([
-// createTask(1, 1000),
-// createTask(2, 2000, true),
-// createTask(3, 1000),
-// ]).then(result => {
-// console.log('result', result);
-// }).catch(err => {
-// console.log('err', err);
-// })
-MyPromise.allSettled([
- createTask(1, 1000),
- createTask(2, 2000, true),
- createTask(3, 1000),
-]).then(result => {
- console.log('result', result);
-}).catch(err => {
- console.log('err', err);
-})
-
-// const p1 = () => new MyPromise((resolve) => {
-// console.log(1);
-// // let p2 = new MyPromise((resolve) => {
-// // console.log(2);
-// // setTimeout(() => { // 宏task 1
-// // console.log(3);
-// // }, 0)
-// // resolve(5);
-// // });
-// resolve(6);
-// // p2.then((arg) => {
-// // console.log(arg);
-// // });
-// })
-// setTimeout(() => { // 宏task 1
-// console.log(8);
-// // new MyPromise(resolve => {
-// // resolve(9);
-// // }).then(res => {
-// // console.log(res)
-// // })
-// }, 0)
-// p1().then((arg) => {
-// console.log(arg);
-// });
-// console.log(10);
-// 1 2 10 5 6 8 9 3
diff --git "a/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js" "b/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js"
deleted file mode 100644
index d5eb99b..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js"
+++ /dev/null
@@ -1,22 +0,0 @@
-
-function flat(arr, deep = -1) {
- const result = []
- if (deep === 0) {
- return arr
- }
- arr.forEach(item => {
- if (Array.isArray(item)) {
- result.push(...flat(item, deep - 1))
- } else {
- result.push(item)
- }
- })
- return result
-}
-
-console.log(flat([1, 2, 3]));
-console.log(flat([1, 2, [3, 4]]));
-console.log(flat([1, [2, [3, 4]]]));
-console.log(flat([1, [2, [3, 4]]], 0));
-console.log(flat([1, [2, [3, 4]]], 1));
-console.log(flat([1, [2, [3, 4]]], 2));
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\213\267\350\264\235.js" "b/packages/code-list/src/\346\213\267\350\264\235.js"
deleted file mode 100644
index 3e02e97..0000000
--- "a/packages/code-list/src/\346\213\267\350\264\235.js"
+++ /dev/null
@@ -1,162 +0,0 @@
-const foo = {
- data: data
-}
-const data = {
- list: [
- {
- foo: 1,
- baz: true,
- }
- ],
- object: {
- foo: 1
- },
- foo: 1,
- baz: true
-}
-/**
- * 递归拷贝
- * 这里使用了reduce,超级好用的api
- * @param data 数据源
- */
-function copy(data, cache = []) {
- if (Array.isArray(data)) {
- return data.reduce((r, v) => {
- r.push(typeof v === 'object' ? copy(v) : v)
- return r
- }, [])
- }
- if (typeof data === 'object') {
- return Object.entries(data).reduce((r, [k, v]) => {
- if (cache.includes(v)) {
- r[k] = v
- return r
- }
- r[k] = typeof data[k] === 'object' ? copy(v, cache) : v
- cache.push(v)
- return r
- }, {})
- }
- return data
-}
-// const copy = source => {
-// if (!getType(source)) {
-// return source;
-// }
-// let dest = Array.isArray(source) ? [] : {};
-// const queue = [{ source, dest }];
-// const set = new Set([]);
-
-// while (queue.length) {
-// const { dest, source } = queue.shift();
-// const type = getType(source);
-// if (type === "Array") {
-// source.forEach((x, index) => {
-// const xType = getType(x);
-// if (!xType) {
-// dest[index] = x;
-// return;
-// }
-
-// if (xType === "Array") {
-// dest[index] = [];
-// queue.push({
-// source: x,
-// dest: dest[index]
-// });
-// return;
-// }
-
-// if (xType === "Object") {
-// if (set.has(x)) {
-// dest[index] = x;
-// return;
-// }
-// dest[index] = {};
-// queue.push({
-// source: x,
-// dest: dest[index]
-// });
-// return;
-// }
-// });
-// } else {
-// // 对象
-// for (let [k, v] of Object.entries(source)) {
-// const vType = getType(v);
-// if (!vType) {
-// dest[k] = v;
-// continue;
-// }
-// if (vType === "Array") {
-// dest[k] = [];
-// queue.push({
-// source: v,
-// dest: dest[k]
-// });
-// }
-// if (vType === "Object") {
-// if (set.has(v)) {
-// dest[k] = v;
-// continue;
-// }
-// dest[k] = {};
-// queue.push({
-// source: v,
-// dest: dest[k]
-// });
-// }
-// }
-// }
-// set.add(source);
-// }
-// return dest;
-// };
-
-console.log(copy(111));
-console.log(copy(true));
-const list = [1, 2, 3]
-console.log(copy(list), copy(list) === list);
-const obj = { foo: 1, bar: true, baz: [1, 2, 3] }
-console.log(copy(obj), copy(obj) === obj);
-
-console.log('end');
-
-// 深拷贝对象
-function deepClone(obj) {
- const _toString = Object.prototype.toString
-
- // null, undefined, non-object, function
- if (!obj || typeof obj !== 'object') {
- return obj
- }
-
- // DOM Node
- if (obj.nodeType && 'cloneNode' in obj) {
- return obj.cloneNode(true)
- }
-
- // Date
- if (_toString.call(obj) === '[object Date]') {
- return new Date(obj.getTime())
- }
-
- // RegExp
- if (_toString.call(obj) === '[object RegExp]') {
- const flags = []
- if (obj.global) { flags.push('g') }
- if (obj.multiline) { flags.push('m') }
- if (obj.ignoreCase) { flags.push('i') }
-
- return new RegExp(obj.source, flags.join(''))
- }
-
- const result = Array.isArray(obj) ? [] : obj.constructor ? new obj.constructor() : {}
-
- for (const key in obj) {
- result[key] = deepClone(obj[key])
- }
-
- return result
-}
-
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts" "b/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts"
deleted file mode 100644
index 520d336..0000000
--- "a/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts"
+++ /dev/null
@@ -1,16 +0,0 @@
-function group(array: T[], count: number) {
- const result: T[][] = []
- for (let i = 0; i < array.length; i+=count) {
- result.push(array.slice(i, i + count))
- }
- return result
-}
-
-
-const list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
-
-console.log(group(list, 3))
-console.log(group(list, 5))
-
-// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
-// [ [ 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9 ] ]
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts" "b/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts"
deleted file mode 100644
index 3d7ad79..0000000
--- "a/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts"
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * A
- * B C
- * D E F
- */
-
-const F = { id: 'F', children: [] }
-const E = { id: 'E', children: [] }
-const D = { id: 'D', children: [] }
-const C = { id: 'C', children: [F] }
-const B = { id: 'B', children: [D, E] }
-const A = { id: 'A', children: [B, C] }
-
-interface TreeNode {
- id: string
- children: TreeNode[]
-}
-
-
-function findPath(data: TreeNode[], nodeId: string, path: string[] = []): string[] | null {
- const newPath: string[] = [...path]
- for (let i = 0; i < data.length; i++) {
- const node = data[i]
- newPath.push(node.id)
- if (node.id === nodeId) {
- return newPath
- }
- const result = findPath(node.children, nodeId, newPath)
- if (result) {
- return result
- }
- newPath.pop()
- }
- return null
-}
-
-console.log(findPath([A], 'F'))
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts" "b/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts"
deleted file mode 100644
index 305f70d..0000000
--- "a/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts"
+++ /dev/null
@@ -1,29 +0,0 @@
-function download(filename: string, data: string) {
- const base64ToBlob = function(code: string) {
- const parts = code.split(';base64,');
- const contentType = parts[0].split(':')[1];
- const raw = atob(parts[1]);
- const rawLength = raw.length;
- const uInt8Array = new Uint8Array(rawLength);
-
- for (let i = 0; i < rawLength; ++i) {
- uInt8Array[i] = raw.charCodeAt(i);
- }
- return new Blob([uInt8Array], {
- type: contentType
- });
- };
- const a = document.createElement('a')
- if (/^data:.+;base64/.test(content)) {
- const blob = base64ToBlob(content);
- a.href = URL.createObjectURL(blob);
- } else {
- a.href = content
- }
- const url = URL.createObjectURL(new Blob([data]))
- a.download = filename
- a.rel = 'noopener'
- a.href = url
- a.click()
- a.remove()
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js" "b/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js"
deleted file mode 100644
index 7f70a33..0000000
--- "a/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js"
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 老早前看网上的代码
- */
-function getType(val) {
- const cfg = {
- '[object Object]': 'object',
- '[object Array]': 'array',
- '[object Number]': 'object number',
- '[object Boolean]': 'object boolean',
- '[object String]': 'object string',
- '[object Null]': 'null',
- }
- const type = typeof val
- const toString = e => Object.prototype.toString.call(e)
- return type === 'object' ? cfg[toString(val)] : type
-}
-
-/**
- * 其实我觉得行代码就可以了
- */
-function getType(val) {
- return Object.prototype.toString.call(val).toLowerCase().slice(8, -1)
-}
-
-/**
- * 当然也可以写成函数表达式
- * 其实这里有个技巧,就是slice支持负数,这一点是优于substring的
- */
-const getType = val => Object.prototype.toString.call(val).toLowerCase().slice(8, -1)
-
-
-/**
- * 然而这并不是一劳永逸的,对于自定义的对象还是要通过instanceof判断的
- * 这也很容易理解,毕竟多数时候其实用不了折磨多,最最常用的还是判断数组
- * 但是我们现在是幸福的,可以用Array.isArray判断了
- */
-function test() {
- const list = [1, 3, 5]
- console.log(Array.isArray(list));
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js" "b/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js"
deleted file mode 100644
index f88ac02..0000000
--- "a/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js"
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-function wrapApi(api) {
- let __counter__ = 0
- return (...args) => {
- const counter = ++__counter__
- __counter__ = counter
- return api(...args).then(res => {
- return {
- ...res,
- isNew: () => __counter__ === counter,
- }
- })
- }
-}
-
-const getAge = (age) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve({ age })
- }, 100)
- })
-}
-const getName = (name) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve({ name })
- }, 300)
- })
-}
-const getAgeWrap = wrapApi(getAge)
-const getNameWrap = wrapApi(getName)
-
-function onChange(age, name) {
- getAgeWrap(age).then(res => {
- if (res.isNew()) {
- console.log(res);
- }
- })
- getNameWrap(name).then(res => {
- if (res.isNew()) {
- console.log(res);
- }
- })
-}
-
-onChange(10, 'Tom')
-onChange(20, 'Jack')
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js" "b/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js"
deleted file mode 100644
index 1143eec..0000000
--- "a/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js"
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 测试Promise then方法的第二个参数和catch的优先级
- * then > catch
- */
-// Promise.reject(1).then(function(value) {
-// console.log('success', value);
-// }, function(value) {
-// console.log('error', value);
-// }).catch(function(error) {
-// console.log('catch', error);
-// })
-
-function LazyMan(name) {
- this.name = name;
- this.queue = [];
- this.queue.push(() => {
- console.log(`hello this is ${this.name}`);
- return Promise.resolve();
- });
- let template = Promise.resolve();
- setTimeout(() => {
- while(this.queue.length) {
- template = template.then(this.queue.pop())
- }
- }, 0)
- // setTimeout(() => {
- // this.queue.forEach(v => {
- // template = template.then(v);
- // });
- // }, 0)
-}
-LazyMan.prototype = {
- sleep(time) {
- this.queue.push(function() {
- return new Promise(function(resolve) {
- setTimeout(() => {
- console.log(`暂停${time}s!`);
- resolve();
- }, time * 1000);
- });
- })
- return this;
- },
- eat(food) {
- this.queue.push(function() {
- console.log(`正在吃 ${food}`);
- return Promise.resolve();
- })
- return this;
- }
-}
-
-// new LazyMan('jack').sleep(2).eat('shit').sleep(3).eat('shit');
-
-function promisify(func) {
- return (...arg) => {
- return () => new Promise((resolve, reject) => {
- func(...arg, (err, arg) => {
- err ? reject(err) : resolve(arg)
- })
- })
- }
-}
-
-function test(text, callback) {
- setTimeout(() => {
- console.log(text);
- callback(null, 'ok')
- }, 1000);
-}
-const chain = []
-chain.push(promisify(test)(1))
-chain.push(promisify(test)(2))
-chain.push(promisify(test)(3))
-
-let handle = Promise.resolve()
-
-setTimeout(() => {
- while (chain.length) {
- handle = handle.then(chain.shift())
- }
-}, 0)
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js" "b/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js"
deleted file mode 100644
index 51076bc..0000000
--- "a/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js"
+++ /dev/null
@@ -1,20 +0,0 @@
-
-function debounce(func, delay = 500, thisArg = null) {
- let timer
- return (...args) => {
- clearTimeout(timer)
- timer = setTimeout(() => {
- func.call(thisArg, ...args)
- }, delay)
- }
-}
-
-function throttle(func, interval = 1000, thisArg = null) {
- let stamp
- return (...args) => {
- if (stamp == null || Date.now() - stamp > interval) {
- func.call(thisArg, ...args)
- stamp = Date.now()
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts" "b/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts"
deleted file mode 100644
index f209477..0000000
--- "a/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts"
+++ /dev/null
@@ -1,4 +0,0 @@
-
-function randID() {
- return Math.random().toString(36).slice(2)
-}
\ No newline at end of file
diff --git a/packages/game-react/.gitignore b/packages/game-react/.gitignore
deleted file mode 100644
index a547bf3..0000000
--- a/packages/game-react/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-lerna-debug.log*
-
-node_modules
-dist
-dist-ssr
-*.local
-
-# Editor directories and files
-.vscode/*
-!.vscode/extensions.json
-.idea
-.DS_Store
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
diff --git a/packages/game-react/.npmrc b/packages/game-react/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-react/index.html b/packages/game-react/index.html
deleted file mode 100644
index 6c2ad5a..0000000
--- a/packages/game-react/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
- game
-
-
-
-
-
-
diff --git a/packages/game-react/package.json b/packages/game-react/package.json
deleted file mode 100644
index 1344c7a..0000000
--- a/packages/game-react/package.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "name": "game-react",
- "version": "0.0.0",
- "scripts": {
- "dev": "vite",
- "build": "tsc && vite build",
- "preview": "vite preview"
- },
- "dependencies": {
- "copy-to-clipboard": "^3.3.1",
- "lz-string": "^1.4.4",
- "react": "^18.0.0",
- "react-dom": "^18.0.0",
- "react-router-dom": "^6.3.0"
- },
- "devDependencies": {
- "@types/lz-string": "^1.3.34",
- "@types/react": "^18.0.0",
- "@types/react-dom": "^18.0.0",
- "@vitejs/plugin-react": "^1.3.0",
- "consola": "^2.15.3",
- "less": "^4.1.2",
- "rollup-plugin-external-globals": "^0.6.1",
- "typescript": "^4.5.4",
- "vite": "^2.9.9",
- "vite-plugin-style-import": "^1"
- }
-}
diff --git a/packages/game-react/public/assets/black-white-turn-pro.png b/packages/game-react/public/assets/black-white-turn-pro.png
deleted file mode 100644
index c703bcf..0000000
Binary files a/packages/game-react/public/assets/black-white-turn-pro.png and /dev/null differ
diff --git a/packages/game-react/public/assets/black-white-turn.png b/packages/game-react/public/assets/black-white-turn.png
deleted file mode 100644
index 95d058d..0000000
Binary files a/packages/game-react/public/assets/black-white-turn.png and /dev/null differ
diff --git a/packages/game-react/public/assets/flag-battle.png b/packages/game-react/public/assets/flag-battle.png
deleted file mode 100644
index 07428a4..0000000
Binary files a/packages/game-react/public/assets/flag-battle.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-2048.png b/packages/game-react/public/assets/number-2048.png
deleted file mode 100644
index 7182915..0000000
Binary files a/packages/game-react/public/assets/number-2048.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-puzzle.png b/packages/game-react/public/assets/number-puzzle.png
deleted file mode 100644
index cf13bac..0000000
Binary files a/packages/game-react/public/assets/number-puzzle.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-ring.png b/packages/game-react/public/assets/number-ring.png
deleted file mode 100644
index c6080ce..0000000
Binary files a/packages/game-react/public/assets/number-ring.png and /dev/null differ
diff --git a/packages/game-react/public/assets/rotate-puzzle.png b/packages/game-react/public/assets/rotate-puzzle.png
deleted file mode 100644
index 73589cb..0000000
Binary files a/packages/game-react/public/assets/rotate-puzzle.png and /dev/null differ
diff --git a/packages/game-react/src/App.less b/packages/game-react/src/App.less
deleted file mode 100644
index b415b74..0000000
--- a/packages/game-react/src/App.less
+++ /dev/null
@@ -1,45 +0,0 @@
-@import './utils/index.less';
-
-* {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
-}
-
-.grid {
- display: flex;
- flex-wrap: wrap;
- max-width: 1000px;
- margin: 0 auto;
- justify-content: space-around;
- margin-top: 24px;
- .card {
- flex: 0 0 calc(25% - 16px);
- &.placeholder {
- opacity: 0;
- margin: 0;
- padding: 0;
- cursor: default;
- }
- }
-
- .medium({
- width: auto;
- margin: 24px;
- .card {
- flex-basis: calc(33.3333% - 16px);
- }
- });
-
- .small({
- .card {
- flex-basis: calc(50% - 16px);
- }
- });
-
- .xsmall({
- .card {
- flex-basis: calc(100%);
- }
- });
-}
\ No newline at end of file
diff --git a/packages/game-react/src/App.tsx b/packages/game-react/src/App.tsx
deleted file mode 100644
index 7e664cf..0000000
--- a/packages/game-react/src/App.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import './App.less'
-import Card from './components/Card'
-import { HashRouter, Route, Routes } from 'react-router-dom';
-import config from './config'
-import useViewport, { Breakpoints } from './hooks/useViewport';
-import useMatchMedia from './hooks/useMatchMedia';
-
-function App() {
- return (
-
-
-
- {
- config.map(item => {
- return (
-
- )
- })
- }
-
- {
- config.map(item => {
- return (
-
- )
- })
- }
-
-
-
-
} />
-
-
-
- )
-}
-
-export default App
diff --git a/packages/game-react/src/components/Card/index.less b/packages/game-react/src/components/Card/index.less
deleted file mode 100644
index 77c28db..0000000
--- a/packages/game-react/src/components/Card/index.less
+++ /dev/null
@@ -1,22 +0,0 @@
-@import '../../utils/index.less';
-
-.card {
- border: 1px solid #edeced;
- border-radius: 8px;
- margin-bottom: 24px;
- box-sizing: border-box;
- overflow: hidden;
- padding: 16px;
- &:hover {
- cursor: pointer;
- box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);
- }
-
- > h3 {
- .single-ellipsis;
- }
- > p {
- word-break: break-all;
- .multi-ellipsis(2);
- }
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/Card/index.tsx b/packages/game-react/src/components/Card/index.tsx
deleted file mode 100644
index a1a2aa1..0000000
--- a/packages/game-react/src/components/Card/index.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { useNavigate } from "react-router-dom"
-import HsImage from "../HsImage"
-import './index.less'
-
-interface IProps {
- url?: string
- title: string
- description: string
- path: string
-}
-
-export default function Card(props: IProps) {
- const navigate = useNavigate()
-
- return (
- {
- navigate(props.path)
- }}>
-
-
{props.title}
-
{props.description}
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/HsImage/index.less b/packages/game-react/src/components/HsImage/index.less
deleted file mode 100644
index ae87b98..0000000
--- a/packages/game-react/src/components/HsImage/index.less
+++ /dev/null
@@ -1,5 +0,0 @@
-.hs-image {
-
- background-position: center;
- background-size: cover;
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/HsImage/index.tsx b/packages/game-react/src/components/HsImage/index.tsx
deleted file mode 100644
index 691b807..0000000
--- a/packages/game-react/src/components/HsImage/index.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { clsx } from '../../utils'
-import './index.less'
-
-interface IProps {
- url: string
- style?: React.CSSProperties
- className?: string
-}
-
-export default function HsImage(props: IProps) {
- return (
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/config.tsx b/packages/game-react/src/config.tsx
deleted file mode 100644
index 9a71008..0000000
--- a/packages/game-react/src/config.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import Game01 from './views/峰回路转'
-import Game02 from './views/黑白迭代'
-import Game03 from './views/黑白无双'
-import Game04 from './views/六边形2028'
-import Game05 from './views/数字华容道'
-import Game06 from './views/旋转拼图'
-import Game07 from './views/血战到底'
-import Game09 from './views/战旗阵地'
-import Game10 from './views/Game2048'
-const numberRing = './assets/number-ring.png'
-const numberPuzzle = './assets/number-puzzle.png'
-const flagBattle = './assets/flag-battle.png'
-const blackWhiteTurn = './assets/black-white-turn.png'
-const blackWhiteTurnPro = './assets/black-white-turn-pro.png'
-const rotatePuzzle = './assets/rotate-puzzle.png'
-const number2048 = './assets/number-2048.png'
-
-export default [
- {
- path: '/number-ring',
- title: '峰回路转',
- element: ,
- description: '峰回路转',
- url: numberRing,
- },
- {
- path: '/black-white-turn',
- title: '黑白迭代',
- element: ,
- description: '黑白迭代',
- url: blackWhiteTurn,
- },
- {
- path: '/black-white-turn-pro',
- title: '黑白无双',
- element: ,
- description: '黑白无双',
- url: blackWhiteTurnPro,
- },
- // {
- // path: '/game04',
- // title: '六边形2028',
- // element: ,
- // description: '六边形2028',
- // url: flagBattle,
- // },
- {
- path: '/number-puzzle',
- title: '数字华容道',
- element: ,
- description: '数字华容道',
- url: numberPuzzle,
- },
- {
- path: '/rotate-puzzle',
- title: '旋转拼图',
- element: ,
- description: '旋转拼图',
- url: rotatePuzzle,
- },
- // {
- // path: '/game07',
- // title: '血战到底',
- // element: ,
- // description: '血战到底',
- // url: flagBattle,
- // },
- {
- path: '/game09',
- title: '战旗阵地',
- element: ,
- description: '战旗阵地',
- url: flagBattle,
- },
- {
- path: '/number-2048',
- title: '2048',
- element: ,
- description: '2048',
- url: number2048,
- },
- ]
\ No newline at end of file
diff --git a/packages/game-react/src/favicon.svg b/packages/game-react/src/favicon.svg
deleted file mode 100644
index de4aedd..0000000
--- a/packages/game-react/src/favicon.svg
+++ /dev/null
@@ -1,15 +0,0 @@
-
diff --git a/packages/game-react/src/hooks/useGesture.tsx b/packages/game-react/src/hooks/useGesture.tsx
deleted file mode 100644
index c978ba9..0000000
--- a/packages/game-react/src/hooks/useGesture.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { useEffect, useRef, useState } from "react"
-
-interface ContextProps {
- dir: number
- startPoints: [number, number]
- endPoints: [number, number]
-}
-
-/**
- * dir up -> 0 right -> 1 down -> 2 left -> 3
- */
-export default function useGesture(callback: (ctx: ContextProps) => void) {
- const pressedRef = useRef(false)
- const startPosRef = useRef<[number, number]>([0, 0])
- const endPosRef = useRef<[number, number]>([0, 0])
- const [index, setIndex] = useState(0)
- const panelRef = useRef(null)
- const threshold = 50
-
- function analyse(startPos: number[], endPos: number[]) {
- if (getDistance(startPos ,endPos) < threshold) {
- return -1
- }
- const [x1, y1] = startPos
- const [x2, y2] = endPos
- const dx = x2 - x1
- const dy = y2 - y1
- if (Math.abs(dx) > Math.abs(dy)) {
- return dx > 0 ? 1 : 3
- } else {
- return dy > 0 ? 2 : 0
- }
- }
-
- function getDistance(startPos: number[], endPos: number[]) {
- const [x1, y1] = startPos
- const [x2, y2] = endPos
- return Math.pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)
- }
-
- useEffect(() => {
- function handleMouseDown(e: MouseEvent) {
- pressedRef.current = true
- startPosRef.current = [e.clientX, e.clientY]
- }
- function handleMouseUp(e: MouseEvent) {
- if (pressedRef.current) {
- endPosRef.current = [e.clientX, e.clientY]
- pressedRef.current = false
- setIndex(index => index + 1)
- }
- }
- const node = panelRef.current
- node.addEventListener('mousedown', handleMouseDown)
- window.addEventListener('mouseup', handleMouseUp)
- return () => {
- node.removeEventListener('mousedown', handleMouseDown)
- window.removeEventListener('mouseup', handleMouseUp)
- }
- }, [])
-
- useEffect(() => {
- const startPos = startPosRef.current
- const endPos = endPosRef.current
- const dir = analyse(startPos, endPos)
- if (dir !== -1) {
- callback({
- dir: dir,
- startPoints: startPosRef.current,
- endPoints: endPosRef.current,
- })
- }
- }, [index])
-
- return panelRef
-}
\ No newline at end of file
diff --git a/packages/game-react/src/hooks/useMatchMedia.tsx b/packages/game-react/src/hooks/useMatchMedia.tsx
deleted file mode 100644
index 891ed16..0000000
--- a/packages/game-react/src/hooks/useMatchMedia.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import { useEffect, useState } from "react"
-
-export default function useMatchMedia(query: string) {
- const [matched, setMatched] = useState(window.matchMedia(query).matches)
-
- useEffect(
- () => {
- const handle = (ev: MediaQueryListEvent) => {
- setMatched(ev.matches)
- console.log(document.documentElement.offsetWidth <= 960, document.documentElement.offsetWidth)
- }
- const mediaQueryList = window.matchMedia(query)
- mediaQueryList.addEventListener('change', handle)
- setMatched(mediaQueryList.matches)
- return () => {
- mediaQueryList.removeEventListener('change', handle)
- }
- },
- []
- )
-
- return matched
-}
\ No newline at end of file
diff --git a/packages/game-react/src/hooks/useViewport.tsx b/packages/game-react/src/hooks/useViewport.tsx
deleted file mode 100644
index 72f08ab..0000000
--- a/packages/game-react/src/hooks/useViewport.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import useMatchMedia from "./useMatchMedia"
-
-export enum Breakpoints {
- XSmall = '(max-width: 480px)',
- Small = '(min-width: 480px) and (max-width: 768px)',
- Medium = '(min-width: 768px) and (max-width: 960px)',
- Large = '(min-width: 961px) and (max-width: 1200px)',
- XLarge = '(min-width: 1200px)',
-}
-
-const breakpoints: BreakpointType[] = ['xmall', 'small', 'medium', 'large', 'xlarge']
-type BreakpointType = 'xmall' | 'small' | 'medium' | 'large' | 'xlarge'
-
-export default function useViewport(): BreakpointType {
- const list = [
- useMatchMedia(Breakpoints.XSmall),
- useMatchMedia(Breakpoints.Small),
- useMatchMedia(Breakpoints.Medium),
- useMatchMedia(Breakpoints.Large),
- useMatchMedia(Breakpoints.XLarge),
- ]
-
- const index = list.findIndex(Boolean)
-
- return breakpoints[index]
-}
\ No newline at end of file
diff --git a/packages/game-react/src/index.less b/packages/game-react/src/index.less
deleted file mode 100644
index ec2585e..0000000
--- a/packages/game-react/src/index.less
+++ /dev/null
@@ -1,13 +0,0 @@
-body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
- sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
-}
-
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
- monospace;
-}
diff --git a/packages/game-react/src/main.tsx b/packages/game-react/src/main.tsx
deleted file mode 100644
index 28110ad..0000000
--- a/packages/game-react/src/main.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import React from 'react'
-import ReactDOM from 'react-dom/client'
-import './index.less'
-import App from './App'
-
-ReactDOM.createRoot(document.getElementById('root')!).render(
-
-
-
-)
diff --git a/packages/game-react/src/utils/contants.ts b/packages/game-react/src/utils/contants.ts
deleted file mode 100644
index 472f975..0000000
--- a/packages/game-react/src/utils/contants.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export enum DevicesViewport {
- Mobile = '(max-width: 600px)',
- Pad = '(min-width: 600px) and (max-width: 1000px)',
- Web = '(min-width: 1000px)',
-}
\ No newline at end of file
diff --git a/packages/game-react/src/utils/index.less b/packages/game-react/src/utils/index.less
deleted file mode 100644
index d5a222a..0000000
--- a/packages/game-react/src/utils/index.less
+++ /dev/null
@@ -1,31 +0,0 @@
-// @devices-handset: "(max-width: 600px)";
-// @devices-tablet: "(min-width: 600px) and (max-width: 1000px)";
-// @devices-web: "(min-width: 1000px)";
-
-@xsmall: 480px;
-@small: 768px;
-@medium: 960px;
-@large: 1200px;
-
-@color: red;
-
-// @viewport-points: @xsmall, @small, @medium, @large, @xlarge;
-
-.xsmall(@rule) { @media (max-width: @xsmall) { @rule(); } }
-.small(@rule) { @media (max-width: @small) { @rule(); } }
-.medium(@rule) { @media (max-width: @medium) { @rule(); } }
-.large(@rule) { @media (max-width: @large) { @rule(); } }
-.xlarge(@rule) { @media (min-width: @large) { @rule(); } }
-
-.single-ellipsis {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
-}
-
-.multi-ellipsis(@line: 3) {
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: @line;
-}
\ No newline at end of file
diff --git a/packages/game-react/src/utils/index.ts b/packages/game-react/src/utils/index.ts
deleted file mode 100644
index b00c2d2..0000000
--- a/packages/game-react/src/utils/index.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-export function clsx(...args: Array | string | boolean | null | undefined>) {
- return args.reduce(
- (acc, arg) => {
- if (arg) {
- if (typeof arg === 'string') {
- acc.push(arg)
- }
- if (typeof arg === 'object') {
- Object.keys(arg).forEach(key => {
- if (arg[key]) {
- acc.push(key)
- }
- })
- }
- }
- return acc
- },
- []
- ).join(' ')
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/Tile.tsx b/packages/game-react/src/views/Game2048/Tile.tsx
deleted file mode 100644
index 3b2771d..0000000
--- a/packages/game-react/src/views/Game2048/Tile.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from "react";
-import Core2048 from "./logic";
-
-interface IProps {
- value: number,
- position: number,
-}
-const tileWidth = 75;
-
-export default function(props: IProps) {
- const style: React.CSSProperties = {
- left: (props.position % Core2048.Scale) * tileWidth,
- top: (props.position / Core2048.Scale | 0) * tileWidth,
- }
- return (
- {props.value ? props.value : ''}
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/index.less b/packages/game-react/src/views/Game2048/index.less
deleted file mode 100644
index abc076c..0000000
--- a/packages/game-react/src/views/Game2048/index.less
+++ /dev/null
@@ -1,60 +0,0 @@
-.game2048 {
- text-align: center;
- padding: 30px;
-
- .pane {
- position: relative;
- width: 310px;
- height: 310px;
- border: 1px solid #ccc;
- margin: 0 auto;
- }
- .tile {
- position: absolute;
- margin: 10px 0 0 10px;
- width: 65px;
- height: 65px;
- border-radius: 3px;
- font-size: 24px;
- color: #fff;
- line-height: 65px;
- text-align: center;
- transition: .5s;
- }
- .tile0 {
- background-color: #ccc;
- }
- .tile2 {
- background-color: #6bd441;
- }
- .tile4 {
- background-color: #ff8d8d;
- }
- .tile8 {
- background-color: #e4e47f;
- }
- .tile16 {
- background-color: #fba7d2;
- }
- .tile32 {
- background-color: #1f9aaa;
- }
- .tile64 {
- background-color: #0080ff;
- }
- .tile128 {
- background-color: #343399;
- }
- .tile256 {
- background-color: #c91783;
- }
- .tile512 {
- background-color: #fd0100;
- }
- .tile1024 {
- background-color: #fab418;
- }
- .tile2048 {
- background-color: #ffff01;
- }
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/index.tsx b/packages/game-react/src/views/Game2048/index.tsx
deleted file mode 100644
index 7731618..0000000
--- a/packages/game-react/src/views/Game2048/index.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import React, { useEffect, useRef, useState } from "react";
-import Core2048 from "./logic";
-import Tile from "./Tile";
-import './index.less'
-
-const instance = new Core2048()
-
-export default function() {
- const containerRef = useRef(null)
- const [data, setData] = useState(instance.getMap())
- const [score, setScore] = useState(0)
-
- const handle = (code: number) => {
- const state = instance.getState()
- if (state === 'normal') {
- instance.move(code)
- setData(() => instance.getMap())
- setScore(() => instance.getScore())
- } else {
- const timer = setTimeout(() => {
- if (state === 'fail') {
- alert('Game over!')
- } else if (state === 'finished') {
- alert('恭喜完成挑战!')
- }
- clearTimeout(timer)
- }, 300)
- }
- }
- const handleKeyDown = (e: any) => {
- const code = e.keyCode
- if (code > 36 && code < 41) {
- handle(e.keyCode)
- }
- }
- useEffect(() => {
- window.addEventListener('keydown', handleKeyDown)
- return () => {
- window.removeEventListener('keydown', handleKeyDown)
- };
- }, [])
- return (
-
-
- 分数{score}
-
-
- {
- data.map((tile, index) => (
-
- ))
- }
-
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/logic.tsx b/packages/game-react/src/views/Game2048/logic.tsx
deleted file mode 100644
index ae95014..0000000
--- a/packages/game-react/src/views/Game2048/logic.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-enum Directions {
- left = 37,
- up = 38,
- right = 39,
- down = 40,
-}
-type State = 'normal' | 'finished' | 'fail'
-
-export default class Core2048 {
- public static Scale = 4
- public static MaxValue = 2048
- private score = 0
- private state: State = 'normal'
- private map: number[] = []
- private mapHandle = [
- { valid: this.upValid, delta: Core2048.Scale * -1 },
- { valid: this.rightValid, delta: 1 },
- { valid: this.downValid, delta: Core2048.Scale },
- { valid: this.leftValid, delta: -1 },
- ]
- private mapTransform = {
- [Directions.left]: this.leftTransform,
- [Directions.up]: this.upTransform,
- [Directions.right]: this.rightTransform,
- [Directions.down]: this.downTransform,
- }
- private mapReTransform = {
- [Directions.left]: this.leftTransform,
- [Directions.up]: this.upTransform,
- [Directions.right]: this.rightTransform,
- [Directions.down]: this.reDownTransform,
- }
-
- constructor() {
- this.initMap()
- this.fileTiles(2)
- }
- public reset() {
- this.state = 'normal'
- this.score = 0
- this.initMap()
- }
- public getScore() {
- return this.score
- }
- public getState() {
- return this.state
- }
- public getMap() {
- return [...this.map]
- }
- public move(dir: Directions) {
- const result: number[] = []
- // 转换、合并
- this.merge(this.transform(this.mapTransform[dir])).forEach(line => {
- result.push(...this.mergeLine(line))
- })
- // 逆转换
- const newData = this.transform(this.mapReTransform[dir], result)
- // 更新状态
- if (newData.toString() !== this.map.toString()) {
- this.map = newData
- this.fileTiles()
- this.updateState()
- }
- }
-
- private updateState() {
- if (this.map.some(v => v === Core2048.MaxValue)) {
- this.state = 'finished'
- } else if (!this.getBlankTiles().length && this.canMerge()) {
- this.state = 'fail'
- }
- }
- private upValid(index: number) {
- return index - Core2048.Scale >= 0
- }
- private rightValid(index: number) {
- return index % Core2048.Scale !== Core2048.Scale - 1
- }
- private downValid(index: number) {
- return index + Core2048.Scale < Core2048.Scale ** 2
- }
- private leftValid(index: number) {
- return index - 1 >= 0 && index % Core2048.Scale !== 0
- }
- private canMerge() {
- return this.map.some((v, i) => {
- return this.mapHandle.some(({ valid, delta }) => {
- return valid(i) && this.map[i + delta] === v
- })
- })
- }
- private mergeLine(line: number[]) {
- const scale = Core2048.Scale
- const stack: number[] = []
- for (let i = 0; i < scale; i++) {
- const prev = line[i]
- if (prev === 0) {
- continue;
- }
- let j = i + 1
- let next = null
- for (; j < scale; j++) {
- next = line[j]
- if (next) {
- break
- }
- }
- if (prev === next) {
- const result = prev * 2
- this.score += result
- stack.push(result)
- i = j
- } else {
- stack.push(prev)
- }
- }
- const reuslt = Array.from({ length: scale }, (v, k) => stack[k] ? stack[k] : 0)
- return reuslt
- }
- private merge(map: number[]) {
- const scale = Core2048.Scale
- const lines: number[][] = []
- for (let i = 0; i < scale; i++) {
- lines.push(map.splice(0, scale))
- }
- return lines
- }
- private leftTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[i * scale + j]
- }
- private upTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[j * scale + i]
- }
- private rightTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[i * scale + (scale - j - 1)]
- }
- private downTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[(scale - j - 1) * scale + i]
- }
- private reDownTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[(j + 1) * scale - 1 - i]
- }
- private transform(handle: Function, data = this.map) {
- const scale = Core2048.Scale
- const arr: number[] = []
- for (let i = 0; i < scale; i++) {
- for (let j = 0; j < scale; j++) {
- arr.push(handle(data, i, j))
- }
- }
- return arr
- }
- private fileTiles(count = 1) {
- const blankTilesBySort = this.getBlankTiles().sort(() => Math.random() - .5)
- blankTilesBySort.splice(0, count).forEach(index => {
- this.map[index] = this.createRndNum()
- })
- }
- private getBlankTiles() {
- return this.map.reduce((r, e, i) => {
- if (!e) {
- r.push(i)
- }
- return r
- }, [])
- }
- private createRndNum() {
- return Math.random() > 0.5 ? 2 : 4
- }
- private initMap() {
- this.map = Array.from({ length: Core2048.Scale ** 2 }, () => 0)
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx"
deleted file mode 100644
index e49a73e..0000000
--- "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx"
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default (props: IProps) => {
- const clickHandle = () => {
- props.onClick(props.index)
- }
- const cls = props.value === 16 ? 'tile mark' : 'tile'
- return (
- {props.value}
- )
-}
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.less" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.less"
deleted file mode 100644
index e69de29..0000000
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx"
deleted file mode 100644
index 8eb07ae..0000000
--- "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx"
+++ /dev/null
@@ -1,10 +0,0 @@
-import React from "react"
-import './index.less'
-
-export default () => {
- return (
-
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx"
deleted file mode 100644
index 7664994..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx"
+++ /dev/null
@@ -1,30 +0,0 @@
-import React from "react"
-
-interface IProps {
- mode: 'vertical' | 'horizontal'
- index: number
- scale: number
- value: number
- onClick: (index: number) => void
-}
-export default (props: IProps) => {
- const cls = ['line', props.mode]
- if (props.value) {
- cls.push('mark')
- }
- const style: React.CSSProperties = props.mode === 'vertical'
- ? {
- top: (props.index / props.scale | 0) * 58 + 8,
- left: props.index % props.scale * 58,
- }
- : {
- top: (props.index / props.scale | 0) * 58,
- left: props.index % props.scale * 58 + 8,
- }
- const clickHandle = () => {
- props.onClick(props.index)
- }
- return (
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx"
deleted file mode 100644
index 3451c5f..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx"
+++ /dev/null
@@ -1,42 +0,0 @@
-import React from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number, mode: string, offset: number) => void
- scale: number
-}
-
-export default (props: IProps) => {
- const clickHandle = (event: React.MouseEvent) => {
- const { left, top, width, height } = (event.target as HTMLDivElement).getBoundingClientRect()
- const x = event.clientX - left
- const y = event.clientY - top
- const h = height / 2
- const w = width / 2
- const dx = x - w
- const dy = y - h
- const arc = Math.atan2(dy, dx)
- const rate = 2 * arc / Math.PI
- let offset = 0, mode = 'vertical'
- // up -1.5 -0.5
- // down 0.5 -1.5
- // right -0.5 0.5
- // left 1.5-2 -2 -1.5
- if (rate > -1.5 && rate <= -0.5) {
- offset = 0
- mode = 'horizontal'
- } else if (rate > 0.5 && rate <= 1.5) {
- offset = props.scale
- mode = 'horizontal'
- } else if (rate > -0.5 && rate <= 1.5) {
- offset = (props.index / props.scale | 0) + 1
- } else {
- offset = props.index / props.scale | 0
- }
- props.onClick(props.index, mode, offset)
- }
- return (
- {props.value > 1 ? props.value : ''}
- )
-}
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css"
deleted file mode 100644
index d6f7ba0..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css"
+++ /dev/null
@@ -1,56 +0,0 @@
-.peak-turn h1 {
- text-align: center;
-}
-.peak-turn--pane.create {
- box-shadow: 0 0 5px #dfab02;
-}
-.peak-turn--pane {
- position: relative;
- width: 356px;
- background-color: #fff;
- height: 356px;
- user-select: none;
- box-shadow: 0 0 5px #666;
- margin: 0 auto;
-}
-.peak-turn--pane .tile {
- float: left;
- width: 50px;
- height: 50px;
- background-color: #eee;
- line-height: 50px;
- text-align: center;
- font-size: 24px;
- color: #666;
- margin: 8px 0 0 8px;
-}
-.peak-turn--pane .line {
- position: absolute;
- background-color: #fff;
- transition: .5s;
-}
-.peak-turn--pane .line.mark {
- background-color: #3363c7;
-}
-.peak-turn--pane .horizontal {
- width: 50px;
- height: 8px;
- text-align: center;
-}
-.peak-turn--pane .vertical {
- width: 8px;
- height: 50px;
- line-height: 50px;
-}
-.peak-turn--bar {
- text-align: center;
- font-size: 24px;
- margin-top: 50px;
-}
-.peak-turn--bar .btn {
- margin: 0 8px;
-}
-.peak-turn--desc {
- width: 356px;
- margin: 16px auto;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx"
deleted file mode 100644
index 1793533..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx"
+++ /dev/null
@@ -1,122 +0,0 @@
-import React, { useEffect, useRef, useState } from "react"
-import './index.css'
-import Line from "./Line"
-import PeakTurn from "./logic"
-import Tile from "./Tile"
-import lz from 'lz-string'
-import copy from 'copy-to-clipboard'
-
-// mode: 1 出题,0 做题
-export default () => {
- const instRef = useRef(new PeakTurn())
- const [ans, setAns] = useState([])
- const [tiles, setTiles] = useState([])
- const [vlines, setVLines] = useState([])
- const [hlines, setHLines] = useState([])
- const [mode, setMode] = useState(0)
-
- useEffect(() => {
- document.title = '数回 - by hans0000'
- load()
- update()
- }, [])
- const load = () => {
- try {
- const data = JSON.parse(lz.decompressFromBase64(window.location.hash.slice(1))) || {}
- if (Array.isArray(data)) {
- setAns(() => data)
- setMode(() => 0)
- } else {
- setMode(() => 1)
- }
- } catch (error) {
- alert('参数错误,请确认链接正确性')
- }
- }
- const update = () => {
- const inst = instRef.current
- const clist = inst.getCList()
- setTiles(() => clist)
- setVLines(() => inst.getVList())
- setHLines(() => inst.getHList())
- if (mode === 0 && JSON.stringify(ans) === JSON.stringify(inst.getCList())) {
- alert('恭喜您完成挑战!')
- setMode(() => 1)
- }
- }
- const tileClick = (index: number, mode: string, offset: number) => {
- if (mode === 'vertical') {
- vlineClick(index + offset)
- } else {
- hlineClick(index + offset)
- }
- }
- const hlineClick = (index: number) => {
- instRef.current.toggleHList(index)
- update()
- }
- const vlineClick = (index: number) => {
- instRef.current.toggleVList(index)
- update()
- }
- const share = () => {
- if (!instRef.current.isCircle()) {
- alert('出题存在交叉或没有闭环!')
- return;
- }
- const data = instRef.current.getCList()
- const url = lz.compressToBase64(JSON.stringify(data))
- window.location.hash = url
- copy(window.location.href)
- alert('链接已复制到剪切板')
- }
- const create = () => {
- setMode(() => 1)
- instRef.current.reset()
- setAns(() => [])
- window.location.hash = ''
- update()
- }
- const cls = ['peak-turn--pane']
- if (mode === 1) {
- cls.push('create')
- }
- const redo = () => {
- instRef.current.reset()
- setMode(() => 0)
- update()
- }
- return (
-
-
数回
-
- {
- (mode === 1 ? tiles : ans).map((tile, index) => )
- }
- {
- vlines.map((line, index) => )
- }
- {
- hlines.map((line, index) => )
- }
-
-
- {
- ans.length
- ? (
-
- )
- : (
-
- )
- }
-
-
-
- - 规则:
- - 数字代表周围涂色的边的个数
- - 涂色的边要求围成一个封闭的区域,且不交叉
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts"
deleted file mode 100644
index 95d965d..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts"
+++ /dev/null
@@ -1,286 +0,0 @@
-export type ModeType = 'horizontal' | 'vertical'
-
-class Line {
- public static dir = true
- private mode: ModeType = 'horizontal';
- private value = false;
- public isVisited = false;
- private vGroup: LineGroup = null
- private hGroup: LineGroup = null
- private index: number = -1
-
- constructor(mode: ModeType, index: number, vGroup: LineGroup, hGroup: LineGroup) {
- this.mode = mode
- this.vGroup = vGroup
- this.hGroup = hGroup
- this.index = index
- }
- public toggle() {
- this.value = !this.value
- }
- public getValue() {
- return this.value
- }
- public getMode() {
- return this.mode
- }
- public next(): Line {
- const scale = PeakTurn.scale
- const index = this.index
- const max = scale * (scale + 1)
- if (this.mode === 'horizontal') {
- const row = index / scale | 0
- const col = index % scale
-
- if (Line.dir) {
- const rui = (row - 1) * (scale + 1) + col + 1
- if (rui >= 0) {
- const ru = this.vGroup.getLine(rui)
- if (ru.getValue() && !ru.isVisited) {
- ru.isVisited = true
- Line.dir = true
- return ru
- }
- }
- const ri = index + 1
- if (index % scale !== scale - 1) {
- const r = this.hGroup.getLine(ri)
- if (r.getValue() && !r.isVisited) {
- r.isVisited = true
- Line.dir = true
- return r
- }
- }
- const rdi = row * (scale + 1) + col + 1
- if (rdi < max) {
- const rd = this.vGroup.getLine(rdi)
- if (rd.getValue() && !rd.isVisited) {
- rd.isVisited = true
- Line.dir = false
- return rd
- }
- }
- } else {
- const ldi = row * (scale + 1) + col
- if (ldi < max) {
- const ld = this.vGroup.getLine(ldi)
- if (ld.getValue() && !ld.isVisited) {
- ld.isVisited = true
- Line.dir = false
- return ld
- }
- }
- const li = index - 1
- if (index % scale !== 0) {
- const l = this.hGroup.getLine(li)
- if (l.getValue() && !l.isVisited) {
- l.isVisited = true
- Line.dir = false
- return l
- }
- }
- const lui = (row - 1) * (scale + 1) + col
- if (lui >= 0) {
- const lu = this.vGroup.getLine(lui)
- if (lu.getValue() && !lu.isVisited) {
- lu.isVisited = true
- Line.dir = true
- return lu
- }
- }
- }
-
- } else {
- const row = index / (scale + 1) | 0
- const col = index % (scale + 1)
- if (Line.dir) {
- const lui = row * scale + col - 1
- if (lui >= 0) {
- const lu = this.hGroup.getLine(lui)
- if (lu.getValue() && lu.getValue() && !lu.isVisited) {
- lu.isVisited = true
- Line.dir = false
- return lu
- }
- }
- const ui = index - scale - 1
- if (ui >= 0) {
- const u = this.vGroup.getLine(ui)
- if (u.getValue() && u.getValue() && !u.isVisited) {
- u.isVisited = true
- Line.dir = true
- return u
- }
- }
- const rui = row * scale + col
- if (col !== scale) {
- const ru = this.hGroup.getLine(rui)
- if (ru.getValue() && !ru.isVisited) {
- ru.isVisited = true
- Line.dir = true
- return ru
- }
- }
- } else {
- const rdi = (row + 1) * scale + col
- if (rdi < max && col !== scale) {
- const rd = this.hGroup.getLine(rdi)
- if (rd.getValue() && !rd.isVisited) {
- rd.isVisited = true
- Line.dir = true
- return rd
- }
- }
- const di = index + scale + 1
- if (di < max) {
- const d = this.vGroup.getLine(di)
- if (d.getValue() && !d.isVisited) {
- d.isVisited = true
- Line.dir = false
- return d
- }
- }
- const ldi = (row + 1) * scale + col - 1
- if (col !== 0) {
- const ld = this.hGroup.getLine(ldi)
- if (ld.getValue() && !ld.isVisited) {
- ld.isVisited = true
- Line.dir = false
- return ld
- }
- }
- }
- }
- return null
- }
-}
-
-class LineGroup {
- private mode: ModeType = 'horizontal';
- private scale: number = 0;
- private list: Line[] = [];
-
- constructor(mode: ModeType, scale: number) {
- this.mode = mode
- this.scale = scale
- }
- public init(vGroup: LineGroup, hGroup: LineGroup) {
- const length = this.scale * (this.scale + 1)
- this.list = Array.from({ length }, (_, index) => new Line(this.mode, index, vGroup, hGroup))
- }
- public toggle(index: number) {
- this.list[index].toggle()
- }
- public getMode() {
- return this.mode
- }
- public getList() {
- return this.list.map(v => +v.getValue())
- }
- public getLine(index: number) {
- return this.list[index]
- }
- public getFirstIndex() {
- return this.list.findIndex(v => v.getValue())
- }
- public isWholeVisited() {
- return !this.list.some(item => !!item.getValue() && !item.isVisited)
- }
- public resetStatus() {
- this.list.forEach(e => e.isVisited = false)
- }
-}
-
-export default class PeakTurn {
- public static scale = 6
- private hGroup: LineGroup
- private vGroup: LineGroup
- private cList: number[] = []
- private mode: number = 1
-
- constructor() {
- this.init()
- }
- public getVGroup() {
- return this.vGroup
- }
- public getHGroup() {
- return this.hGroup
- }
- public setMode(mode: number) {
- this.mode = mode
- }
- public reset() {
- this.init()
- }
- private init() {
- const scale = PeakTurn.scale
- this.hGroup = new LineGroup('horizontal', scale)
- this.vGroup = new LineGroup('vertical', scale)
- this.hGroup.init(this.vGroup, this.hGroup)
- this.vGroup.init(this.vGroup, this.hGroup)
- this.cList = Array.from({ length: scale ** 2 }, () => 0)
- }
- public isCircle() {
- const index = this.vGroup.getFirstIndex()
- if (index === -1) {
- return false
- }
- const first = this.vGroup.getLine(index)
- let line = first
- let count = 0
- while (line) {
- count++
- line = line.next()
- if (line === null) {
- this.resetStatus()
- return false
- }
- if (line === first) {
- break
- }
- }
- if (count < 4) {
- this.resetStatus()
- return false
- }
- const flag = this.vGroup.isWholeVisited() && this.hGroup.isWholeVisited()
- this.resetStatus()
- return flag
- }
- private resetStatus() {
- this.vGroup.resetStatus()
- this.hGroup.resetStatus()
- Line.dir = true
- }
-
- public getHList() {
- return this.hGroup.getList()
- }
- public getVList() {
- return this.vGroup.getList()
- }
- public getCList() {
- return [...this.cList]
- }
- public toggleHList(index: number) {
- this.hGroup.toggle(index)
- !!this.mode && this.update()
- }
- public toggleVList(index: number) {
- this.vGroup.toggle(index)
- !!this.mode && this.update()
- }
- private update() {
- const scale = PeakTurn.scale
- this.cList.forEach((_, index) => {
- const row = index / scale | 0
- const col = index % scale
- const up = +this.hGroup.getLine(row * scale + col).getValue()
- const down = +this.hGroup.getLine(scale * (row + 1) + col).getValue()
- const left = +this.vGroup.getLine(row * (scale + 1) + col).getValue()
- const right = +this.vGroup.getLine(row * (scale + 1) + col + 1).getValue()
- this.cList[index] = up + down + left + right
- })
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx"
deleted file mode 100644
index 79c7c08..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React from "react";
-import { DirKind } from "./logic";
-import Tile from "./Tile";
-
-interface IProps {
- data: number[]
- onMove: (index: number, dir: DirKind) => void
-}
-
-export default function Pane(props: IProps) {
- return (
-
- {
- props.data.map((item, index) => {
- return (
- props.onMove(index, dir)}/>
- )
- })
- }
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx"
deleted file mode 100644
index 38631e8..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx"
+++ /dev/null
@@ -1,61 +0,0 @@
-import React, { useState } from "react";
-import { clsx } from "../../utils";
-import { DirKind, SpriteKind } from "./logic";
-
-interface IProps {
- value: SpriteKind
- index: number
- onMove: (dir: DirKind) => void
-}
-
-export default function Tile(props: IProps) {
- const [hold, setHold] = useState(false)
-
- const valids = React.useMemo(
- () => {
- const flag = hold && (props.value === SpriteKind.Star || props.value === SpriteKind.Stone)
- const obj = {
- up: flag,
- right: flag,
- down: flag,
- left: flag,
- }
- return obj
- },
- [props.index, hold, props.value]
- )
-
- return (
- {
- if (props.value) {
- setHold(hold => !hold)
- }
- }}>
- { valids.up &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Up)
- }}>
}
- { valids.right &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Right)
- }}>
}
- { valids.down &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Down)
- }}>
}
- { valids.left &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Left)
- }}>
}
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css"
deleted file mode 100644
index 940aefa..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css"
+++ /dev/null
@@ -1,75 +0,0 @@
-.game03 {
- user-select: none;
-}
-.game03 .pane {
- width: 452px;
- margin: 50px auto;
- border: 2px solid #aaa;
- overflow: hidden;
-}
-
-.game03 .tile {
- position: relative;
- float: left;
- width: 56px;
- height: 56px;
- border: 2px solid #aaa;
- background-color: #eee;
-}
-
-.game03 .tile.stone {
- background-color: #929292;
-}
-
-.game03 .tile.target {
- background-color: #76efff;
-}
-
-.game03 .tile.star {
- background-color: #fded07;
-}
-
-.game03 .tile .up {
- position: absolute;
- height: 0;
- width: 0;
- left: 0;
- top: -56px;
- border: 26px solid transparent;
- border-bottom-color: bisque;
-}
-
-.game03 .tile .down {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: 0;
- top: 54px;
- border: 26px solid transparent;
- border-top-color: bisque;
-}
-
-
-.game03 .tile .left {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: -56px;
- top: 0;
- border: 26px solid transparent;
- border-right-color: bisque;
-}
-
-
-.game03 .tile .right {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: 54px;
- top: 0;
- border: 26px solid transparent;
- border-left-color: bisque;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx"
deleted file mode 100644
index 87c7d14..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx"
+++ /dev/null
@@ -1,37 +0,0 @@
-import React, { useState } from "react";
-import useGesture from "../../hooks/useGesture";
-import './index.css'
-import { Logic } from "./logic";
-import Pane from "./Pane";
-
-const game = new Logic([
- 0, 0, 0, 0, 0, 0, 0, 1,
- 0, 2, 0, 0, 0, 1, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 3, 0, 0, 1,
- 0, 0, 0, 0, 0, 1, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0, 1, 0, 0, 1, 0, 0,
-])
-
-export default function Game03() {
-
- const [data, setData] = useState(game.getMap())
- const ref = useGesture((dir) => {
- console.log(dir)
- })
-
- return (
-
-
{
- setData(game.move(index, dir))
- setTimeout(() => {
- if (game.isOk()) {
- alert('success')
- }
- }, 0);
- }} />
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts"
deleted file mode 100644
index 3b2873e..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts"
+++ /dev/null
@@ -1,102 +0,0 @@
-
-export enum SpriteKind {
- Empty,
- Stone,
- Star,
- Target,
-}
-
-export enum DirKind {
- Up,
- Right,
- Down,
- Left,
-}
-
-export class Logic {
- private map: number[] = []
- private success = false
-
- public static Scale = 8
-
- constructor(map?: number[]) {
- this.success = false
- this.map = map ? map : Array.from({ length: Logic.Scale ** 2 }, () => SpriteKind.Empty)
- }
-
- public getMap() { return [...this.map] }
-
- private getOffset(row: number, col: number) {
- return Logic.Scale * row + col
- }
-
- private getData(row: number, col: number) {
- return this.map[this.getOffset(row, col)]
- }
-
- public isOk() {
- return this.success
- }
-
- private isValid(row: number, col: number, cx: number, cy: number) {
- return (
- cx >= 0 &&
- cy >= 0 &&
- cx < Logic.Scale &&
- cy < Logic.Scale
- )
- }
-
- public move(index: number, dir: DirKind) {
- const offsetVectors = [ [0, -1], [1, 0], [0, 1], [-1, 0] ]
- const [vx, vy] = offsetVectors[dir]
-
- const row = index / Logic.Scale | 0
- const col = index % Logic.Scale
-
- let cx = col
- let cy = row
-
- while (true) {
- cy += vy
- cx += vx
- const next = this.getData(cy, cx)
-
- // 出界
- if (! this.isValid(row, col, cx, cy)) {
- this.map[this.getOffset(row, col)] = SpriteKind.Empty
- break
- }
-
- // 碰撞
- if (next && next !== SpriteKind.Target) {
- const newIndex = this.getOffset(cy - vy, cx - vx)
- if (this.map[newIndex] === SpriteKind.Target) {
- this.success = true
- }
- this.map[newIndex] = this.map[index]
- if (newIndex !== this.getOffset(row, col)) {
- this.map[this.getOffset(row, col)] = SpriteKind.Empty
- }
- break
- }
- }
- return this.getMap()
- }
-
- public moveUp(index: number) {
- return this.move(index, DirKind.Up)
- }
-
- public moveRight(index: number) {
- return this.move(index, DirKind.Right)
- }
-
- public moveDown(index: number) {
- return this.move(index, DirKind.Down)
- }
-
- public moveLeft(index: number) {
- return this.move(index, DirKind.Left)
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx"
deleted file mode 100644
index dd5282f..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: number[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx"
deleted file mode 100644
index ac0b608..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value === 16 ? 'tile mark' : 'tile'
- return (
- {this.props.value}
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less"
deleted file mode 100644
index d466324..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less"
+++ /dev/null
@@ -1,31 +0,0 @@
-.number-puzzle {
- margin: 0 auto;
- width: 428px;
- overflow: hidden;
- user-select: none;
-}
-.number-puzzle .pane {
- overflow: hidden;
- padding: 4px;
- margin: 0 auto;
- border: 10px solid #aaa;
-}
-.number-puzzle .ctrl {
- text-align: center;
- margin-bottom: 20px;
-}
-.number-puzzle .tile {
- float: left;
- width: 92px;
- height: 92px;
- margin: 4px;
- background-color: #eee;
- line-height: 98px;
- text-align: center;
- font-size: 32px;
-}
-.number-puzzle .tile.mark {
- background-color: #fff;
- color: #fff;
- box-shadow: 0 0 4px #eee;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx"
deleted file mode 100644
index 33ccc6c..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx"
+++ /dev/null
@@ -1,60 +0,0 @@
-import React, { Component } from 'react';
-import Pane from './Pane';
-import { initData, exchange, clear } from './logic';
-import './index.less'
-
-interface IState {
- data: number[];
-}
-
-export default class NumberPuzzle extends Component<{}, IState> {
- private static dataString = JSON.stringify(clear())
- private data: number[] = clear();
- private isRunning = false;
-
- public state: IState = {
- data: clear()
- }
- private clickHandle = (index: number) => {
- const data = exchange(this.state.data, index)
- this.setState({ data })
- if (this.isRunning) {
- if (JSON.stringify(data) === NumberPuzzle.dataString) {
- alert('挑战成功!')
- }
- }
- }
- private reset = () => {
- this.isRunning = true;
- this.setState({
- data: this.data
- })
- }
- private clear = () => {
- this.isRunning = false;
- this.setState({
- data: clear()
- })
- }
- private generate = () => {
- this.isRunning = true
- const data = initData()
- this.data = data
- this.setState({
- data
- })
- }
- public render() {
- return (
-
-
-
数字华容道
-
-
-
-
-
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts"
deleted file mode 100644
index 738b9b1..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts"
+++ /dev/null
@@ -1,63 +0,0 @@
-export const ROW = 4;
-const BLANK_NUMBER = ROW ** 2 // 代表空白的数字
-
-function valid(data: number[]) {
- let count = 0;
- mergeSort(data, count);
- return count % 2 === 0;
-}
-function merge(left: number[], right: number[], count: number) {
- const tmp = [];
- while (left.length && right.length) {
- if (left[0] > right[0]) {
- tmp.push(left.shift());
- count++;
- } else {
- tmp.push(right.shift());
- }
- }
- return tmp.concat(left, right);
-}
-function mergeSort(arr: number[], count: number): number[] {
- const len = arr.length;
- if (len === 1) return arr;
- const mid = len / 2 | 0;
- const left = arr.slice(0, mid);
- const right = arr.slice(mid);
- return merge(mergeSort(left, count), mergeSort(right, count), count);
-}
-function shuffle(data: number[]) {
- let len = data.length;
- for (let i = 0; i < len; i++) {
- let m = Math.random() * (len - i) | 0;
- [data[len - i - 1], data[m]] = [data[m], data[len - i - 1]];
- }
- return data;
-}
-export function exchange(data: number[], index: number) {
- const newData = [...data]
- const offset = [-1, 0, 0, 1, 1, 0, 0, -1]
- for (let i = 0; i < offset.length; i+=2) {
- const oy = offset[i];
- const ox = offset[i + 1];
- const newIndex = index + oy * ROW + ox;
- if (newData[newIndex] === BLANK_NUMBER) {
- [newData[newIndex], newData[index]] = [newData[index], newData[newIndex]]
- break
- }
- }
- return newData
-}
-export function clear() {
- return Array.from({ length: ROW ** 2 }, (_, i) => i + 1);
-}
-export function initData() {
- const data = clear();
- while (1) {
- shuffle(data);
- if (valid(data)) {
- break;
- }
- }
- return data
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx"
deleted file mode 100644
index cf07770..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx"
+++ /dev/null
@@ -1,25 +0,0 @@
-import React, { Component } from 'react'
-import { ROW, G_WIDTH, ROW_DOT, WIDTH_DOT } from './logic'
-
-interface IProps {
- index: number;
- value: number;
- onClick: (index: number) => void;
-}
-interface IState {}
-
-export default class Dot extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.value)
- }
- render() {
- const row = (this.props.index / ROW_DOT | 0) + 1
- const col = this.props.index % ROW_DOT + 1
- const unit = G_WIDTH / ROW
- const top = row * unit - WIDTH_DOT / 2 + 10
- const left = col * unit - WIDTH_DOT / 2 + 10
- return (
- ↻
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx"
deleted file mode 100644
index ca99869..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx"
+++ /dev/null
@@ -1,35 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-import Dot from './Dot'
-import { initDotList } from './logic';
-
-interface IProps {
- data: number[];
- onClick: (index: number) => void;
-}
-interface IState { }
-
-export default class Pane extends Component {
- public static dotList: number[] = initDotList();
-
- render() {
- return (
-
-
- {
- this.props.data.map((v, i) => )
- }
-
-
- {
- Pane.dotList.map((v, i) => {
- return (
-
- )
- })
- }
-
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx"
deleted file mode 100644
index a07b242..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx"
+++ /dev/null
@@ -1,16 +0,0 @@
-import React, { Component } from 'react'
-import { G_WIDTH, ROW } from './logic'
-
-interface IProps {
- value: number;
-}
-interface IState {}
-
-export default class Tile extends Component {
- render() {
- const width = G_WIDTH / ROW
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less"
deleted file mode 100644
index c95bca3..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less"
+++ /dev/null
@@ -1,65 +0,0 @@
-@color1: #ff7a00;
-@color2: #4e4eff;
-@color3: #449d04;
-@color4: #ebc808;
-
-.four-colors-pane {
- user-select: none;
- .ctrl {
- text-align: center;
- margin-bottom: 20px;
- }
- .pane {
- position: relative;
- overflow: hidden;
- width: 380px;
- height: 380px;
- padding: 10px;
- margin: 0 auto;
- background: linear-gradient(90deg, @color3 50%, @color4 50%);
- &::before {
- content: '';
- position: absolute;
- width: 100%;
- height: 50%;
- top: 0;
- left: 0;
- background: linear-gradient(90deg, @color1 50%, @color2 50%);
- }
- }
- .tile-cont {
- position: relative;
- height: 100%;
- .tile {
- float: left;
- border: 1px solid #eee;
- box-sizing: border-box;
- }
- .tile.tile-0 {
- background-color: @color1;
- }
- .tile.tile-1 {
- background-color: @color2;
- }
- .tile.tile-2 {
- background-color: @color3;
- }
- .tile.tile-3 {
- background-color: @color4;
- }
- }
- .dot-cont {
- .dot {
- position: absolute;
- width: 28px;
- height: 28px;
- text-align: center;
- line-height: 28px;
- border-radius: 50%;
- color: #999;
- cursor: pointer;
- background-color: #eee;
- box-shadow: 1px 1px 6px rgba(0,0,0,.2);
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx"
deleted file mode 100644
index 17c93dd..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx"
+++ /dev/null
@@ -1,67 +0,0 @@
-import React, { Component } from 'react';
-import Pane from './Pane';
-import { initData, turn, getRandNum } from './logic';
-import './index.less'
-
-interface IState {
- data: number[];
-}
-
-export default class RotateJigsaw extends Component<{}, IState> {
- public static dataString = JSON.stringify(initData());
- private data: number[];
- private isRunning = false;
-
- public state: IState = {
- data: initData()
- }
- private clickHandle = (index: number) => {
- const data = turn(this.state.data, index)
- this.setState({ data })
- if (this.isRunning) {
- if (JSON.stringify(data) === RotateJigsaw.dataString) {
- alert('挑战成功!')
- }
- }
- }
- private reset = () => {
- this.isRunning = true;
- if (this.data?.length) {
- this.setState({
- data: this.data
- })
- }
- }
- private clear = () => {
- this.isRunning = false;
- this.setState({
- data: initData()
- })
- }
- private generate = () => {
- let count = Pane.dotList.length
- let data = this.state.data;
- this.isRunning = true;
-
- while (count--) {
- const num = Pane.dotList[getRandNum(Pane.dotList.length)]
- data = turn(data, num)
- }
- this.data = data
- this.setState({
- data
- })
- }
- public render() {
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts"
deleted file mode 100644
index ee7ba6a..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts"
+++ /dev/null
@@ -1,38 +0,0 @@
-export const ROW = 6 // 色块行数,同时也是列数
-export const G_WIDTH = 360 //容器宽度,
-export const WIDTH_DOT = 28 // 旋钮大小
-export const ROW_DOT = ROW - 1 // 旋钮行数
-
-export function initDotList() {
- const row = ROW - 1
- return Array.from({ length: (row ** 2) }, (_ ,i) => {
- return (i / row | 0) * ROW + i % row
- })
-}
-
-const total = ROW ** 2
-
-export function getRandNum(max: number) {
- return Math.random() * max | 0
-}
-
-export function initData() {
- return Array.from({ length: total }, (_, i) => {
- const row = (i / ROW | 0) >= ROW / 2 ? 1 : 0
- const col = i % ROW >= ROW / 2 ? 1 : 0
- return row * 2 + col
- })
-}
-
-export function turn(sourceData: number[], index: number) {
- const data = [...sourceData]
- const offset = [[0, 0], [0, 1], [1, 1], [1, 0]]
- for (let i = 0; i < offset.length; i++) {
- const [y1, x1] = offset[i]
- const [y2, x2] = offset[(i + 1) % 4]
- const prev = index + y1 * ROW + x1
- const next = index + y2 * ROW + x2
- data[next] = sourceData[prev]
- }
- return data
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx"
deleted file mode 100644
index d1e1ef1..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css"
deleted file mode 100644
index 2ce33e3..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css"
+++ /dev/null
@@ -1,33 +0,0 @@
-
-.number-sweep {
- margin: 30px auto;
- overflow: hidden;
- width: 840px;
-}
-.number-sweep .pane {
- float: left;
- width: 240px;
- height: 240px;
- margin: 20px;
-}
-
-.number-sweep .tile {
- float: left;
- width: 28px;
- height: 28px;
- background-color: #eee;
- margin: 1px;
-}
-.number-sweep .tile.mark {
- background-color: #333;
-}
-.number-sweep .tile:hover {
- opacity: .7;
-}
-h1 {
- text-align: center;
- margin-bottom: 16px;
-}
-.number-sweep .ctrl {
- text-align: center;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx"
deleted file mode 100644
index 4f2a3b8..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx"
+++ /dev/null
@@ -1,86 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.css'
-
-interface IProps { }
-interface IState {
- data: boolean[]
-}
-
-const ROW = 8
-const HEIGHT = 6
-const COUNT = ROW ** 2
-const TOTAL_COUNT = COUNT * HEIGHT
-
-export default class BlackWhiteTurn extends Component {
-
- public state: IState = {
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- }
- private clickHandle = (index: number) => {
- this.findUpdateNodes(index)
- }
- private findUpdateNodes = (index: number) => {
- const data = [...this.state.data]
- // 前右下左上下
- const offset = [0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 1]
- // 查找周围,取反
- for (let i = 0; i < offset.length; i+=3) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const oz = offset[i + 2]
- const newIndex = index + oy * ROW + ox + COUNT * oz
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= TOTAL_COUNT) {
- continue
- }
- const zIndex = index / COUNT | 0
- const zNewIndex = newIndex / COUNT | 0
- if (zIndex === zNewIndex) {
- /* eslint-disable */
- if (index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- /* eslint-enable */
- } else {
- if (index !== newIndex + COUNT && index !== newIndex - COUNT) {
- continue
- }
- }
- data[newIndex] = !data[newIndex]
- }
- this.setState({
- data
- })
- }
- private reset = () => {
- this.setState({
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- })
- }
- private slice() {
- const data = [...this.state.data]
- const result = []
- const count = ROW ** 2
- while(data.length) {
- result.push(data.splice(0, count))
- }
- return result
- }
- public render() {
- return (
-
-
-
-
- {
- this.slice().map((data, index) => (
-
this.clickHandle(pos + index * COUNT)} />
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts"
deleted file mode 100644
index 54a0c23..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts"
+++ /dev/null
@@ -1,124 +0,0 @@
-const ROW = 8 // 行数,同时也是列数
-const G_WIDTH = 480 //容器宽度,
-
-const total = ROW ** 2
-const MAX_NUMBER = 100
-
-function getRandNum(max: number, min = 0) {
- return min + Math.random() * max | 0
-}
-
-function canVerticalLink(data: number[], p1: number, p2: number) {
- const [y1, x1] = convert(p1);
- const [y2, x2] = convert(p2);
- if (x1 !== x2) {
- return false
- }
- const [yMin, yMax] = y1 <= y2 ? [y1, y2] : [y2, y1]
- for (let i = yMin + 1; i < yMax; i++) {
- if (data[x1 + ROW * i]) {
- return false
- }
- }
- return true
-}
-function canHorizonLinK(data: number[], p1: number, p2: number) {
- const [y1, x1] = convert(p1);
- const [y2, x2] = convert(p2);
- if (y1 !== y2) {
- return false
- }
- const [xMin, xMax] = x1 <= x2 ? [x1, x2] : [x2, x1]
- for (let i = xMin + 1; i < xMax; i++) {
- if (data[y1 * ROW + i]) {
- return false
- }
- }
- return true
-}
-
-function initData() {
- const data = Array.from({ length: total }, (_, i) => i)
- const num = getRandNum(MAX_NUMBER, 1)
-
- return [0]
-}
-function convert(index: number) {
- return [index / ROW | 0, index % ROW]
-}
-function canSweep(sourceData: number[], prev: number, next: number) {
- const [r1, c1] = convert(prev)
- const [r2, c2] = convert(next)
- // const [minCol, maxCol] = c1 <= c2 ? [c1, c2] : [c2, c1]
- // const [minRow, maxRow] = r1 <= r2 ? [r1, r2] : [r2, r1]
-
- // horizontal
- for (let i = 0; i < ROW; i++) {
- const p1 = ROW * r1 + i
- if (prev !== p1 && sourceData[p1]) {
- continue
- }
- if (!canHorizonLinK(sourceData, prev, ROW * r1 + i)) {
- continue
- }
- const p2 = ROW * r2 + i
- if (next !== p2 && sourceData[p2]) {
- continue
- }
- if (!canHorizonLinK(sourceData, p2, next)) {
- continue
- }
- if (i === 0 || i === ROW - 1) {
- return true
- }
- if (!canVerticalLink(sourceData, p1, p2)) {
- continue
- }
- return true
- }
- // vertical
- for (let i = 0; i < ROW; i++) {
- const p1 = ROW * i + c1
- if (prev !== p1 && sourceData[p1]) {
- continue
- }
- if (!canVerticalLink(sourceData, prev, p1)) {
- continue
- }
- const p2 = ROW * i + c2
- if (next !== p2 && sourceData[p2]) {
- continue
- }
- if (!canVerticalLink(sourceData, p2, next)) {
- continue
- }
- if (i === 0 || i === ROW - 1) {
- return true
- }
- if (!canHorizonLinK(sourceData, p1, p2)) {
- continue
- }
- return true
- }
- return false
-}
-
-function sweep(sourceData: number[], prev: number, next: number) {
-
-}
-
-const data = [
- 0, 9, 1, 1, 0, 0, 0, 0, // 7
- 0, 0, 1, 0, 0, 0, 0, 0, // 15
- 0, 0, 1, 9, 0, 0, 0, 0, // 23
- 0, 0, 1, 0, 0, 0, 0, 0, // 31
- 0, 0, 1, 0, 0, 0, 0, 0, // 39
- 0, 0, 1, 0, 0, 0, 0, 0, // 47
- 0, 0, 0, 0, 0, 0, 0, 0, // 55
- 0, 0, 1, 1, 0, 0, 0, 0,
-]
-
-console.log(canSweep(data, 1, 19));
-// console.log(canVerticalLink(data, 1, 17));
-
-export default {}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx"
deleted file mode 100644
index d1e1ef1..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less"
deleted file mode 100644
index 1b5dbe7..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less"
+++ /dev/null
@@ -1,34 +0,0 @@
-
-.black-white-turn2 {
- margin: 0 auto;
- overflow: hidden;
- width: 840px;
-
- .pane {
- float: left;
- width: 240px;
- height: 240px;
- margin: 20px;
- }
-
- .tile {
- float: left;
- width: 28px;
- height: 28px;
- background-color: #eee;
- margin: 1px;
- }
- .tile.mark {
- background-color: #333;
- }
- .tile:hover {
- opacity: .7;
- }
- h1 {
- text-align: center;
- margin-bottom: 16px;
- }
- .ctrl {
- text-align: center;
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx"
deleted file mode 100644
index 0aae84e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx"
+++ /dev/null
@@ -1,84 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.less'
-
-interface IProps { }
-interface IState {
- data: boolean[]
-}
-
-const ROW = 8
-const HEIGHT = 6
-const COUNT = ROW ** 2
-const TOTAL_COUNT = COUNT * HEIGHT
-
-export default class BlackWhiteTurn extends Component {
-
- public state: IState = {
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- }
- private clickHandle = (index: number) => {
- this.findUpdateNodes(index)
- }
- private findUpdateNodes = (index: number) => {
- const data = [...this.state.data]
- // 前右下左上下
- const offset = [0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 1]
- // 查找周围,取反
- for (let i = 0; i < offset.length; i+=3) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const oz = offset[i + 2]
- const newIndex = index + oy * ROW + ox + COUNT * oz
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= TOTAL_COUNT) {
- continue
- }
- const zIndex = index / COUNT | 0
- const zNewIndex = newIndex / COUNT | 0
- if (zIndex === zNewIndex) {
- if (index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- } else {
- if (index !== newIndex + COUNT && index !== newIndex - COUNT) {
- continue
- }
- }
- data[newIndex] = !data[newIndex]
- }
- this.setState({
- data
- })
- }
- private reset = () => {
- this.setState({
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- })
- }
- private slice() {
- const data = [...this.state.data]
- const result = []
- const count = ROW ** 2
- while(data.length) {
- result.push(data.splice(0, count))
- }
- return result
- }
- public render() {
- return (
-
-
-
-
- {
- this.slice().map((data, index) => (
-
this.clickHandle(pos + index * COUNT)} />
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx"
deleted file mode 100644
index b6ae0da..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx"
+++ /dev/null
@@ -1,21 +0,0 @@
-import React, { Component } from 'react'
-import { convert } from '.'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less"
deleted file mode 100644
index e75ef49..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less"
+++ /dev/null
@@ -1,29 +0,0 @@
-
-.black-white-turn {
- margin: 0 auto;
- width: 400px;
- overflow: hidden;
-
- .tile {
- float: left;
- width: 48px;
- height: 48px;
- background-color: #eee;
- margin: 1px;
- }
- .tile.mark {
- background-color: #333;
- }
- .tile:hover {
- opacity: .7;
- }
- h1 {
- text-align: center;
- margin-bottom: 16px;
- }
- .ctrl {
- text-align: center;
- margin-bottom: 20px;
- }
-
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx"
deleted file mode 100644
index a72c5a8..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx"
+++ /dev/null
@@ -1,142 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.less'
-
-interface IProps { }
-interface IState {
- data: boolean[],
- coordinate: number[][],
-}
-
-const ROW = 8
-
-function turn(sourceData: boolean[], index: number) {
- const data = [...sourceData]
- const offset = [0, 0, -1, 0, 0, 1, 1, 0, 0, -1]
- // 查找四周,取反
- for (let i = 0; i < offset.length; i+=2) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const newIndex = index + oy * ROW + ox
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= ROW * ROW ||
- index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- data[newIndex] = !data[newIndex]
- }
- return data
-}
-export function convert(index: number) {
- return [index / ROW | 0, index % ROW]
-}
-function getFlipX(index: number) {
- const [row, col] = convert(index)
- return ROW * row + 7 - col
-}
-function countBlackTiles(data: boolean[]) {
- return data.reduce((s, v) => v ? s + 1 : s, 0)
-}
-function filter(path: number[]) {
- path = path.sort((a, b) => a - b)
- return path.reduce((s, v) => {
- if (s[s.length - 1] === v) {
- s.pop()
- } else {
- s.push(v)
- }
- return s
- }, [])
-}
-export default class BlackWhiteTurn extends Component {
- private isRunning = false;
- private path: number[] = []
-
- public state: IState = {
- data: Array.from({ length: ROW ** 2 }, () => false),
- coordinate: [],
- }
- private clickHandle = (index: number) => {
- const data = turn(this.state.data, index)
- this.setState({
- data
- }, () => {
- if (this.isRunning) {
- const isOver = this.state.data.every(v => v === false)
- if (isOver) {
- alert('挑战成功!')
- this.isRunning = false
- }
- }
- })
- }
- private generate = () => {
- this.isRunning = true
- let data = Array.from({ length: ROW ** 2 }, () => false)
- this.path = []
- while(1) {
- const count = countBlackTiles(data)
- if (count > 35 && count < 50) {
- break
- }
- const num = Math.random() * 64 | 0;
- data = turn(data, num)
- const num2 = getFlipX(num)
- data = turn(data, num2)
- this.path.push(num, num2)
- }
- this.setState({
- data,
- coordinate: [],
- })
- }
- private reset = () => {
- this.isRunning = true
- let initData = Array.from({ length: ROW ** 2 }, () => false)
- const data = this.path.reduce((s, v) => {
- s = turn(s, v)
- return s
- }, initData)
- this.setState({
- data
- })
- }
- private clear = () => {
- this.isRunning = false
- this.setState({
- data: Array.from({ length: ROW ** 2 }, () => false),
- coordinate: [],
- })
- }
- private cheat = () => {
- const path = filter(this.path)
- console.log(path);
-
- this.setState({
- coordinate: path.map(v => convert(v))
- })
- }
- public render() {
- return (
-
-
-
黑白迭代
-
-
-
-
-
-
-
- {
- this.state.coordinate.map((arr, index) => {
- return {`(${arr[0]}, ${arr[1]})`}
- })
- }
-
-
- )
- }
-}
diff --git a/packages/game-react/src/vite-env.d.ts b/packages/game-react/src/vite-env.d.ts
deleted file mode 100644
index 11f02fe..0000000
--- a/packages/game-react/src/vite-env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/packages/game-react/tsconfig.json b/packages/game-react/tsconfig.json
deleted file mode 100644
index 13bbfbb..0000000
--- a/packages/game-react/tsconfig.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "compilerOptions": {
- "target": "ESNext",
- "useDefineForClassFields": true,
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
- "allowJs": false,
- "skipLibCheck": false,
- "esModuleInterop": false,
- "allowSyntheticDefaultImports": true,
- "strict": true,
- "strictNullChecks": false,
- "forceConsistentCasingInFileNames": true,
- "module": "ESNext",
- "moduleResolution": "Node",
- "resolveJsonModule": true,
- "isolatedModules": true,
- "noEmit": true,
- "jsx": "react-jsx",
- },
- "include": ["src"],
- "references": [{ "path": "./tsconfig.node.json" }]
-}
diff --git a/packages/game-react/tsconfig.node.json b/packages/game-react/tsconfig.node.json
deleted file mode 100644
index e993792..0000000
--- a/packages/game-react/tsconfig.node.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "compilerOptions": {
- "composite": true,
- "module": "esnext",
- "moduleResolution": "node"
- },
- "include": ["vite.config.ts"]
-}
diff --git a/packages/game-react/vite.config.ts b/packages/game-react/vite.config.ts
deleted file mode 100644
index 0e6a3ae..0000000
--- a/packages/game-react/vite.config.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { defineConfig } from 'vite'
-import react from '@vitejs/plugin-react'
-import { resolve } from 'path'
-
-// https://vitejs.dev/config/
-export default defineConfig({
- base: './',
- css: {
- preprocessorOptions: {
- less: { javascriptEnabled: true }
- }
- },
- build: {
- outDir: resolve('../..', './docs/game-react'),
- target: 'esnext',
- assetsDir: './',
- // minify: false,
- // polyfillModulePreload: false,
- // rollupOptions: {
- // output: {
- // format: 'iife',
- // globals: {
- // 'react': 'React',
- // 'lz-string': 'LZString',
- // 'react-dom': 'ReactDOM',
- // 'react-router': 'ReactRouter',
- // 'react-router-dom': 'ReactRouterDOM',
- // },
- // },
- // external: [
- // 'react',
- // 'lz-string',
- // 'react-dom',
- // 'react-router',
- // 'react-router-dom',
- // ],
- // },
- },
- plugins: [
- react(),
- ]
-})
diff --git a/packages/game-vanilla/.npmrc b/packages/game-vanilla/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-vanilla/package.json b/packages/game-vanilla/package.json
deleted file mode 100644
index cab964b..0000000
--- a/packages/game-vanilla/package.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "game-vanilla",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "build": "node ./script.mjs"
- },
- "keywords": [],
- "author": "",
- "license": "ISC",
- "devDependencies": {
- "fs-extra": "^10.1.0",
- "globby": "^13.1.2"
- }
-}
diff --git a/packages/game-vanilla/readme.md b/packages/game-vanilla/readme.md
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-vanilla/script.mjs b/packages/game-vanilla/script.mjs
deleted file mode 100644
index 0651006..0000000
--- a/packages/game-vanilla/script.mjs
+++ /dev/null
@@ -1,17 +0,0 @@
-import fse from 'fs-extra'
-import { resolve, join, dirname } from 'path'
-import { globby } from 'globby'
-
-const distDir = resolve('../../docs', 'game-vanilla')
-
-globby('./src/**').then(paths => {
- paths.forEach(path => {
- const targetPath = resolve(path)
- const distPath = join(distDir, path.slice(5))
- const dir = dirname(distPath)
- if (! fse.existsSync(dir)) {
- fse.mkdirSync(dir, { recursive: true })
- }
- fse.copyFileSync(targetPath, distPath)
- })
-})
\ No newline at end of file
diff --git a/packages/game-vanilla/src/blockout-2/index.html b/packages/game-vanilla/src/blockout-2/index.html
deleted file mode 100644
index 46bea28..0000000
--- a/packages/game-vanilla/src/blockout-2/index.html
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
- Document
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-