Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
interactiveGames_Level
Project
Project
Details
Activity
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
xuxing@jiuaoedu.com
interactiveGames_Level
Commits
634ccff1
Commit
634ccff1
authored
Nov 08, 2021
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
准备做计算逻辑
parent
bce34096
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
213 additions
and
22 deletions
+213
-22
FormulaSolitaireItem.prefab
...games/formulaSolitaire/prefab/FormulaSolitaireItem.prefab
+3
-0
FormulaSolitaireCtr.ts
...ndle/games/formulaSolitaire/script/FormulaSolitaireCtr.ts
+200
-16
FormulaSolitaireItem.ts
...dle/games/formulaSolitaire/script/FormulaSolitaireItem.ts
+10
-6
No files found.
assets/sceneBundle/games/formulaSolitaire/prefab/FormulaSolitaireItem.prefab
View file @
634ccff1
...
@@ -995,6 +995,9 @@
...
@@ -995,6 +995,9 @@
"textLab": {
"textLab": {
"__id__": 39
"__id__": 39
},
},
"clickNode": {
"__id__": 2
},
"_id": ""
"_id": ""
},
},
{
{
...
...
assets/sceneBundle/games/formulaSolitaire/script/FormulaSolitaireCtr.ts
View file @
634ccff1
import
{
_decorator
,
Component
,
Node
,
Sprite
,
Vec3
,
Prefab
,
Label
,
CCFloat
,
instantiate
,
UITransform
,
v3
,
director
}
from
'cc'
;
import
{
_decorator
,
Component
,
Node
,
Sprite
,
Vec3
,
Prefab
,
Label
,
CCFloat
,
instantiate
,
UITransform
,
v3
,
director
,
EventTouch
,
v2
,
Color
}
from
'cc'
;
import
{
VIEW_DEF
}
from
'../../../../startFolder/script/common/ViewDef'
;
import
{
VIEW_DEF
}
from
'../../../../startFolder/script/common/ViewDef'
;
import
{
viewMgr
}
from
'../../../../startFolder/script/common/ViewMgr'
;
import
{
viewMgr
}
from
'../../../../startFolder/script/common/ViewMgr'
;
import
{
GameDescView
}
from
'../../commonView/script/GameDescView'
;
import
{
GameDescView
}
from
'../../commonView/script/GameDescView'
;
import
{
FS_ITEM_STATE
}
from
'./FormulaSolitaireItem'
;
import
{
F
ormulaSolitaireItem
,
F
S_ITEM_STATE
}
from
'./FormulaSolitaireItem'
;
const
{
ccclass
,
property
}
=
_decorator
;
const
{
ccclass
,
property
}
=
_decorator
;
const
colorArr
:
string
[]
=
[
"#749A98"
,
"#85B3B0"
,
"#A0D6D3"
,
"#B29E67"
,
"#D2B977"
,
"#FFE18F"
,
"#6E96B6"
,
"#7FAED2"
,
"#98D2FF"
,
"#B6A6AF"
,
"#D0BBC6"
,
"#FFE6F3"
,
"#A97171"
,
"#D28C8C"
,
"#FFAAAA"
,
"#8D72A8"
,
"#A585C5"
,
"#CFA8F6"
]
export
interface
ItemPosIfo
{
export
interface
ItemPosIfo
{
id
:
number
,
//唯一标识
id
:
number
,
//唯一标识
pos
:
Vec3
,
//位置
pos
:
Vec3
,
//位置
...
@@ -16,9 +37,10 @@ export interface ItemPosIfo {
...
@@ -16,9 +37,10 @@ export interface ItemPosIfo {
enum
GAME_STATE
{
enum
GAME_STATE
{
READY
=
10
,
READY
=
10
,
RUN
=
20
,
END
=
20
,
END
=
30
,
PAUSE
=
30
,
PAUSE
=
40
,
IDLE
=
40
,
MOVE
=
50
}
}
@
ccclass
(
'FormulaSolitaireCtr'
)
@
ccclass
(
'FormulaSolitaireCtr'
)
...
@@ -53,16 +75,20 @@ export class FormulaSolitaireCtr extends Component {
...
@@ -53,16 +75,20 @@ export class FormulaSolitaireCtr extends Component {
private
isPlayCountdownMus
=
false
;
private
isPlayCountdownMus
=
false
;
private
isShowGameDescViewOnce
=
false
;
private
isShowGameDescViewOnce
=
false
;
private
usedColorArr
:
string
[]
=
[];
private
orgColor
=
"#D7C7BB"
;
private
curLinePointArr
:
ItemPosIfo
[]
=
[];
private
allLinePointArr
:
ItemPosIfo
[][]
=
[];
showGameDescView
()
{
showGameDescView
()
{
this
.
isShowGameDescViewOnce
=
true
;
this
.
isShowGameDescViewOnce
=
true
;
viewMgr
.
openView
(
VIEW_DEF
.
GameDescView
,
(
node
)
=>
{
viewMgr
.
openView
(
VIEW_DEF
.
GameDescView
,
(
node
)
=>
{
node
.
getComponent
(
GameDescView
)?.
setDesc
(
"
选择数字填入空格使横着的和竖着的算式都要成立。
\
n注意:不论从左到右还是从上到下都要符合四则运算优先级
。"
);
node
.
getComponent
(
GameDescView
)?.
setDesc
(
"
把算式连接在一起
。"
);
});
});
}
}
onCloseGameDescView
()
{
onCloseGameDescView
()
{
this
.
gameState
=
GAME_STATE
.
RUN
;
this
.
gameState
=
GAME_STATE
.
IDLE
;
}
}
setGameData
(
resData
:
object
)
{
setGameData
(
resData
:
object
)
{
...
@@ -86,14 +112,154 @@ export class FormulaSolitaireCtr extends Component {
...
@@ -86,14 +112,154 @@ export class FormulaSolitaireCtr extends Component {
}
}
}
}
start
()
{
start
()
{
// [3]
// [3]
this
.
posArrNode
.
on
(
Node
.
EventType
.
TOUCH_START
,
this
.
onTouchStart
,
this
);
this
.
posArrNode
.
on
(
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onTouchMove
,
this
);
this
.
posArrNode
.
on
(
Node
.
EventType
.
TOUCH_END
,
this
.
onTouchEnd
,
this
);
this
.
gameStart
();
this
.
gameStart
();
}
}
gameStart
(){
onTouchStart
(
event
:
EventTouch
)
{
if
(
this
.
gameState
!=
GAME_STATE
.
IDLE
)
return
;
this
.
curLinePointArr
=
[];
let
selPoint
:
ItemPosIfo
=
null
!
;
for
(
let
i
=
0
;
i
<
this
.
itemPosIfoArr
.
length
;
++
i
)
{
let
rect
=
this
.
itemPosIfoArr
[
i
].
target
!
.
getComponent
(
FormulaSolitaireItem
)?.
getWorldAABB
();
if
(
rect
?.
contains
(
event
.
getUILocation
()))
{
selPoint
=
this
.
itemPosIfoArr
[
i
];
break
;
}
}
if
(
selPoint
==
null
)
return
;
let
oldLine
=
this
.
findLineWithPoint
(
selPoint
);
if
(
oldLine
==
null
)
{
this
.
curLinePointArr
.
push
(
selPoint
);
this
.
allLinePointArr
.
push
(
this
.
curLinePointArr
);
let
colorStr
=
this
.
getRandomItemColor
();
this
.
usedColorArr
.
push
(
colorStr
);
selPoint
.
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
colorStr
));
}
else
{
this
.
curLinePointArr
=
oldLine
;
let
idx
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
curLinePointArr
.
length
;
++
i
)
{
if
(
selPoint
.
target
.
uuid
==
this
.
curLinePointArr
[
i
].
target
.
uuid
)
{
idx
=
i
;
break
;
}
}
for
(
let
i
=
idx
+
1
;
i
<
this
.
curLinePointArr
.
length
;
++
i
)
{
this
.
curLinePointArr
[
i
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
this
.
orgColor
));
this
.
curLinePointArr
[
i
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
}
this
.
curLinePointArr
.
splice
(
idx
+
1
,
this
.
curLinePointArr
.
length
);
this
.
curLinePointArr
[
idx
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
}
this
.
gameState
=
GAME_STATE
.
MOVE
;
}
onTouchMove
(
event
:
EventTouch
)
{
if
(
this
.
gameState
!=
GAME_STATE
.
MOVE
)
return
;
let
selPoint
:
ItemPosIfo
=
null
!
;
for
(
let
i
=
0
;
i
<
this
.
itemPosIfoArr
.
length
;
++
i
)
{
let
rect
=
this
.
itemPosIfoArr
[
i
].
target
!
.
getComponent
(
FormulaSolitaireItem
)?.
getWorldAABB
();
if
(
rect
?.
contains
(
event
.
getUILocation
()))
{
selPoint
=
this
.
itemPosIfoArr
[
i
];
break
;
}
}
if
(
selPoint
==
null
)
return
;
let
lastPoint
=
this
.
curLinePointArr
[
this
.
curLinePointArr
.
length
-
1
];
if
(
Math
.
abs
(
selPoint
.
xIdx
-
lastPoint
.
xIdx
)
+
Math
.
abs
(
selPoint
.
yIdx
-
lastPoint
.
yIdx
)
!=
1
)
return
;
let
colorStr
=
this
.
curLinePointArr
[
0
].
target
.
getComponent
(
FormulaSolitaireItem
)
!
.
getColor
();
let
oldLine
=
this
.
findLineWithPoint
(
selPoint
);
if
(
oldLine
==
null
)
{
console
.
log
(
`没有占有此点的线段`
);
this
.
curLinePointArr
.
push
(
selPoint
);
selPoint
.
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
colorStr
));
}
else
{
let
idx
=
-
1
;
for
(
let
i
=
0
;
i
<
oldLine
.
length
;
++
i
)
{
if
(
selPoint
.
id
==
oldLine
[
i
].
id
)
{
idx
=
i
;
break
;
}
}
for
(
let
i
=
idx
;
i
<
oldLine
.
length
;
++
i
)
{
oldLine
[
i
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
this
.
orgColor
));
oldLine
[
i
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
}
oldLine
.
splice
(
idx
,
this
.
curLinePointArr
.
length
);
this
.
curLinePointArr
.
push
(
selPoint
);
selPoint
.
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
colorStr
));
}
this
.
paintPaths
();
}
paintPaths
()
{
for
(
let
i
=
0
;
i
<
this
.
allLinePointArr
.
length
;
++
i
)
{
let
line
=
this
.
allLinePointArr
[
i
];
for
(
let
j
=
0
;
j
<
line
.
length
;
++
j
)
{
if
(
j
==
line
.
length
-
1
)
{
line
[
j
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
}
else
{
line
[
j
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
this
.
getDirection
(
line
[
j
],
line
[
j
+
1
]));
}
}
}
}
onTouchEnd
(
event
:
EventTouch
)
{
if
(
this
.
gameState
!=
GAME_STATE
.
MOVE
)
return
;
this
.
gameState
=
GAME_STATE
.
IDLE
;
for
(
let
i
=
0
;
i
<
this
.
allLinePointArr
.
length
;
++
i
)
{
if
(
this
.
allLinePointArr
[
i
].
length
<
2
)
{
let
pointArr
=
this
.
allLinePointArr
[
i
];
this
.
allLinePointArr
.
splice
(
i
,
1
);
for
(
let
j
=
0
;
j
<
pointArr
.
length
;
++
j
)
{
pointArr
[
j
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
this
.
orgColor
));
pointArr
[
j
].
target
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
}
}
}
console
.
log
(
`线段集合`
);
console
.
log
(
this
.
allLinePointArr
);
}
findLineWithPoint
(
point
:
ItemPosIfo
)
{
for
(
let
i
=
0
;
i
<
this
.
allLinePointArr
.
length
;
++
i
)
{
for
(
let
j
=
0
;
j
<
this
.
allLinePointArr
[
i
].
length
;
++
j
)
{
if
(
point
.
id
==
this
.
allLinePointArr
[
i
][
j
].
id
)
{
return
this
.
allLinePointArr
[
i
];
}
}
}
return
null
;
}
gameStart
()
{
this
.
gameState
=
GAME_STATE
.
READY
;
this
.
usedColorArr
=
[];
this
.
curLinePointArr
=
[];
this
.
allLinePointArr
=
[];
this
.
creAllItem
();
this
.
creAllItem
();
this
.
setBgSprSize
();
this
.
setBgSprSize
();
this
.
gameState
=
GAME_STATE
.
IDLE
;
}
getRandomItemColor
()
{
let
count
=
0
;
let
colorStr
=
""
;
do
{
count
+=
1
;
colorStr
=
colorArr
[
Math
.
floor
(
Math
.
random
()
*
colorArr
.
length
)];
}
while
(
this
.
usedColorArr
.
indexOf
(
colorStr
)
!=
-
1
&&
count
<
300
);
return
colorStr
;
}
}
creAllItem
()
{
creAllItem
()
{
...
@@ -103,6 +269,8 @@ export class FormulaSolitaireCtr extends Component {
...
@@ -103,6 +269,8 @@ export class FormulaSolitaireCtr extends Component {
this
.
posArrNode
.
addChild
(
node
);
this
.
posArrNode
.
addChild
(
node
);
node
.
setPosition
(
this
.
itemPosIfoArr
[
i
].
pos
);
node
.
setPosition
(
this
.
itemPosIfoArr
[
i
].
pos
);
this
.
itemPosIfoArr
[
i
].
target
=
node
;
this
.
itemPosIfoArr
[
i
].
target
=
node
;
node
.
getComponent
(
FormulaSolitaireItem
)?.
setItemState
(
FS_ITEM_STATE
.
CENTER
);
node
.
getComponent
(
FormulaSolitaireItem
)?.
setColor
(
Color
.
fromHEX
(
new
Color
(),
this
.
orgColor
));
}
}
}
}
...
@@ -188,25 +356,41 @@ export class FormulaSolitaireCtr extends Component {
...
@@ -188,25 +356,41 @@ export class FormulaSolitaireCtr extends Component {
return
this
.
calculator
(
numStrArr
);
return
this
.
calculator
(
numStrArr
);
}
}
getItemsDirArr
(
itemPosIfos
:
ItemPosIfo
[]){
getItemsDirArr
(
itemPosIfos
:
ItemPosIfo
[])
{
let
dirArr
:
FS_ITEM_STATE
[]
=
[];
let
dirArr
:
FS_ITEM_STATE
[]
=
[];
for
(
let
i
=
0
;
i
<
itemPosIfos
.
length
-
1
;
++
i
)
{
for
(
let
i
=
0
;
i
<
itemPosIfos
.
length
-
1
;
++
i
)
{
if
(
itemPosIfos
[
i
+
1
].
pos
.
x
-
itemPosIfos
[
i
].
pos
.
x
<
0
)
{
if
(
itemPosIfos
[
i
+
1
].
pos
.
x
-
itemPosIfos
[
i
].
pos
.
x
<
0
)
{
dirArr
.
push
(
FS_ITEM_STATE
.
LEFT
);
dirArr
.
push
(
FS_ITEM_STATE
.
LEFT
);
}
}
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
x
-
itemPosIfos
[
i
].
pos
.
x
>
0
)
{
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
x
-
itemPosIfos
[
i
].
pos
.
x
>
0
)
{
dirArr
.
push
(
FS_ITEM_STATE
.
RIGHT
);
dirArr
.
push
(
FS_ITEM_STATE
.
RIGHT
);
}
}
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
y
-
itemPosIfos
[
i
].
pos
.
y
<
0
)
{
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
y
-
itemPosIfos
[
i
].
pos
.
y
<
0
)
{
dirArr
.
push
(
FS_ITEM_STATE
.
BOTTOM
);
dirArr
.
push
(
FS_ITEM_STATE
.
BOTTOM
);
}
}
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
y
-
itemPosIfos
[
i
].
pos
.
y
>
0
)
{
else
if
(
itemPosIfos
[
i
+
1
].
pos
.
y
-
itemPosIfos
[
i
].
pos
.
y
>
0
)
{
dirArr
.
push
(
FS_ITEM_STATE
.
TOP
);
dirArr
.
push
(
FS_ITEM_STATE
.
TOP
);
}
}
}
}
if
(
itemPosIfos
.
length
>
0
)
dirArr
.
push
(
FS_ITEM_STATE
.
CENTER
);
if
(
itemPosIfos
.
length
>
0
)
dirArr
.
push
(
FS_ITEM_STATE
.
CENTER
);
return
dirArr
;
return
dirArr
;
}
}
getDirection
(
s_item
:
ItemPosIfo
,
e_item
:
ItemPosIfo
):
FS_ITEM_STATE
{
if
(
s_item
.
id
==
e_item
.
id
)
return
FS_ITEM_STATE
.
CENTER
;
if
(
e_item
.
xIdx
>
s_item
.
xIdx
)
{
return
FS_ITEM_STATE
.
RIGHT
;
}
else
if
(
e_item
.
yIdx
>
s_item
.
yIdx
)
{
return
FS_ITEM_STATE
.
BOTTOM
;
}
else
if
(
e_item
.
yIdx
<
s_item
.
yIdx
)
{
return
FS_ITEM_STATE
.
TOP
;
}
else
{
return
FS_ITEM_STATE
.
LEFT
;
}
}
// update (deltaTime: number) {
// update (deltaTime: number) {
// // [4]
// // [4]
// }
// }
...
...
assets/sceneBundle/games/formulaSolitaire/script/FormulaSolitaireItem.ts
View file @
634ccff1
...
@@ -62,12 +62,16 @@ export class FormulaSolitaireItem extends Component {
...
@@ -62,12 +62,16 @@ export class FormulaSolitaireItem extends Component {
return
this
.
_text
;
return
this
.
_text
;
}
}
setColor
(
color
:
math
.
IColorLike
){
setColor
(
color
:
Color
){
this
.
bgSpr
.
color
=
new
Color
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
this
.
bgSpr
.
color
=
color
;
this
.
topSpr
.
color
=
new
Color
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
this
.
topSpr
.
color
=
color
;
this
.
bottomSpr
.
color
=
new
Color
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
this
.
bottomSpr
.
color
=
color
;
this
.
leftSpr
.
color
=
new
Color
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
this
.
leftSpr
.
color
=
color
;
this
.
rightSpr
.
color
=
new
Color
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
this
.
rightSpr
.
color
=
color
;
}
getColor
(){
return
this
.
bgSpr
.
color
.
toHEX
();
}
}
getWorldAABB
(){
getWorldAABB
(){
...
...
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