Skip to content

Commit fb774a0

Browse files
committed
feat: add ability to manage game status and navigate between minigames
1 parent ce03b8a commit fb774a0

File tree

5 files changed

+112
-30
lines changed

5 files changed

+112
-30
lines changed

js/src/components/MiniGame.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ export default defineComponent({
2020
}
2121
}
2222
23+
const returnToGameStatus = () => {
24+
ctx.emit('select-minigame', {
25+
id: ''
26+
})
27+
}
28+
2329
return {
2430
...toRefs(state),
25-
checkPassword
31+
checkPassword,
32+
returnToGameStatus
2633
}
2734
}
2835
})
@@ -41,6 +48,9 @@ export default defineComponent({
4148
@keyup.enter="checkPassword"
4249
/>
4350
<button type="submit" @click="checkPassword">Submit</button>
51+
<div>
52+
<button @click="returnToGameStatus">Back to Game Status</button>
53+
</div>
4454
</section>
4555
</template>
4656

js/src/components/MiniGame2.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export default defineComponent({
2828
state.userSequence = []
2929
}
3030
31+
const returnToGameStatus = () => {
32+
ctx.emit('select-minigame', {
33+
id: ''
34+
})
35+
}
36+
3137
watchEffect(() => {
3238
if (state.userSequence.length === 3) {
3339
checkColorSequence()
@@ -37,7 +43,8 @@ export default defineComponent({
3743
return {
3844
...toRefs(state),
3945
addColorToSequence,
40-
colorOptions
46+
colorOptions,
47+
returnToGameStatus
4148
}
4249
}
4350
})
@@ -60,6 +67,7 @@ export default defineComponent({
6067
{{ color }}
6168
</button>
6269
</div>
70+
<button @click="returnToGameStatus">Back to Game Status</button>
6371
</section>
6472
</template>
6573

js/src/components/MiniGame3.vue

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ export default defineComponent({
4242
state.userSelection.selectedWire = colorName
4343
}
4444
45+
const returnToGameStatus = () => {
46+
ctx.emit('select-minigame', {
47+
id: ''
48+
})
49+
}
50+
4551
return {
4652
...toRefs(state),
4753
checkWireColors,
4854
registerMatchColor,
4955
registerWireColor,
5056
mousePosition,
51-
registerPosition
57+
registerPosition,
58+
returnToGameStatus
5259
}
5360
}
5461
})
@@ -61,9 +68,6 @@ export default defineComponent({
6168
@mousemove="registerPosition"
6269
>
6370
<h1>MiniGame 3</h1>
64-
<p>{{ mousePosition }}</p>
65-
<p>{{ userSelection }}</p>
66-
<p>{{ matchStatus }}</p>
6771
<div :class="$style.wireboard">
6872
<div :class="$style.panel">
6973
<ul>
@@ -77,23 +81,7 @@ export default defineComponent({
7781
</li>
7882
</ul>
7983
</div>
80-
<svg
81-
version="1.1"
82-
xmlns="http://www.w3.org/2000/svg"
83-
xmlns:xlink="http://www.w3.org/1999/xlink"
84-
x="0px"
85-
y="0px"
86-
xml:space="preserve"
87-
style="border: 1px solid red; flex: 1;"
88-
>
89-
<path
90-
class="path2"
91-
fill="#01a09e"
92-
stroke-width="5"
93-
stroke="black"
94-
:d="`M0 11 L ${mousePosition.x} ${mousePosition.y - 250}`"
95-
/>
96-
</svg>
84+
9785
<div :class="$style.panel">
9886
<ul>
9987
<li
@@ -108,6 +96,7 @@ export default defineComponent({
10896
</ul>
10997
</div>
11098
</div>
99+
<button @click="returnToGameStatus">Back to Game Status</button>
111100
</section>
112101
</template>
113102

js/src/components/MiniGameStatus.vue

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script>
2+
import { reactive, toRefs } from 'vue'
3+
4+
export default {
5+
setup(props, ctx) {
6+
const state = reactive({
7+
minigames: [
8+
{
9+
id: 'mg-enter-password',
10+
label: 'Enter Password'
11+
},
12+
{
13+
id: 'mg-sequence-solver',
14+
label: 'Sequence Solver'
15+
},
16+
{
17+
id: 'mg-wire-matcher',
18+
label: 'Wire Matcher'
19+
}
20+
]
21+
})
22+
23+
const sendSelection = minigame => {
24+
ctx.emit('select-minigame', {
25+
...minigame
26+
})
27+
}
28+
29+
return {
30+
...toRefs(state),
31+
sendSelection
32+
}
33+
}
34+
}
35+
</script>
36+
37+
<template>
38+
<div>
39+
<h2>Mission</h2>
40+
<p>Complete all three mini-games to win!</p>
41+
<ul>
42+
<li
43+
v-for="minigame in minigames"
44+
:key="minigame.id"
45+
@click="sendSelection(minigame)"
46+
>
47+
{{ minigame.label }}
48+
</li>
49+
</ul>
50+
</div>
51+
</template>
52+
53+
<style></style>

js/src/views/SpaceGame.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import { reactive, toRefs } from 'vue'
33
import MiniGame from '../components/MiniGame'
44
import MiniGame2 from '../components/MiniGame2'
55
import MiniGame3 from '../components/MiniGame3'
6+
import MiniGameStatus from '../components/MiniGameStatus'
67
78
export default {
89
components: {
910
MiniGame,
1011
MiniGame2,
11-
MiniGame3
12+
MiniGame3,
13+
MiniGameStatus
1214
},
1315
setup() {
1416
const state = reactive({
15-
gameStatus: 'Not Started'
17+
gameStatus: 'Not Started',
18+
selectedGame: 'Tests'
1619
})
1720
1821
const user = reactive({
@@ -23,13 +26,18 @@ export default {
2326
state.gameStatus = 'Game Started'
2427
}
2528
29+
const registerSelection = payload => {
30+
state.selectedGame = payload.id
31+
}
32+
2633
const updateUserMiniGame = () => {
2734
user.miniGamesWon++
2835
}
2936
3037
return {
3138
...toRefs(state),
3239
...toRefs(user),
40+
registerSelection,
3341
updateUserMiniGame,
3442
startGame
3543
}
@@ -39,16 +47,30 @@ export default {
3947

4048
<template>
4149
<div>
42-
<!-- <h1>Space Game</h1>
50+
<h1>Space Game</h1>
4351
<h2>Game Status</h2>
4452
<p>{{ gameStatus }}</p>
45-
<h2>User Properties</h2> -->
53+
<p>Selected Game: {{ selectedGame }}</p>
54+
<h2>User Properties</h2>
4655
<p>Mini-Games Won: {{ miniGamesWon }}</p>
4756
<div class="game-stage">
4857
<div class="mini-game-wrapper">
49-
<MiniGame v-if="false" @mini-game-won="updateUserMiniGame" />
50-
<MiniGame2 v-if="false" @mini-game-won="updateUserMiniGame" />
51-
<MiniGame3 @mini-game-won="updateUserMiniGame" />
58+
<MiniGame
59+
v-if="selectedGame === 'mg-enter-password'"
60+
@mini-game-won="updateUserMiniGame"
61+
@select-minigame="registerSelection"
62+
/>
63+
<MiniGame2
64+
v-else-if="selectedGame === 'mg-sequence-solver'"
65+
@mini-game-won="updateUserMiniGame"
66+
@select-minigame="registerSelection"
67+
/>
68+
<MiniGame3
69+
v-else-if="selectedGame === 'mg-wire-matcher'"
70+
@mini-game-won="updateUserMiniGame"
71+
@select-minigame="registerSelection"
72+
/>
73+
<MiniGameStatus v-else @select-minigame="registerSelection" />
5274
</div>
5375
<div
5476
class="panel"

0 commit comments

Comments
 (0)