Skip to content

Commit 4b3e029

Browse files
committed
[^]游戏:调整游戏难度&&精简代码
1 parent be4290c commit 4b3e029

File tree

8 files changed

+29
-14
lines changed

8 files changed

+29
-14
lines changed

src/views/game/components/Config.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</template>
99

1010
<script setup>
11-
import { ref, reactive, getCurrentInstance, computed, watch, onMounted } from "vue";
11+
import { computed } from "vue";
1212
import { useStore } from "vuex";
1313
const store = useStore();
1414

src/views/game/components/Enemy.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</template>
1010

1111
<script setup>
12-
import { ref, reactive, getCurrentInstance, computed, onMounted, watch } from "vue";
13-
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
12+
import { ref, computed, onMounted, watch } from "vue";
13+
import { onBeforeRouteLeave } from "vue-router";
1414
import { ElNotification } from "element-plus";
1515
import loadsh from "lodash";
1616
import { useStore } from "vuex";

src/views/game/components/Fail.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</template>
1313

1414
<script setup>
15-
import { ref, reactive, getCurrentInstance, computed, watch, onMounted } from "vue";
15+
import { ref, computed, onMounted } from "vue";
1616
import loadsh from "lodash";
1717
import { useStore } from "vuex";
1818
const store = useStore();

src/views/game/components/Figure.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,34 @@
55
</template>
66

77
<script setup>
8-
import { ref, reactive, getCurrentInstance, computed, onMounted, watch } from "vue";
9-
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
8+
import { ref, computed, onMounted, watch } from "vue";
9+
import { onBeforeRouteLeave } from "vue-router";
1010
import { useStore } from "vuex";
1111
const store = useStore();
1212
1313
const jumpUp = ref(null);
1414
const jumpDown = ref(null);
15+
const jumpHeight = ref(600);
16+
const jumpPoor = ref(100);
1517
const brick = computed(() => store.state.game.brick);
1618
const figure = computed(() => store.state.game.figure);
1719
const game = computed(() => store.state.game.game);
1820
21+
watch(
22+
game,
23+
(val) => {
24+
if (!val.start) {
25+
jumpHeight.value = 600;
26+
} else {
27+
if (jumpHeight.value <= 200) {
28+
jumpPoor.value = 10;
29+
}
30+
jumpHeight.value = jumpHeight.value - jumpPoor.value;
31+
}
32+
},
33+
{ deep: true }
34+
);
35+
1936
const figureJump = () => {
2037
figure.value.bottom += figure.value.speed;
2138
document.getElementById("figure").style.bottom = figure.value.bottom + "px";
@@ -43,7 +60,7 @@ const moveFn = (e) => {
4360
cancelAnimationFrame(jumpUp.value);
4461
jumpUp.value = null;
4562
jumpDown.value = requestAnimationFrame(figureDown);
46-
}, 300);
63+
}, jumpHeight.value);
4764
}
4865
};
4966

src/views/game/components/Floor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</template>
2222

2323
<script setup>
24-
import { reactive, onMounted, computed, watch } from "vue";
24+
import { onMounted, computed, watch } from "vue";
2525
import { useStore } from "vuex";
2626
const store = useStore();
2727

src/views/game/components/GameMap.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</template>
1717

1818
<script setup>
19-
import { ref, reactive, getCurrentInstance, computed, onMounted } from "vue";
19+
import { computed } from "vue";
2020
import Floor from "./Floor";
2121
import Figure from "./Figure";
2222
import Enemy from "./Enemy";

src/views/game/components/Score.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</template>
77

88
<script setup>
9-
import { ref, reactive, getCurrentInstance, computed, watch, onMounted } from "vue";
9+
import { computed } from "vue";
1010
import { useStore } from "vuex";
1111
const store = useStore();
1212
@@ -18,7 +18,5 @@ const game = computed(() => store.state.game.game);
1818
position: absolute;
1919
top: 10px;
2020
right: 20px;
21-
// left: 50%;
22-
// transform: translateX(-50%);
2321
}
2422
</style>

src/views/game/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<script setup>
1010
import Map from "./components/GameMap.vue";
11-
import { ref, reactive, onMounted, computed, watch } from "vue";
12-
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
11+
import { ref, onMounted, computed } from "vue";
12+
import { onBeforeRouteLeave } from "vue-router";
1313
import loadsh from "lodash";
1414
import { useStore } from "vuex";
1515
const store = useStore();

0 commit comments

Comments
 (0)