Skip to content

Commit

Permalink
create the gridn and node
Browse files Browse the repository at this point in the history
  • Loading branch information
GunawanAhmad committed Mar 9, 2021
1 parent ee68f7c commit 42ce09a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 129 deletions.
29 changes: 2 additions & 27 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view/>
<router-view />
</div>
</template>

<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
<style lang="scss"></style>
60 changes: 0 additions & 60 deletions src/components/HelloWorld.vue

This file was deleted.

32 changes: 32 additions & 0 deletions src/components/Node.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div
class="node"
:class="[
node.isFinish ? 'finish-node' : '',
node.isStart ? 'start-node' : '',
]"
></div>
</template>

<script>
export default {
props: ["node"],
};
</script>

<style>
.node {
height: 25px;
width: 25px;
outline: 1px solid rgb(192, 191, 191);
display: inline-block;
}
.finish-node {
background: red;
}
.start-node {
background: green;
}
</style>
30 changes: 11 additions & 19 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Vue from "vue";
import VueRouter from "vue-router";
import PathfindingVisualizer from "../views/PathfindingVisualizer";

Vue.use(VueRouter)
Vue.use(VueRouter);

const routes = [
{
path: '/',
name: 'Home',
component: Home
name: "Pathfinding Visializer",
path: "/",
component: PathfindingVisualizer,
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
];

const router = new VueRouter({
routes
})
routes,
});

export default router
export default router;
5 changes: 0 additions & 5 deletions src/views/About.vue

This file was deleted.

18 changes: 0 additions & 18 deletions src/views/Home.vue

This file was deleted.

67 changes: 67 additions & 0 deletions src/views/PathfindingVisualizer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<div class="container">
<div class="grid" v-for="(row, rowIndex) in grid" :key="rowIndex">
<Node v-for="(col, colIndex) in row" :key="colIndex" :node="col"></Node>
</div>
</div>
</template>

<script>
import Node from "../components/Node.vue";
export default {
components: { Node },
data() {
return {
START_NODE_ROW: 10,
START_NODE_COL: 10,
FINISH_NODE_ROW: 15,
FINISH_NODE_COL: 15,
grid: [],
};
},
methods: {
getInitialGrid() {
const grid = [];
for (let row = 0; row < 30; row++) {
const currentRow = [];
for (let col = 0; col < 30; col++) {
currentRow.push(this.createNode(col, row));
}
grid.push(currentRow);
}
return grid;
},
createNode(col, row) {
return {
col,
row,
isStart: row === this.START_NODE_ROW && col === this.START_NODE_COL,
isFinish: row === this.FINISH_NODE_ROW && col === this.FINISH_NODE_COL,
isVisited: false,
isWall: false,
previousNode: null,
};
},
},
mounted() {
this.grid = this.getInitialGrid();
},
};
</script>

<style>
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin-top: 200px;
}
</style>

0 comments on commit 42ce09a

Please sign in to comment.