Commit 2a9be4b5 authored by wildfirecode's avatar wildfirecode

1

parent c83d161f
No preview for this file type
node_modules
\ No newline at end of file
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "启动 Chrome 并打开 localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
\ No newline at end of file
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- <script src="phaser-matter-physics.js"></script> -->
<script src="phaser-duiba.min.js"></script>
<script src="output.js"></script>
</body>
</html>
\ No newline at end of file
!function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:t})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n){console.log("hello")}]);
//# sourceMappingURL=output.js.map
\ No newline at end of file
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/index.ts"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","r","value","n","__esModule","default","object","property","prototype","hasOwnProperty","p","s","e","console","log"],"mappings":"aACA,IAAAA,KAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,IACAG,EAAAH,EACAI,KACAH,YAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,KAGAF,EAAAD,QAKAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,GACAK,gBACAC,cACAC,IAAAN,KAMAZ,EAAAmB,EAAA,SAAAjB,GACAY,OAAAC,eAAAb,EAAA,cAAiDkB,YAIjDpB,EAAAqB,EAAA,SAAAlB,GACA,IAAAS,EAAAT,KAAAmB,WACA,WAA2B,OAAAnB,EAAAoB,SAC3B,WAAiC,OAAApB,GAEjC,OADAH,EAAAU,EAAAE,EAAA,IAAAA,GACAA,GAIAZ,EAAAa,EAAA,SAAAW,EAAAC,GAAsD,OAAAX,OAAAY,UAAAC,eAAApB,KAAAiB,EAAAC,IAGtDzB,EAAA4B,EAAA,GAIA5B,IAAA6B,EAAA,cAAAC,EAAAT,GCnEAU,QAAQC,IAAI","file":"output.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","console.log('hello')"],"sourceRoot":""}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"name": "dogborn",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.prod.js",
"watch": "webpack --watch",
"start": "webpack-dev-server --config webpack.dev.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"ts-loader": "^4.0.0",
"tslint": "^5.9.1",
"typescript": "^2.7.2",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.0",
"webpack-merge": "^4.1.2",
"@types/createjs": "^0.0.29"
}
}
\ No newline at end of file
export default class Piece extends createjs.Container {
isDog: boolean;
front: createjs.Bitmap;
back: createjs.Bitmap;
index: number;
static FLIP_DURTION = 1000;
constructor(isDog: boolean, index: number) {
super();
this.index = index;
this.isDog = isDog;
if (isDog) {
this.front = new createjs.Bitmap('./imgs/front.png');
} else {
this.front = new createjs.Bitmap('./imgs/bone.png');
}
this.back = new createjs.Bitmap('./imgs/back.png');
this.addChild(this.front);
this.addChild(this.back);
// this.front.anchorX = this.front.width / 2;
// this.front.anchorY = this.front.height / 2;
// this.back.anchorX = this.back.width / 2;
// this.back.anchorY = this.back.height / 2;
}
reset(callback) {
// createjs.Tween.get(this.front, { loop: true })
// .to({ x: 400 }, 1000, createjs.Ease.getPowInOut(4))
const ease = createjs.Ease.quadInOut;
createjs.Tween.get(this.front)
.to({ scaleX: 0.01 }, Piece.FLIP_DURTION / 2, ease);
// createjs.Tween.get(this.front, Piece.FLIP_DURTION / 2, {
// scaleX: 0.01,
// ease: ease,
// onComplete: () => {
// this.back.visible = true;
// this.front.visible = false;
// annie.Tween.to(this.back, Piece.FLIP_DURTION / 2, {
// scaleX: 1,
// ease: ease,
// onComplete: () => {
// callback && callback();
// }
// });
// }
// });
}
resetImmediately() {
this.back.visible = true;
this.back.scaleX = 1;
this.front.visible = false;
this.front.scaleX = 0.01;
}
flipImmediately() {
this.back.visible = false;
this.front.visible = true;
this.front.scaleX = 1;
this.back.scaleX = 0.01;
}
flip(callback = null) {
// const ease = annie.Tween.quadraticInOut;
// annie.Tween.to(this.back, Piece.FLIP_DURTION / 2, {
// ease: ease,
// scaleX: 0.01,
// onComplete: () => {
// this.back.visible = false;
// this.front.visible = true;
// annie.Tween.to(this.front, Piece.FLIP_DURTION / 2, {
// ease: ease,
// scaleX: 1,
// onComplete: () => {
// callback && callback();
// }
// });
// }
// });
}
}
\ No newline at end of file
import Piece from './Piece';
import * as utils from './utils'
import Swap from './Swap';
export default class Scene extends createjs.Container {
private _targets: number[];
private _list: Piece[];
SHOW_TIME = 1000;
DELAY = 500;
BORNS = 1;
R = 3;
TIMES = 3;
N = 4;
SIZE = 235;
constructor() {
super();
this.initUI();
this.update();
}
initUI() {
const n = this.R * this.R;
const targetList = utils.fillN(n);
const randomTargetList = utils.shuffle(targetList);
this._targets = randomTargetList.slice(0, this.BORNS);
this._list = [];
for (let index = 1; index <= n; index++) {
const inTargets = this._targets.indexOf(index) != -1;
const p = new Piece(!inTargets, index);
p['index'] = index;
this.addChild(p);
this._list.push(p);
p.x = ((index - 1) % this.R) * this.SIZE;
p.y = Math.floor((index - 1) / this.R) * this.SIZE;
p.flipImmediately();
p.addEventListener('click', (e: createjs.MouseEvent) => {
const p = (e.currentTarget as Piece);
this.disable();
let enable = false;
const index = this._targets.indexOf(p.index);
if (index != -1) {
this._targets.splice(index, 1);
if (this._targets.length == 0) {
console.log('good.')
} else {
enable = true;
}
}
else {
console.log('sorry.')
}
p.flip(() => {
if (enable) this.enable();
});
});
}
this.disable();
}
update() {
const onResetComplete = () => {
setTimeout(() => {
Swap.startSwap(this._list, this.N, this.TIMES, this._targets[0], () => {
this.onSwapComplete()
})
}, this.DELAY);
}
setTimeout(() => {
for (let i = 0; i < this._list.length; i++) {
const e = this._list[i];
e.reset(i == 0 ? onResetComplete : null);
}
}, this.SHOW_TIME);
}
onSwapComplete() {
console.log('onSwapComplete');
this.enable();
}
disable() {
for (const e of this._list) {
e.mouseEnabled = false;
}
}
enable() {
for (const e of this._list) {
e.mouseEnabled = true;
}
}
}
\ No newline at end of file
import * as utils from './utils'
import Piece from './Piece';
export default class Swap {
static DURATION = 0.25;
static DELAY = .9;
static startSwap(all: Piece[], n: number, times: number, target: number, onSwapComplete: Function) {
for (let index = 0; index < times; index++) {
const list = Swap.getList(all, n, target);
setTimeout(() => {
Swap.swap(list, index + 1 == times ? onSwapComplete : null);
}, Swap.DURATION * 1000 * index + Swap.DELAY * 1000 * index);
}
}
private static getList(all: Piece[], n: number, target: number) {
const randomizedDeck = utils.shuffle(all);
let targetPiece;
const randomizedDeck2 = randomizedDeck.filter(e => {
if (e.index == target)
targetPiece = e;
return e.index != target;
});
const list = randomizedDeck2.slice(0, n - 1);
const m = n / 2;
const list1 = list.slice(0, m);
const list2 = list.slice(m);
list2.push(targetPiece);
return list1.map(
(val, index) => { return { a: val, b: list2[index] } }
)
}
private static swap(list: { a: Piece, b: Piece }[], onComplete: Function = null) {
let tag = true;
for (const e of list) {
if (tag) {
tag = false;
Swap.swapOne(e.a, e.b, onComplete);
} else {
Swap.swapOne(e.a, e.b);
}
}
}
private static swapOne(a: Piece, b: Piece, onComplete: Function = null) {
const ax = a.x;
const ay = a.y;
const bx = b.x;
const by = b.y;
const ease = createjs.Ease.quadInOut;
// if (onComplete)
// annie.Tween.to(b, Swap.DURATION, { x: ax, y: ay, onComplete: onComplete, ease: ease });
// else
// annie.Tween.to(b, Swap.DURATION, { x: ax, y: ay, ease: ease });
// annie.Tween.to(a, Swap.DURATION, { x: bx, y: by, ease: ease });
}
}
\ No newline at end of file
import Piece from './Piece';
import Scene from './Scene';
const stage = new createjs.StageGL('gameCanvas');
const scene = new Scene();
stage.addChild(scene);
createjs.Ticker.on('tick', ()=>{
stage.update()
});``
\ No newline at end of file
let gameconfig = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload: preload,
create: create,
update: update
}
};
let game = new Phaser.Game(gameconfig);
function preload() {
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.image('star', 'assets/star.png');
this.load.image('bomb', 'assets/bomb.png');
}
function create() {
this.add.image(400, 300, 'sky');
this.add.image(400, 300, 'star');
}
function update() {
//
}
\ No newline at end of file
const shuffle = (deck: any[]) => {
const randomizedDeck: any[] = [];
const array = deck.slice();
while (array.length !== 0) {
const rIndex = Math.floor(array.length * Math.random());
randomizedDeck.push(array[rIndex]);
array.splice(rIndex, 1)
}
return randomizedDeck;
};
const fillN = (n: number) => {
const list = [];
for (let index = 1; index <= n; index++) {
list.push(index);
}
return list;
}
export { fillN, shuffle }
\ No newline at end of file
{
"compilerOptions": {
"target": "es5",
"module": "es6",
"outDir": "./dist/",
"sourceMap": true,
"allowJs": false,
"noImplicitAny": false,
"removeComments": true,
"noEmitOnError": true
},
"exclude": [
"node_modules",
"src/components",
"dist"
]
}
\ No newline at end of file
exports.__esModule = true;
exports.rules = {
// "only-arrow-functions": true,
"no-namespace": true,
"no-var-keyword": true,
"prefer-const": true,
"no-conditional-assignment": true,
"prefer-for-of": true,
"no-inferrable-types": true,
// "no-magic-numbers": [true, -1, 0, 1],
"cyclomatic-complexity": [true, 20],
"max-line-length": [true, 150],
"max-file-line-count": [true, 500],
"max-classes-per-file": [true, 6],
// "quotemark": [true, "single"],
"no-empty-interface": true,
"adjacent-overload-signatures": true,
// "member-access":true,
"no-non-null-assertion": true,
"no-consecutive-blank-lines": true,
// "no-console": [true, "log"],
"no-empty": [true, "allow-empty-catch"],
"no-unused-expression": [true, "allow-fast-null-checks"],
"no-duplicate-super": true,
};
\ No newline at end of file
{
"defaultSeverity": "error",
"extends": [
// "tslint:recommended"
"./tslint-config"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
\ No newline at end of file
const path = require('path');
module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: 'output.js',
path: path.resolve(__dirname, './dist')
}
};
\ No newline at end of file
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: './dist',
}
});
\ No newline at end of file
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = merge(common, {
devtool: 'source-map',
plugins: [
new UglifyJSPlugin(
{ sourceMap: true }
)
]
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment