Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JM04-3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
JM04-3
Commits
6d69b7f4
Commit
6d69b7f4
authored
Jul 21, 2021
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev commit
parent
6f6b57fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
291 additions
and
5 deletions
+291
-5
play.component.ts
src/app/play/play.component.ts
+291
-5
No files found.
src/app/play/play.component.ts
View file @
6d69b7f4
...
@@ -135,6 +135,12 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -135,6 +135,12 @@ export class PlayComponent implements OnInit, OnDestroy {
m_wordAll
=
null
;
m_wordAll
=
null
;
m_allBlocks
=
[];
m_allBlocks
=
[];
m_currentInput
=
""
;
m_currentInput
=
""
;
m_currentQuestionIndex
=
0
;
m_hasActiveBlock
=
false
;
m_hasErrorLetter
=
false
;
m_currentInputIndex
=
0
;
m_submited
=
false
;
m_wordLetterInputCatch
=
[];
// ------------------------------------
// ------------------------------------
...
@@ -180,6 +186,11 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -180,6 +186,11 @@ export class PlayComponent implements OnInit, OnDestroy {
return
array
return
array
}
}
// 重置长音频
resetLongAudio
()
{
}
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// 游戏核心处理区
// 游戏核心处理区
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
...
@@ -196,7 +207,9 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -196,7 +207,9 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
initTitle
();
this
.
initTitle
();
this
.
initQuestion
();
this
.
initQuestion
();
this
.
initKeyboard
();
this
.
initKeyboard
();
this
.
initSubmit
();
this
.
initOutputWindow
();
this
.
initOutputWindow
();
this
.
switchQuestion
(
0
,
0
);
}
}
cleanGameVar
(){
cleanGameVar
(){
...
@@ -209,7 +222,8 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -209,7 +222,8 @@ export class PlayComponent implements OnInit, OnDestroy {
restartGame
(){
restartGame
(){
// this.cleanGameVar()
// this.cleanGameVar()
this
.
startGame
()
this
.
startGame
();
this
.
switchQuestion
(
0
,
0
);
}
}
initBackground
()
{
initBackground
()
{
...
@@ -323,6 +337,17 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -323,6 +337,17 @@ export class PlayComponent implements OnInit, OnDestroy {
})
})
questionText
.
ref
.
text
=
"
a fish whose head look like those of a horse
"
questionText
.
ref
.
text
=
"
a fish whose head look like those of a horse
"
this
.
subscribeMapDownEvent
(
btnNext
.
id
,
()
=>
{
this
.
switchQuestion
(
this
.
m_currentQuestionIndex
,
this
.
m_currentQuestionIndex
+
1
);
jelly
(
btnNext
.
ref
)
this
.
g_enableMapDown
=
true
;
})
this
.
subscribeMapDownEvent
(
btnPre
.
id
,
()
=>
{
this
.
switchQuestion
(
this
.
m_currentQuestionIndex
,
this
.
m_currentQuestionIndex
-
1
);
jelly
(
btnPre
.
ref
)
this
.
g_enableMapDown
=
true
;
})
element
.
ref
.
addChild
(
labelIndex
.
ref
)
element
.
ref
.
addChild
(
labelIndex
.
ref
)
element
.
ref
.
addChild
(
questionText
.
ref
)
element
.
ref
.
addChild
(
questionText
.
ref
)
...
@@ -377,12 +402,14 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -377,12 +402,14 @@ export class PlayComponent implements OnInit, OnDestroy {
let
le
=
createWord
(
letttes
[
i
-
1
],
baseX
,
baseY
)
let
le
=
createWord
(
letttes
[
i
-
1
],
baseX
,
baseY
)
this
.
subscribeMapDownEvent
(
le
.
id
,
()
=>
{
this
.
subscribeMapDownEvent
(
le
.
id
,
()
=>
{
jelly
(
le
.
ref
)
jelly
(
le
.
ref
)
let
target
=
this
.
g_cartoon
.
getCartoonElement
(
this
.
m_currentInput
)
if
(
this
.
m_openShift
)
{
if
(
this
.
m_openShift
)
{
console
.
log
(
letttes
[
i
-
1
].
toUpperCase
())
target
.
setContentText
(
letttes
[
i
-
1
].
toUpperCase
())
}
else
{
}
else
{
console
.
log
(
letttes
[
i
-
1
].
toLocaleLowerCase
())
target
.
setContentText
(
letttes
[
i
-
1
].
toLocaleLowerCase
())
}
}
this
.
g_enableMapDown
=
true
;
this
.
g_enableMapDown
=
true
;
this
.
jumpToNextActive
(
this
.
m_currentQuestionIndex
);
})
})
allLetterRefs
.
push
(
le
.
ref
.
children
[
1
])
allLetterRefs
.
push
(
le
.
ref
.
children
[
1
])
element
.
ref
.
addChild
(
le
.
ref
)
element
.
ref
.
addChild
(
le
.
ref
)
...
@@ -451,6 +478,14 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -451,6 +478,14 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
})
})
let
text
=
this
.
g_cartoon
.
createCartoonElementLabelFunc
(
`block_
${
x
}
_
${
y
}
_letter`
,
""
,
"
Aileron-Bold
"
,
"
#FFFFFF
"
,
72
,
(
w
,
h
)
=>
{
return
{
x
:
0
,
y
:
0
,
}
})
let
bgInit
=
this
.
g_cartoon
.
createCartoonElementImageFunc
(
`block_
${
x
}
_
${
y
}
_container_init`
,
"
bg_block_init
"
,
(
w
,
h
)
=>
{
let
bgInit
=
this
.
g_cartoon
.
createCartoonElementImageFunc
(
`block_
${
x
}
_
${
y
}
_container_init`
,
"
bg_block_init
"
,
(
w
,
h
)
=>
{
return
{
return
{
sx
:
80
/
w
,
sx
:
80
/
w
,
...
@@ -462,6 +497,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -462,6 +497,7 @@ export class PlayComponent implements OnInit, OnDestroy {
y
:
0
y
:
0
}
}
})
})
bgInit
.
ref
.
alpha
=
0
;
let
bgDisable
=
this
.
g_cartoon
.
createCartoonElementImageFunc
(
`block_
${
x
}
_
${
y
}
_container_disable`
,
"
bg_block_disable
"
,
(
w
,
h
)
=>
{
let
bgDisable
=
this
.
g_cartoon
.
createCartoonElementImageFunc
(
`block_
${
x
}
_
${
y
}
_container_disable`
,
"
bg_block_disable
"
,
(
w
,
h
)
=>
{
return
{
return
{
...
@@ -520,7 +556,9 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -520,7 +556,9 @@ export class PlayComponent implements OnInit, OnDestroy {
container
.
ref
.
addChild
(
bgRight
.
ref
)
container
.
ref
.
addChild
(
bgRight
.
ref
)
container
.
ref
.
addChild
(
bgFocus
.
ref
)
container
.
ref
.
addChild
(
bgFocus
.
ref
)
container
.
ref
.
addChild
(
bgWrong
.
ref
)
container
.
ref
.
addChild
(
bgWrong
.
ref
)
container
.
ref
.
addChild
(
text
.
ref
);
container
.
isCorrect
=
false
;
container
.
switchStatus
=
(
status
)
=>
{
container
.
switchStatus
=
(
status
)
=>
{
switch
(
status
)
{
switch
(
status
)
{
case
"
init
"
:
case
"
init
"
:
...
@@ -529,6 +567,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -529,6 +567,7 @@ export class PlayComponent implements OnInit, OnDestroy {
bgRight
.
ref
.
alpha
=
0
;
bgRight
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
text
.
ref
.
fontColor
=
"
#b17d5a
"
break
;
break
;
case
"
disable
"
:
case
"
disable
"
:
bgInit
.
ref
.
alpha
=
0
;
bgInit
.
ref
.
alpha
=
0
;
...
@@ -536,6 +575,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -536,6 +575,7 @@ export class PlayComponent implements OnInit, OnDestroy {
bgRight
.
ref
.
alpha
=
0
;
bgRight
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
text
.
ref
.
fontColor
=
"
#b17d5a
"
break
;
break
;
case
"
right
"
:
case
"
right
"
:
bgInit
.
ref
.
alpha
=
0
;
bgInit
.
ref
.
alpha
=
0
;
...
@@ -543,6 +583,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -543,6 +583,7 @@ export class PlayComponent implements OnInit, OnDestroy {
bgRight
.
ref
.
alpha
=
1
;
bgRight
.
ref
.
alpha
=
1
;
bgFocus
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
text
.
ref
.
fontColor
=
"
#ffffff
"
break
;
break
;
case
"
focus
"
:
case
"
focus
"
:
bgInit
.
ref
.
alpha
=
0
;
bgInit
.
ref
.
alpha
=
0
;
...
@@ -550,6 +591,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -550,6 +591,7 @@ export class PlayComponent implements OnInit, OnDestroy {
bgRight
.
ref
.
alpha
=
0
;
bgRight
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
1
;
bgFocus
.
ref
.
alpha
=
1
;
bgWrong
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
0
;
text
.
ref
.
fontColor
=
"
#b17d5a
"
break
;
break
;
case
"
wrong
"
:
case
"
wrong
"
:
bgInit
.
ref
.
alpha
=
0
;
bgInit
.
ref
.
alpha
=
0
;
...
@@ -557,9 +599,104 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -557,9 +599,104 @@ export class PlayComponent implements OnInit, OnDestroy {
bgRight
.
ref
.
alpha
=
0
;
bgRight
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgFocus
.
ref
.
alpha
=
0
;
bgWrong
.
ref
.
alpha
=
1
;
bgWrong
.
ref
.
alpha
=
1
;
text
.
ref
.
fontColor
=
"
#ffffff
"
break
;
break
;
}
}
}
}
container
.
active
=
(
status
=
false
)
=>
{
console
.
log
(
"
DVDV
"
)
if
(
status
)
{
if
(
container
.
getContentText
()
==
""
)
{
bgFocus
.
ref
.
alpha
=
1
;
// bgDisable.ref.alpha = 0;
}
}
else
{
bgFocus
.
ref
.
alpha
=
0
;
// bgDisable.ref.alpha = 1;
}
if
(
status
)
{
this
.
m_currentInput
=
`block_
${
x
}
_
${
y
}
`
;
}
}
container
.
canSetActive
=
()
=>
{
return
true
// if(bgRight.ref.alpha == 1) {
// return false;
// }
if
(
bgFocus
.
ref
.
alpha
==
1
&&
this
.
m_blockFirstSubmit
[
this
.
m_currentQuestionIndex
])
{
return
true
;
}
if
(
bgWrong
.
ref
.
alpha
==
1
)
{
return
true
;
}
}
container
.
setContentText
=
(
letter
)
=>
{
text
.
ref
.
text
=
letter
?
letter
:
""
;
}
container
.
getContentText
=
()
=>
{
return
text
.
ref
.
text
?
text
.
ref
.
text
:
""
;
}
container
.
checkStatus
=
(
withRed
=
false
,
groupIndex
)
=>
{
container
.
active
(
false
);
if
(
container
.
getContentText
()
==
""
)
{
container
.
switchStatus
(
"
focus
"
);
if
(
!
this
.
m_hasActiveBlock
)
{
this
.
m_hasActiveBlock
=
true
;
container
.
active
(
true
)
}
}
else
if
(
withRed
&&
(
letter
!=
container
.
getContentText
()))
{
this
.
m_hasErrorLetter
=
true
;
container
.
switchStatus
(
"
wrong
"
);
if
(
!
this
.
m_hasActiveBlock
)
{
this
.
m_hasActiveBlock
=
true
;
this
.
m_currentInputIndex
=
groupIndex
;
container
.
active
(
true
)
}
}
else
{
container
.
isCorrect
=
true
;
container
.
switchStatus
(
"
right
"
)
}
}
container
.
checkWhenSwitchQuestion
=
(
withRed
,
fromIndex
,
groupIndex
,
contentSaved
?)
=>
{
container
.
active
(
false
);
// 没有点击提交就切换,清空
if
(
!
this
.
m_submited
&&
questionIndex
==
fromIndex
)
{
container
.
setContentText
(
contentSaved
)
}
console
.
log
(
"
==A==
"
)
if
(
groupIndex
!=
this
.
m_currentQuestionIndex
)
{
if
(
container
.
getContentText
()
==
""
)
{
container
.
switchStatus
(
"
init
"
)
}
else
if
(
letter
!=
container
.
getContentText
())
{
container
.
switchStatus
(
"
wrong
"
)
}
else
{
container
.
switchStatus
(
"
right
"
)
}
}
else
{
if
(
container
.
getContentText
()
==
""
)
{
container
.
switchStatus
(
"
right
"
);
if
(
!
this
.
m_hasActiveBlock
)
{
this
.
m_hasActiveBlock
=
true
;
container
.
active
(
true
)
}
}
else
if
(
withRed
&&
(
letter
!=
container
.
getContentText
()))
{
this
.
m_hasErrorLetter
=
true
;
container
.
switchStatus
(
"
wrong
"
);
if
(
!
this
.
m_hasActiveBlock
)
{
this
.
m_hasActiveBlock
=
true
;
this
.
m_currentInputIndex
=
groupIndex
;
container
.
active
(
true
)
}
}
}
console
.
log
(
this
.
m_currentInput
)
}
this
.
subscribeMapDownEvent
(
container
.
id
,
()
=>
{
this
.
subscribeMapDownEvent
(
container
.
id
,
()
=>
{
container
.
switchStatus
(
"
wrong
"
)
container
.
switchStatus
(
"
wrong
"
)
...
@@ -613,16 +750,165 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -613,16 +750,165 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
}
}
}
}
this
.
render
(
element
.
ref
)
}
//
initSubmit
()
{
let
submit
=
this
.
g_cartoon
.
createCartoonElementImageFunc
(
`button_submit`
,
"
btn_submit
"
,
(
w
,
h
)
=>
{
return
{
sx
:
888
*
this
.
g_mapScale
/
w
,
sy
:
160
*
this
.
g_mapScale
/
h
,
}
},
(
w
,
h
)
=>
{
return
{
x
:
this
.
g_canvasWidth
/
2
+
855
*
this
.
g_mapScale
/
2
+
118
*
this
.
g_mapScale
,
y
:
this
.
g_canvasHeight
/
2
+
800
*
this
.
g_mapScale
}
})
submit
.
switchActive
=
(
status
)
=>
{
if
(
status
)
{
submit
.
ref
.
alpha
=
1
;
}
else
{
submit
.
ref
.
alpha
=
0
;
}
}
const
handleSubmit
=
()
=>
{
this
.
m_submited
=
true
;
this
.
m_submitTimes
[
this
.
m_currentQuestionIndex
]
++
;
this
.
m_blockFirstSubmit
[
this
.
m_currentQuestionIndex
]
=
false
;
this
.
m_currentInputIndex
=
0
;
let
status
=
this
.
updateStatusByGroupIndex
(
this
.
m_currentQuestionIndex
);
this
.
switchQuestion
(
this
.
m_currentQuestionIndex
,
this
.
m_currentQuestionIndex
+
1
)
// if(this.m_currentQuestionIndex == this.g_formData.dataArray.length-1) {
// // 最后一题提交以后 弹出结束按钮
// let btn = this.g_cartoon.getCartoonElement("FinishButton")
// btn.in()
// } else {
// if(status) {
// this.g_cartoon.playAudio("正确")
// this.switchQuestion(this.m_currentQuestionIndex, this.m_currentQuestionIndex+1)
// } else {
// this.g_cartoon.playAudio("错误")
// }
// }
}
this
.
subscribeMapDownEvent
(
submit
.
id
,
()
=>
{
handleSubmit
()
this
.
g_enableMapDown
=
true
;
})
this
.
render
(
submit
.
ref
)
}
// 切换题目,主要是变蓝/变红输入框
switchQuestion
(
fromIndex
,
toIndex
)
{
this
.
m_currentQuestionIndex
=
toIndex
;
this
.
m_currentInputIndex
=
0
;
this
.
m_hasActiveBlock
=
false
;
this
.
m_blockGroup
.
forEach
((
group
,
groupIndex
)
=>
{
group
.
forEach
((
block
,
index
)
=>
{
block
.
checkWhenSwitchQuestion
(
true
,
fromIndex
,
groupIndex
,
this
.
m_wordLetterInputCatch
[
index
]?
this
.
m_wordLetterInputCatch
[
index
]:
""
)
});
});
/*
this.m_wordLetterInputCatch = []
this.m_blockGroup[toIndex].forEach(block => {
this.m_wordLetterInputCatch.push(block.getContentText())
});
let indexText = this.g_cartoon.getCartoonElement("IndexText")
indexText.setIndex(toIndex);
let questionText = this.g_cartoon.getCartoonElement("QuestionText");
questionText.setContent(this.g_formData.dataArray[toIndex].text)
this
.
render
(
element
.
ref
)
let nextButton = this.g_cartoon.getCartoonElement("NextButton")
if(this.g_formData.dataArray.length>toIndex+1) {
nextButton.active(true)
} else {
nextButton.active(false)
}
let preButton = this.g_cartoon.getCartoonElement("PreButton")
if(toIndex>0) {
preButton.active(true)
} else {
preButton.active(false)
}
this.m_submited = false;
// this.setKeyboard(this.m_wordAll[toIndex])
*/
}
// submit响应事件,会标红错误
updateStatusByGroupIndex
(
index
)
{
let
blocks
=
this
.
m_blockGroup
[
index
];
this
.
m_hasActiveBlock
=
false
;
this
.
m_hasErrorLetter
=
false
;
blocks
.
forEach
((
item
,
index
)
=>
{
item
.
checkStatus
(
true
,
index
)
});
// 提交后,检查是否有错误拼写, 如果有->禁用提交按钮
let
btn
=
this
.
g_cartoon
.
getCartoonElement
(
"
button_submit
"
)
if
(
!
this
.
m_hasErrorLetter
)
{
btn
.
switchActive
(
false
)
return
true
;
}
else
{
return
false
;
}
}
}
// 跳转下一个焦点输入框
jumpToNextActive
(
index
)
{
console
.
log
(
"
jumpToNextActive
"
)
let
blocks
=
this
.
m_blockGroup
[
index
];
this
.
m_hasActiveBlock
=
false
;
if
(
!
blocks
[
this
.
m_currentInputIndex
])
{
return
;
}
let
checkNextActive
=
()
=>
{
// 当遇到绿色块 或者 索引小于题目数量时,循环
let
count
=
0
;
do
{
blocks
[
this
.
m_currentInputIndex
]
&&
blocks
[
this
.
m_currentInputIndex
].
active
(
false
);
// 当前块 取消激活
this
.
m_currentInput
=
null
;
this
.
m_currentInputIndex
++
;
count
++
;
}
while
(
count
<
blocks
.
length
&&
this
.
m_currentInputIndex
<
blocks
.
length
&&
blocks
[
this
.
m_currentInputIndex
].
isCorrect
)
}
checkNextActive
();
console
.
log
(
this
.
m_currentInputIndex
)
if
(
this
.
m_currentInputIndex
>=
blocks
.
length
)
{
// 没有获取焦点的输入框,启用提交功能
if
(
!
this
.
m_hasActiveBlock
)
{
let
btn
=
this
.
g_cartoon
.
getCartoonElement
(
"
button_submit
"
)
btn
.
switchActive
(
true
)
console
.
log
(
"
使能提交按钮
"
)
}
// 切换当前输入从头开始
this
.
m_currentInputIndex
=
-
1
;
checkNextActive
();
// 判断是否需要激活(绿色不需要激活,红色或者蓝色没有文字需要激活)
if
(
blocks
[
this
.
m_currentInputIndex
].
canSetActive
())
{
blocks
[
this
.
m_currentInputIndex
].
active
(
true
)
}
}
else
{
// 判断是否需要激活(绿色不需要激活,红色或者蓝色没有文字需要激活)
if
(
blocks
[
this
.
m_currentInputIndex
].
canSetActive
())
{
blocks
[
this
.
m_currentInputIndex
].
active
(
true
)
}
}
}
...
...
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