Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Areesanan committed Oct 23, 2022
2 parents 0967404 + 42d05d2 commit 6ed52af
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
14 changes: 13 additions & 1 deletion components/Controller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {Robot} from "~/classes/Robot";
const p = defineProps<{
robo: Robot,
chapterName: String,
currentTask: number,
taskCount: number
}>()
function callFunction(functionName) {
Expand All @@ -14,7 +17,16 @@ let RoboMethods = $ref(Object.getOwnPropertyNames(Object.getPrototypeOf(p.robo))
</script>
<template>
<div class="w-full bg-gray-200 h-20 flex justify-between p-6">
<div class="w-full bg-gray-400 flex justify-between pt-4">
<div class="grid grid-cols-2 border-2 border-gray-200 p-2 gap-2">
<div class="grid grid-rows-2">
<div class="bg-red-500 p-2">Chapter</div>
<div class="bg-red-500 p-2">{{ chapterName }}</div>
</div>
<div class="bg-red-500 p-2">
{{currentTask}}/{{taskCount}}
</div>
</div>
<div class="flex gap-2">
<button
class="p-4 border-2 border-gray-500 rounded-xl flex place-items-center"
Expand Down
15 changes: 9 additions & 6 deletions components/GameView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import {Robot} from "~/classes/Robot"
const p = defineProps<{
robo: Robot,
resolution: {
type: Number,
default: 12,
},
}>()
console.log('Robo: ', p.robo);
// console.log('Robo: ', p.robo);
</script>

<template>
<div class="grid aspect-square bg-green-50" style="
grid-template-columns: repeat(24, minmax(0, 1fr));
grid-template-rows: repeat(24, minmax(0, 1fr));">
<div class="grid aspect-square bg-green-50"
:style="{gridTemplateColumns: resolution, gridTemplateRows: resolution}">
<div
class="bg-gray-500"
:style="{gridRowStart: 24 - robo._y, gridColumnStart: 1 + robo._x}"
:style="{gridRowStart: resolution - robo._y, gridColumnStart: 1 + robo._x}"
></div>

<div v-for="obst of robo._level.obstacles" class="bg-black"
:style="{gridColumnStart: 1 + obst, gridRowStart: 24}"/>
:style="{gridColumnStart: 1 + obst, gridRowStart: resolution}"/>
</div>
</template>
46 changes: 28 additions & 18 deletions pages/chapter/console/1.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
<script lang="ts" setup>
import GameView from "~/components/GameView.vue"
import Controller from "~/components/Controller.vue"
import {Robot} from "~/classes/Robot"
import {Level} from "~/classes/Level"
import {watchEffect} from "#imports"
import {useRouter} from "#app"
import GameView from "~/components/GameView.vue"
import Controller from "~/components/Controller.vue"
import {Robot} from "~/classes/Robot"
import {Level} from "~/classes/Level"
import {watchEffect} from "#imports"
import {useRouter} from "#app"
const router = useRouter()
const level = new Level({obstacles: new Set([3, 6, 10]), goal: 2})
const robo = new Robot({level})
const router = useRouter()
const level = new Level({obstacles: new Set([3, 6, 10]), goal: 2})
const robo = new Robot({level})
watchEffect(() => {
if (robo._x >= level.goal) {
alert('goal reached!')
router.push('/chapter/console/2')
}
})
watchEffect(() => {
if (robo._x >= level.goal) {
alert('goal reached!')
router.push('/chapter/console/2')
}
})
</script>
<template>
<div class="flex flex-col aspect-square">
<GameView :robo="robo" class="flex-grow"/>
<Controller :robo="robo" class="fixed bottom-0"/>
<div class="flex flex-col aspect-square max-w-2xl mx-auto mt-10">
<div class="p-10 bg-gray-400">
<GameView
:robo="robo"
:resolution="12"
/>
<Controller
:robo="robo"
chapter-name="Methods"
current-task="1"
task-count="4"
/>
</div>
</div>
</template>

0 comments on commit 6ed52af

Please sign in to comment.