Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
learn-phaser
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wildfirecode13
learn-phaser
Commits
d384b84c
Commit
d384b84c
authored
Apr 21, 2018
by
wildfirecode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
975c66c3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
161 deletions
+184
-161
PieceControl.ts
dogborn/src/PieceControl.ts
+4
-2
Scene.ts
dogborn/src/Scene.ts
+0
-97
SceneControl.ts
dogborn/src/SceneControl.ts
+97
-0
Swap.ts
dogborn/src/Swap.ts
+73
-54
index.ts
dogborn/src/index.ts
+10
-8
No files found.
dogborn/src/PieceControl.ts
View file @
d384b84c
export
default
class
PieceControl
{
p
rivate
scene
;
p
ublic
scene
;
private
isDog
:
boolean
;
private
front
;
private
back
;
...
...
@@ -38,7 +38,9 @@ export default class PieceControl {
scaleX
:
1
,
ease
:
'Quad.easeInOut'
,
duration
:
PieceControl
.
FLIP_DURTION
/
2
,
onComplete
:
()
=>
{
callback
&&
callback
()
}
onComplete
:
()
=>
{
callback
&&
callback
()
}
}]
});
}
...
...
dogborn/src/Scene.ts
deleted
100644 → 0
View file @
975c66c3
// 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
dogborn/src/SceneControl.ts
0 → 100644
View file @
d384b84c
import
PieceControl
from
'./PieceControl'
;
import
*
as
utils
from
'./utils'
import
Swap
from
'./Swap'
;
export
default
class
SceneControl
{
private
scene
;
private
_targets
:
number
[];
private
_list
:
PieceControl
[];
SHOW_TIME
=
1000
;
DELAY
=
500
;
BORNS
=
2
;
R
=
3
;
TIMES
=
3
;
N
=
4
;
SIZE
=
235
;
constructor
(
scene
)
{
this
.
scene
=
scene
;
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
PieceControl
(
this
.
scene
,
!
inTargets
,
index
);
p
[
'index'
]
=
index
;
this
.
_list
.
push
(
p
);
p
.
container
.
x
=
((
index
-
1
)
%
this
.
R
)
*
this
.
SIZE
+
106
+
50
;
p
.
container
.
y
=
Math
.
floor
((
index
-
1
)
/
this
.
R
)
*
this
.
SIZE
+
106
+
50
;
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
dogborn/src/Swap.ts
View file @
d384b84c
//
import * as utils from './utils'
// import Piece from './Piece
';
//
export default class Swap {
// static DURATION = 0.2
5;
//
static DELAY = .9;
import
*
as
utils
from
'./utils'
import
PieceControl
from
'./PieceControl
'
;
export
default
class
Swap
{
static
DURATION
=
0.4
5
;
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] } }
//
)
//
}
static
startSwap
(
all
:
PieceControl
[],
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
:
PieceControl
[],
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
swap
(
list
:
{
a
:
PieceControl
,
b
:
PieceControl
}[],
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
private
static
swapOne
(
a
:
PieceControl
,
b
:
PieceControl
,
onComplete
:
Function
=
null
)
{
const
ax
=
a
.
container
.
x
;
const
ay
=
a
.
container
.
y
;
const
bx
=
b
.
container
.
x
;
const
by
=
b
.
container
.
y
;
const
scene
=
a
.
scene
;
if
(
onComplete
)
{
const
tween
=
scene
.
tweens
.
add
({
targets
:
b
.
container
,
x
:
ax
,
y
:
ay
,
ease
:
'Quad.easeInOut'
,
duration
:
Swap
.
DURATION
*
1000
,
onComplete
:
onComplete
});
}
else
{
const
tween
=
scene
.
tweens
.
add
({
targets
:
b
.
container
,
x
:
ax
,
y
:
ay
,
ease
:
'Quad.easeInOut'
,
duration
:
Swap
.
DURATION
*
1000
,
});
}
const
tween
=
scene
.
tweens
.
add
({
targets
:
a
.
container
,
x
:
bx
,
y
:
by
,
ease
:
'Quad.easeInOut'
,
duration
:
Swap
.
DURATION
*
1000
,
});
}
}
\ No newline at end of file
dogborn/src/index.ts
View file @
d384b84c
import
PieceControl
from
"./PieceControl"
;
import
SceneControl
from
"./SceneControl"
;
const
gameconfig
=
{
type
:
Phaser
.
AUTO
,
width
:
800
,
height
:
6
00
,
height
:
8
00
,
scene
:
{
preload
:
preload
,
create
:
create
,
...
...
@@ -20,14 +21,15 @@ function preload() {
}
function
create
()
{
const
a
=
new
PieceControl
(
this
,
true
,
0
);
a
.
container
.
x
=
107
;
a
.
container
.
y
=
107
;
new
SceneControl
(
this
)
// const a = new PieceControl(this, true, 0);
// a.container.x = 107;
// a.container.y = 107;
// a.container.visible =false
a
.
resetImmediately
();
setTimeout
(()
=>
{
a
.
flip
();
},
1000
);
//
a.resetImmediately();
//
setTimeout(() => {
//
a.flip();
//
}, 1000);
// a.container.scaleX = 0.5
// a.flipImmediately();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment