Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSAPP2501
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
SSAPP2501
Commits
ebca1c4b
Commit
ebca1c4b
authored
Aug 02, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
e4707ca5
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1536 additions
and
597 deletions
+1536
-597
SSAPP2501.fire
assets/SSAPP2501/scene/SSAPP2501.fire
+1288
-353
SSAPP2501.ts
assets/SSAPP2501/scene/SSAPP2501.ts
+181
-200
Game.ts
assets/SSAPP2501/scene/tool/Game.ts
+67
-43
huiwan_cocos.md
huiwan_cocos.md
+0
-1
No files found.
assets/SSAPP2501/scene/SSAPP2501.fire
View file @
ebca1c4b
This diff is collapsed.
Click to expand it.
assets/SSAPP2501/scene/SSAPP2501.ts
View file @
ebca1c4b
This diff is collapsed.
Click to expand it.
assets/SSAPP2501/scene/tool/Game.ts
View file @
ebca1c4b
...
...
@@ -135,35 +135,35 @@ export default class Game {
if
(
!
Game
.
ins
)
Game
.
ins
=
new
Game
();
return
Game
.
ins
;
}
/** 游戏数据 */
private
data
:
any
;
/** 选项列表 */
private
lists
:
Array
<
Option
>
/** 游戏数据源数组 */
private
data
:
Array
<
any
>
;
/** 玩家实例 */
public
player
:
Player
;
/** 游戏状态 */
public
state
:
GAME_STATE
;
/**
问题
总数 */
/**
数据
总数 */
public
total
:
number
;
/** 每页数据数量 */
public
pageSize
:
number
;
/**
* 构造函数,初始化游戏基本属性
*/
constructor
()
{
this
.
start
=
false
;
this
.
lists
=
[];
this
.
data
=
[];
this
.
page
=
0
;
this
.
pageSize
=
6
;
this
.
player
=
new
Player
();
this
.
state
=
GAME_STATE
.
WAIT
;
}
/**
* 获取当前
选项列表
长度
* @returns
选项列表
长度
* 获取当前
数据源
长度
* @returns
数据源
长度
*/
get
len
()
{
return
this
.
lists
.
length
;
return
this
.
data
?
this
.
data
.
length
:
0
;
}
/** 是否为单人游戏模式 */
public
singleGame
:
boolean
;
/** 问题信息,包含文本和音频 */
public
question
:
{
text
,
audio
};
/** 游戏标题 */
...
...
@@ -177,14 +177,15 @@ export default class Game {
* @param data 游戏配置数据
*/
public
init
(
data
)
{
this
.
singleGame
=
!
data
.
onlineFlg
;
this
.
pageSize
=
6
;
// 每页最多6个数据
this
.
question
=
{
text
:
data
.
questionText
,
audio
:
data
.
questionTextAudio
};
this
.
title
=
data
.
title
;
this
.
bgAudio
=
data
.
bgAudio
||
""
;
this
.
questionText
=
data
.
questionText
;
this
.
start
=
false
;
this
.
lists
=
[];
this
.
page
=
0
;
// 页码从0开始
this
.
data
=
data
.
questions
;
this
.
total
=
this
.
data
.
length
;
}
/** 游戏是否已开始 */
public
start
:
boolean
;
...
...
@@ -192,68 +193,91 @@ export default class Game {
public
page
:
number
;
/**
* 重置游戏状态
* 重置玩家数据,初始化
问题列表
,准备开始新游戏
* 重置玩家数据,初始化
游戏状态
,准备开始新游戏
*/
reset
()
{
this
.
player
.
reset
();
this
.
page
=
1
;
this
.
page
=
0
;
// 页码从0开始
this
.
start
=
true
;
this
.
lists
=
[];
for
(
let
i
=
0
;
i
<
this
.
data
.
length
;
i
++
)
{
let
data
=
this
.
data
[
i
];
this
.
lists
.
push
(
new
Option
(
data
,
i
));
}
this
.
state
=
GAME_STATE
.
WAIT
;
this
.
total
=
this
.
lists
.
length
;
this
.
total
=
this
.
data
.
length
;
}
/**
* 获取
随机卡片信息
*
从列表中随机抽取一个选项并从列表中移除
* @returns
随机选项,如果列表为空则返回null
* 获取
当前页的数据
*
@param {number} pageIndex 页码索引,默认为当前页码(页码从0开始)
* @returns
{Array<Option>} 当前页的选项数据数组
*/
public
getCardInfo
()
{
let
option
:
Option
;
if
(
this
.
lists
.
length
>
0
)
{
let
random
=
Math
.
floor
(
Math
.
random
()
*
this
.
lists
.
length
);
option
=
this
.
lists
.
splice
(
random
,
1
)[
0
];
}
else
{
option
=
null
;
getPageData
(
pageIndex
?:
number
)
{
// 如果没有指定页码索引,则使用当前页码(页码从0开始)
const
index
=
pageIndex
!==
undefined
?
pageIndex
:
this
.
page
;
// 计算当前页的起始索引和结束索引
const
startIndex
=
index
*
this
.
pageSize
;
const
endIndex
=
Math
.
min
(
startIndex
+
this
.
pageSize
,
this
.
data
.
length
);
// 如果起始索引超出数据范围,返回空数组
if
(
startIndex
>=
this
.
data
.
length
)
{
return
[];
}
// 提取当前页的数据并转换为Option对象
const
pageData
:
Array
<
Option
>
=
[];
for
(
let
i
=
startIndex
;
i
<
endIndex
;
i
++
)
{
pageData
.
push
(
new
Option
(
this
.
data
[
i
],
i
));
}
console
.
log
(
"
this.cardInfo=======
"
,
option
)
return
option
;
return
pageData
;
}
/**
* 获取总页数
/剩余问题数
* @returns
剩余问题数量
* 获取总页数
* @returns
总页数(向上取整)
*/
getTotalPageNum
()
{
return
this
.
lists
.
length
;
return
Math
.
ceil
(
this
.
data
.
length
/
this
.
pageSize
)
;
}
/**
* 获取当前页码
* @returns 当前页码
* @returns 当前页码
(从0开始)
*/
getCurrentPageNum
()
{
return
this
.
page
;
}
/**
* 页码加1,用于游戏进度更新
*/
addPage
()
{
this
.
page
+=
1
;
}
/**
* 获取
剩余
总数
* @returns
剩余问题数量
* 获取
数据
总数
* @returns
数据总数
*/
get
getTotla
()
{
return
this
.
lists
.
length
;
get
getTotal
()
{
return
this
.
data
.
length
;
}
/**
* 获取当前页的卡片信息
* @returns 当前页的选项数据数组
*/
getCardInfo
()
{
const
currentPageData
=
this
.
getPageData
();
if
(
currentPageData
.
length
===
0
)
{
return
null
;
}
return
currentPageData
[
0
];
// 返回当前页的第一个选项
}
/**
* 判断游戏是否结束
* @returns 当前页码是否超过
问题总
数
* @returns 当前页码是否超过
或等于总页
数
*/
get
isOver
()
{
return
this
.
page
>
this
.
lists
.
length
;
return
this
.
page
>
=
this
.
getTotalPageNum
()
;
}
}
\ No newline at end of file
huiwan_cocos.md
View file @
ebca1c4b
...
...
@@ -295,7 +295,6 @@
|
`player`
|
`Player`
| 玩家实例 |
|
`state`
|
`GAME_STATE`
| 游戏状态 |
|
`total`
|
`number`
| 问题总数 |
|
`singleGame`
|
`boolean`
| 是否为单人游戏模式 |
|
`question`
|
`{text, audio}`
| 问题信息 |
|
`title`
|
`string`
| 游戏标题 |
|
`bgAudio`
|
`string`
| 背景音乐URL |
...
...
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