contra code

by kordarei

HTML

<html>

  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>

  <body>
    <div id="app">
      <span v-if="cheats">Unlocked</span>
      <p v-text="JSON.stringify(keys)"></p>
    </div>
  </body>

</html>

Vue

export default {
  data() {
    return {
      cheats: false,
      keys: [],
      code: [
        'ArrowUp', 
        'ArrowUp', 
        'ArrowDown', 
        'ArrowDown', 
        'ArrowLeft', 
        'ArrowRight', 
        'ArrowLeft', 
        'ArrowRight', 
        'b', 
        'a', 
        'Enter'
      ],
    }	
  },
  methods: {
		keymonitor: function(event) {
      (this.code[this.keys.length] == event.key) ? this.keys.push(event.key) : this.keys = [] ;
      if (this.code.length === this.keys.length) this.cheats = true;
		},
	},
	created() {
		window.addEventListener('keydown', this.keymonitor)
	}
};



new Vue({
	el:'#app',
	mixins: [ contraCode ]
})