Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
EmidWife-New
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-24-005
EmidWife-New
Commits
cc8603af
Commit
cc8603af
authored
May 17, 2024
by
Malsha Jayakody
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix message errors
parent
5229c7c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
40 deletions
+30
-40
src/screens/home/game/game02/level01.js
src/screens/home/game/game02/level01.js
+10
-15
src/screens/home/game/game02/level02.js
src/screens/home/game/game02/level02.js
+20
-25
No files found.
src/screens/home/game/game02/level01.js
View file @
cc8603af
...
...
@@ -150,50 +150,45 @@ const Game02Level01 = ({navigation, route}) => {
if
(
budget
-
item
.
cost
>=
0
)
{
setBudget
(
budget
-
item
.
cost
);
setCollectedItems
([...
collectedItems
,
item
]);
if
(
item
.
type
===
'
healthy
'
)
{
setHealthyCost
(
prevCost
=>
prevCost
+
item
.
cost
);
}
else
{
setUnhealthyCost
(
prevCost
=>
prevCost
+
item
.
cost
);
}
// Use a setTimeout to ensure state updates have been applied before check
setTimeout
(()
=>
{
if
(
unhealthyCost
>
2000
)
{
if
(
unhealthyCost
+
item
.
cost
>
2000
)
{
// ensure the current cost is added to total for the check
Alert
.
alert
(
'
Game lost!
'
,
'
Choose healthier foods. 🍇🍌🍉🥬🥕🍒
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
{
navigation
.
navigate
(
ROUTES
.
GAME_QUIZ_OPTIONS
);
},
onPress
:
()
=>
navigation
.
navigate
(
ROUTES
.
GAME_QUIZ_OPTIONS
),
},
]);
}
else
if
(
healthyCost
>
2000
)
{
Alert
.
alert
(
'
Game won!
'
,
}
else
if
(
healthyCost
+
item
.
cost
>
2000
)
{
// ensure the current cost is added to total for the check
Alert
.
alert
(
'
Game won!
'
,
'
Congratulations! You have made healthy choices.
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
{
navigation
.
navigate
(
ROUTES
.
Game02ProgressLevel03
);
},
onPress
:
()
=>
navigation
.
navigate
(
ROUTES
.
Game02ProgressLevel03
),
},
]);
backgroundMusic
.
current
.
setVolume
(
0.0
);
}
},
0
);
}
else
{
Alert
.
alert
(
'
Not enough budget
'
,
Alert
.
alert
(
'
Not enough budget
'
,
'
Please try to manage your budget better.
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
{
navigation
.
navigate
(
ROUTES
.
CHOOSE_GAME
);
},
onPress
:
()
=>
navigation
.
navigate
(
ROUTES
.
CHOOSE_GAME
),
},
]);
}
};
return
(
<
ScrollView
style
=
{
styles
.
container
}
>
...
...
src/screens/home/game/game02/level02.js
View file @
cc8603af
...
...
@@ -81,44 +81,39 @@ const CravingsPuzzleGame02Level02 = ({navigation}) => {
};
const
purchaseItem
=
item
=>
{
// Check if the budget allows for the purchase
if
(
budget
-
item
.
cost
>=
0
)
{
// Update the budget and purchased items
setBudget
(
budget
-
item
.
cost
);
setPurchasedItems
([...
purchasedItems
,
item
]);
// Update the cost tracking based on whether the item is essential
if
(
item
.
essential
===
true
)
{
setHealthyCost
(
prevCost
=>
prevCost
+
item
.
cost
);
}
else
{
setUnhealthyCost
(
prevCost
=>
prevCost
+
item
.
cost
);
}
setTimeout
(()
=>
{
if
(
unhealthyCost
>
2000
)
{
Alert
.
alert
(
'
Game lost!
'
,
'
Choose essintial items!
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
{
navigation
.
navigate
(
ROUTES
.
GAME_QUIZ_OPTIONS
);
},
},
]);
}
else
if
(
healthyCost
>
2000
)
{
Alert
.
alert
(
'
Game won!
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
{
navigation
.
navigate
(
ROUTES
.
Game02ProgressLevel06
);
},
},
]);
backgroundMusic
.
current
.
setVolume
(
0.0
);
}
},
0
);
// Delay is unnecessary, so directly execute the checks
if
(
unhealthyCost
+
item
.
cost
>
2000
)
{
Alert
.
alert
(
'
Game lost!
'
,
'
Choose essential items!
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
navigation
.
navigate
(
ROUTES
.
GAME_QUIZ_OPTIONS
),
},
]);
}
else
if
(
healthyCost
+
item
.
cost
>
2000
)
{
Alert
.
alert
(
'
Game won!
'
,
'
Congratulations!
'
,
[
{
text
:
'
OK
'
,
onPress
:
()
=>
navigation
.
navigate
(
ROUTES
.
Game02ProgressLevel06
),
},
]);
backgroundMusic
.
current
.
setVolume
(
0.0
);
}
}
else
{
Alert
.
alert
(
'
Not enough budget
'
);
}
setBudget
(
currentBudget
=>
currentBudget
-
item
.
cost
);
setPurchasedItems
(
currentItems
=>
[...
currentItems
,
item
]);
};
return
(
...
...
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