SHARE
TWEET

Untitled

a guest Oct 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div v-if="!hasRun" class="maze-game-ascii">
  3.     <pre>{{ emptyMaze() }}</pre>
  4.   </div>
  5.   <div v-else>
  6.     <div class="maze-game-ascii">
  7.       <pre>{{ getMaze() }}</pre>
  8.     </div>
  9.   </div>
  10. </template>
  11.  
  12. <script>
  13. export default {
  14.   data() {
  15.     return {
  16.       gameState: null,
  17.     };
  18.   },
  19.   methods: {
  20.     async createGameSession() {
  21.       this.gameViz = {
  22.         Blocked: "██",
  23.         Exit: "▒▒",
  24.         Open: "  ",
  25.         Player: "⋐⋑",
  26.       };
  27.       this.gameState = (await this.$axios.get("/api/game/maze/map", {
  28.         headers: { "X-TOKEN": "5e017a67-2080-4a76-9f41-010cc1556e3a" },
  29.       })).data;
  30.     },
  31.     async getMaze() {
  32.       this.createGameSession();
  33.  
  34.       const map = this.gameState.map;
  35.       const [playerX, playerY] = [
  36.         this.gameState.player.x,
  37.         this.gameState.player.y,
  38.       ];
  39.       const [exitX, exitY] = [this.gameState.exit.x, this.gameState.exit.y];
  40.       map[playerY][playerX] = "Player";
  41.       map[exitY][exitX] = "Exit";
  42.  
  43.       return map.map(x => x.map(y => this.gameViz[y]).join("")).join("\n");
  44.     },
  45.     emptyMaze() {
  46.       return Array.from({ length: 10 }, x => " ".repeat(20)).join("\n");
  47.     },
  48.   },
  49.   computed: {
  50.     hasRun() {
  51.       return this.$store.state.run;
  52.     },
  53.   },
  54. };
  55. </script>
  56.  
  57. <style scoped>
  58. .maze-game-ascii {
  59.   display: flex;
  60.   align-items: center;
  61.   justify-content: center;
  62. }
  63.  
  64. .maze-game-ascii > pre {
  65.   border: solid 4px #373737;
  66.   font-size: 2.25vw;
  67. }
  68. </style>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top