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
0e7848d6
Commit
0e7848d6
authored
Apr 08, 2022
by
徐行
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数式接龙逻辑好了
parent
d20fd132
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
FormulaSolitaireCtr.ts
...ndle/games/formulaSolitaire/script/FormulaSolitaireCtr.ts
+19
-0
Calculator.ts
assets/startFolder/script/common/Calculator.ts
+6
-2
No files found.
assets/sceneBundle/games/formulaSolitaire/script/FormulaSolitaireCtr.ts
View file @
0e7848d6
...
...
@@ -331,11 +331,29 @@ export class FormulaSolitaireCtr extends Component {
return
false
;
}
combFormula
(
numStrArr
:
string
[])
{
let
idx
=
0
;
while
(
idx
<
numStrArr
.
length
-
1
)
{
// if (el_arr[0] === "(" && el_arr[2] === ")" && el_arr[1] !== "+" && el_arr[1] !== "-" && el_arr[1] !== "×" && el_arr[1] !== "÷")
let
isOk_1
=
!
(
numStrArr
[
idx
]
==
"("
||
numStrArr
[
idx
]
==
")"
||
numStrArr
[
idx
]
==
"+"
||
numStrArr
[
idx
]
==
"-"
||
numStrArr
[
idx
]
==
"×"
||
numStrArr
[
idx
]
==
"÷"
);
let
isOk_2
=
!
(
numStrArr
[
idx
+
1
]
==
"("
||
numStrArr
[
idx
+
1
]
==
")"
||
numStrArr
[
idx
+
1
]
==
"+"
||
numStrArr
[
idx
+
1
]
==
"-"
||
numStrArr
[
idx
+
1
]
==
"×"
||
numStrArr
[
idx
+
1
]
==
"÷"
);
if
(
isOk_1
&&
isOk_2
)
{
numStrArr
[
idx
]
=
numStrArr
[
idx
]
+
numStrArr
[
idx
+
1
];
numStrArr
.
splice
(
idx
+
1
,
1
);
}
else
{
idx
+=
1
;
}
}
return
numStrArr
;
}
getResult
(
numStrArr
:
string
[])
{
let
ret
:
any
[]
=
[];
try
{
let
tempArr
:
string
[]
=
[];
tempArr
=
tempArr
.
concat
(
numStrArr
);
tempArr
=
this
.
combFormula
(
tempArr
);
ret
.
push
(
this
.
calculator
(
tempArr
));
}
catch
{
...
...
@@ -347,6 +365,7 @@ export class FormulaSolitaireCtr extends Component {
let
tempArr
:
string
[]
=
[];
tempArr
=
tempArr
.
concat
(
numStrArr
);
tempArr
=
tempArr
.
reverse
();
tempArr
=
this
.
combFormula
(
tempArr
);
ret
.
push
(
this
.
calculator
(
tempArr
));
}
catch
{
...
...
assets/startFolder/script/common/Calculator.ts
View file @
0e7848d6
...
...
@@ -29,7 +29,11 @@ export class Calculator {
}
private
compute
(
el_arr
:
string
[]):
string
|
undefined
{
//初步检测算式是否合理,如果单独的一个数被一个小括号括住会报错
if
(
el_arr
.
length
===
1
)
{
if
(
el_arr
[
0
]
!==
"("
&&
el_arr
[
0
]
!==
")"
&&
el_arr
[
0
]
!==
"+"
&&
el_arr
[
0
]
!==
"-"
&&
el_arr
[
0
]
!==
"×"
&&
el_arr
[
0
]
!==
"÷"
)
return
el_arr
[
0
];
}
//初步检测算式是否合理,如果单独的一个数被一个小括号括住会直接返回
if
(
el_arr
.
length
===
3
)
{
if
(
el_arr
[
0
]
===
"("
&&
el_arr
[
2
]
===
")"
&&
el_arr
[
1
]
!==
"+"
&&
el_arr
[
1
]
!==
"-"
&&
el_arr
[
1
]
!==
"×"
&&
el_arr
[
1
]
!==
"÷"
)
return
el_arr
[
1
];
...
...
@@ -63,7 +67,7 @@ export class Calculator {
b_paren_idx_arr
.
push
(
i
);
}
}
if
(
f_paren_idx_arr
.
length
==
0
&&
b_paren_idx_arr
.
length
==
0
)
{
//啥也不做
}
...
...
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