Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
op_spy
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
op_spy
Commits
7f0cc29e
Commit
7f0cc29e
authored
Jul 22, 2022
by
limingzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: AIAI
parent
b75c59b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
176 additions
and
16 deletions
+176
-16
op_spy.js
assets/op_spy/scene/op_spy.js
+176
-16
No files found.
assets/op_spy/scene/op_spy.js
View file @
7f0cc29e
...
@@ -504,6 +504,10 @@ cc.Class({
...
@@ -504,6 +504,10 @@ cc.Class({
this
.
showSearchIcon
(
res
.
data
);
this
.
showSearchIcon
(
res
.
data
);
break
;
break
;
case
'
add_ai
'
:
this
.
onAddAi
(
res
.
data
);
return
;
case
'
send_result
'
:
case
'
send_result
'
:
console
.
log
(
'
in send_result ~
'
,
JSON
.
stringify
(
res
.
data
));
console
.
log
(
'
in send_result ~
'
,
JSON
.
stringify
(
res
.
data
));
...
@@ -515,9 +519,7 @@ cc.Class({
...
@@ -515,9 +519,7 @@ cc.Class({
// this.getGood(res.data);
// this.getGood(res.data);
return
;
return
;
case
'
add_ai
'
:
this
.
onAddAi
(
res
.
data
);
return
;
case
'
add_player
'
:
case
'
add_player
'
:
this
.
onAddPlayer
(
res
.
data
);
this
.
onAddPlayer
(
res
.
data
);
...
@@ -606,8 +608,58 @@ cc.Class({
...
@@ -606,8 +608,58 @@ cc.Class({
// if (this.isTeacher) {
// if (this.isTeacher) {
this
.
addUser
(
data
)
this
.
addUser
(
data
)
// }
// }
this
.
initAiGameData
();
},
initAiGameData
()
{
// 默认数据
this
.
aiGameData
=
{
"
talkGroup
"
:[{
"
word
"
:
"
die
"
},{
"
word
"
:
"
spy
"
},{
"
word
"
:
"
pie
"
},{
"
word
"
:
"
lie
"
},{
"
word
"
:
"
light
"
}],
"
searchGroup
"
:[{
"
word
"
:
"
key
"
,
"
isRight
"
:
false
},{
"
word
"
:
"
candy
"
,
"
isRight
"
:
false
},{
"
word
"
:
"
jeep
"
,
"
isRight
"
:
false
},{
"
word
"
:
"
leaf
"
,
"
isRight
"
:
false
},{
"
word
"
:
"
bee
"
,
"
isRight
"
:
false
}]}
},
setAiGameData
(
callback
)
{
const
node
=
cc
.
find
(
'
middleLayer
'
);
if
(
node
)
{
console
.
log
(
'
node exist
'
);
const
mScript
=
node
.
getComponent
(
'
middleLayer
'
);
const
coursewareid
=
mScript
?.
courseItem
?.
id
;
if
(
!
coursewareid
)
{
console
.
log
(
"
!coursewareid~:
"
);
callback
();
return
;
}
console
.
log
(
'
~ coursewareid :
'
,
coursewareid
);
const
count
=
1
;
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
url
=
"
/api/oxford/courseware/v1/
"
+
coursewareid
+
"
/getanswer
"
mScript
.
callNetworkApiGet
(
url
,
{
coursewareid
,
token
,
count
},
(
res
)
=>
{
console
.
log
(
"
res~:
"
,
res
);
if
(
typeof
(
res
)
==
"
string
"
)
{
res
=
JSON
.
parse
(
res
);
console
.
log
(
'
objRes:
'
,
res
);
}
if
(
res
.
code
==
200
)
{
// this.aiGameData = res
callback
();
}
});
}
else
{
console
.
log
(
'
node not exist
'
);
callback
();
}
},
},
onRefreshPlayerList
(
data
)
{
onRefreshPlayerList
(
data
)
{
console
.
log
(
'
onRefreshPlayerList data:
'
,
data
);
console
.
log
(
'
onRefreshPlayerList data:
'
,
data
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
...
@@ -650,15 +702,18 @@ cc.Class({
...
@@ -650,15 +702,18 @@ cc.Class({
this
.
resultDataArr
=
[];
this
.
resultDataArr
=
[];
this
.
playerAudioDataArr
=
[];
this
.
playerAudioDataArr
=
[];
this
.
initPlayerAB
();
this
.
round
=
1
;
this
.
round
=
1
;
this
.
roundChangeCount
=
0
;
this
.
roundChangeCount
=
0
;
this
.
searchWrongCount
=
0
;
this
.
searchWrongCount
=
0
;
this
.
score
=
0
;
this
.
score
=
0
;
this
.
totalScore
=
20
;
this
.
totalScore
=
20
;
this
.
selfScore
=
0
;
this
.
selfScore
=
0
;
this
.
resultTalkGroup
=
[];
this
.
resultSearchGroup
=
[];
this
.
wordDataArr
=
baseData
//JSON.parse( JSON.stringify(baseData) );
this
.
wordDataArr
=
baseData
//JSON.parse( JSON.stringify(baseData) );
this
.
initPlayerAB
();
if
(
this
.
isPlayer1
)
{
if
(
this
.
isPlayer1
)
{
this
.
initDataGroup
(
baseData
);
this
.
initDataGroup
(
baseData
);
...
@@ -678,10 +733,24 @@ cc.Class({
...
@@ -678,10 +733,24 @@ cc.Class({
return
;
return
;
}
}
this
.
isGameStart
=
true
;
this
.
isGameStart
=
true
;
this
.
initData
();
this
.
initView
();
this
.
hideLoadingLayer
();
const
startShow
=
()
=>
{
this
.
initData
();
this
.
initView
();
this
.
hideLoadingLayer
();
}
if
(
this
.
aiGameData
)
{
this
.
setAiGameData
(()
=>
{
startShow
();
});
}
else
{
startShow
();
}
},
},
hideLoadingLayer
()
{
hideLoadingLayer
()
{
...
@@ -1541,6 +1610,7 @@ cc.Class({
...
@@ -1541,6 +1610,7 @@ cc.Class({
},
},
initDataGroup
(
baseData
)
{
initDataGroup
(
baseData
)
{
this
.
dataGroup1
=
baseData
.
splice
(
0
,
5
);
this
.
dataGroup1
=
baseData
.
splice
(
0
,
5
);
this
.
dataGroup2
=
baseData
;
this
.
dataGroup2
=
baseData
;
},
},
...
@@ -1567,14 +1637,15 @@ cc.Class({
...
@@ -1567,14 +1637,15 @@ cc.Class({
this
.
bg
=
bg
;
this
.
bg
=
bg
;
bg
.
on
(
'
touchstart
'
,
()
=>
{
bg
.
on
(
'
touchstart
'
,
()
=>
{
if
(
!
this
.
isS
earching
||
!
this
.
curData
)
{
if
(
!
this
.
isS
howSearchIcon
||
!
this
.
curData
)
{
return
;
return
;
}
}
if
(
this
.
searchWrongCount
>=
2
)
{
this
.
searchWrongCount
++
;
if
(
this
.
searchWrongCount
==
3
)
{
this
.
searchWrong
();
this
.
searchWrong
();
}
else
{
}
else
if
(
this
.
searchWrongCount
<
3
)
{
this
.
searchWrongCount
++
;
playDragonBoneAnimation
(
this
.
coolcat
,
'
begin
'
,
-
1
);
playDragonBoneAnimation
(
this
.
coolcat
,
'
begin
'
,
-
1
);
this
.
playAudioByName
(
'
bad
'
,
()
=>
{
this
.
playAudioByName
(
'
bad
'
,
()
=>
{
...
@@ -1829,9 +1900,9 @@ cc.Class({
...
@@ -1829,9 +1900,9 @@ cc.Class({
let
audio_url
=
data
.
audioUrl
;
let
audio_url
=
data
.
audioUrl
;
const
score
=
data
.
result
?.
overall
;
const
score
=
data
.
result
?.
overall
;
if
(
score
>=
70
)
{
if
(
score
>=
70
)
{
callback
(
audio_url
);
callback
(
audio_url
,
score
);
}
else
{
}
else
{
callback
();
callback
(
null
,
score
);
}
}
},
},
...
@@ -1857,14 +1928,15 @@ cc.Class({
...
@@ -1857,14 +1928,15 @@ cc.Class({
data
=
JSON
.
parse
(
data
)
data
=
JSON
.
parse
(
data
)
}
}
this
.
recordEnd
(
data
,
(
audio_url
)
=>
{
this
.
recordEnd
(
data
,
(
audio_url
,
score
)
=>
{
const
sendData
=
{
word
:
this
.
curData
.
word
}
const
sendData
=
{
word
:
this
.
curData
.
word
,
score
}
if
(
audio_url
)
{
if
(
audio_url
)
{
sendData
.
audio_url
=
audio_url
;
sendData
.
audio_url
=
audio_url
;
}
}
this
.
sendServerEvent
(
'
word_data
'
,
sendData
);
this
.
sendServerEvent
(
'
word_data
'
,
sendData
);
this
.
resultTalkGroup
.
push
(
sendData
);
this
.
showItemLight
(
audio_url
,
()
=>
{
this
.
showItemLight
(
audio_url
,
()
=>
{
this
.
changeNewWord
();
this
.
changeNewWord
();
...
@@ -1927,6 +1999,10 @@ cc.Class({
...
@@ -1927,6 +1999,10 @@ cc.Class({
console
.
log
(
'
getWordData:
'
,
data
);
console
.
log
(
'
getWordData:
'
,
data
);
this
.
showTalkIcon
(
false
);
this
.
showTalkIcon
(
false
);
if
(
this
.
round
==
1
&&
this
.
aiGameData
)
{
this
.
showAiSearching
(
data
);
}
if
((
this
.
isPlayer1
&&
this
.
round
==
1
)
||
(
this
.
isPlayer2
&&
this
.
round
==
2
))
{
if
((
this
.
isPlayer1
&&
this
.
round
==
1
)
||
(
this
.
isPlayer2
&&
this
.
round
==
2
))
{
return
;
return
;
}
}
...
@@ -1981,6 +2057,59 @@ cc.Class({
...
@@ -1981,6 +2057,59 @@ cc.Class({
},
},
showAiSearching
(
data
)
{
const
{
searchGroup
}
=
this
.
aiGameData
;
let
index
=
-
1
;
for
(
let
i
=
0
;
i
<
searchGroup
.
length
;
i
++
)
{
if
(
searchGroup
[
i
].
word
==
data
.
word
)
{
index
=
i
;
break
;
}
}
const
subData
=
searchGroup
.
splice
(
index
,
1
)[
0
];
this
.
sendServerEvent
(
"
show_search_icon
"
,
true
)
setTimeout
(()
=>
{
if
(
subData
.
isRight
)
{
this
.
sendServerEvent
(
'
add_score
'
)
}
this
.
sendServerEvent
(
"
show_search_icon
"
,
false
)
if
(
searchGroup
.
length
==
0
)
{
this
.
sendServerEvent
(
"
next_round
"
)
}
},
3000
);
},
showAiTalking
()
{
this
.
sendServerEvent
(
"
show_talk_icon
"
,
true
)
setTimeout
(()
=>
{
const
{
talkGroup
}
=
this
.
aiGameData
;
const
subData
=
talkGroup
.
shift
();
this
.
sendServerEvent
(
'
word_data
'
,
subData
);
if
(
talkGroup
.
length
>
0
)
{
setTimeout
(()
=>
{
this
.
showAiTalking
();
},
1500
);
}
else
{
this
.
sendServerEvent
(
"
next_round
"
)
}
},
3000
);
},
hideTalkBtn
()
{
hideTalkBtn
()
{
this
.
talkBtn
.
active
=
false
;
this
.
talkBtn
.
active
=
false
;
this
.
hideWave
();
this
.
hideWave
();
...
@@ -2126,6 +2255,7 @@ cc.Class({
...
@@ -2126,6 +2255,7 @@ cc.Class({
this
.
searchEnd
();
this
.
searchEnd
();
});
});
this
.
resultSearchGroup
.
push
({
word
:
this
.
curData
.
word
,
isRight
:
true
});
this
.
curTopSpr
.
active
=
false
;
this
.
curTopSpr
.
active
=
false
;
},
},
...
@@ -2137,6 +2267,7 @@ cc.Class({
...
@@ -2137,6 +2267,7 @@ cc.Class({
this
.
searchEnd
();
this
.
searchEnd
();
});
});
this
.
resultSearchGroup
.
push
({
word
:
this
.
curData
.
word
,
isRight
:
false
});
this
.
curTopSpr
.
active
=
false
;
this
.
curTopSpr
.
active
=
false
;
},
},
...
@@ -2195,7 +2326,9 @@ cc.Class({
...
@@ -2195,7 +2326,9 @@ cc.Class({
playDragonBoneAnimation
(
this
.
coolcat
,
'
normal
'
,
-
1
);
playDragonBoneAnimation
(
this
.
coolcat
,
'
normal
'
,
-
1
);
if
(
this
.
isPlayer1
)
{
if
(
this
.
isPlayer1
)
{
if
(
this
.
aiGameData
)
{
this
.
showAiTalking
();
}
}
else
{
}
else
{
this
.
dataGroup2
=
this
.
wordDataArr
;
this
.
dataGroup2
=
this
.
wordDataArr
;
this
.
initCurData
();
this
.
initCurData
();
...
@@ -2209,8 +2342,35 @@ cc.Class({
...
@@ -2209,8 +2342,35 @@ cc.Class({
gameEnd
()
{
gameEnd
()
{
console
.
log
(
'
in game end
'
);
console
.
log
(
'
in game end
'
);
this
.
showResultLayer
();
this
.
showResultLayer
();
this
.
saveAnswer
();
// console.log('this.resultDataArr: ', this.resultDataArr)
console
.
log
(
'
this.resultTalkGroup:
'
,
JSON
.
stringify
(
this
.
resultTalkGroup
)
);
console
.
log
(
'
this.resultSearchGroup:
'
,
JSON
.
stringify
(
this
.
resultSearchGroup
)
);
},
},
saveAnswer
()
{
console
.
log
(
'
in saveAnswer
'
)
const
resultData
=
{
talkGroup
:
this
.
resultTalkGroup
,
searchGroup
:
this
.
resultSearchGroup
}
const
node
=
cc
.
find
(
'
middleLayer
'
);
if
(
node
)
{
console
.
log
(
'
node exist
'
);
const
mScript
=
node
.
getComponent
(
'
middleLayer
'
);
console
.
log
(
'
saveAnswer ~ :
'
,
JSON
.
stringify
(
resultData
));
mScript
.
saveAnswer
(
resultData
,
()
=>
{
callback
&&
callback
();
})
}
},
showResultLayer
()
{
showResultLayer
()
{
...
...
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