Skip to content

Instantly share code, notes, and snippets.

@elxris
Created May 7, 2016 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elxris/9acdb110c67a4ae447570e62b9a89c55 to your computer and use it in GitHub Desktop.
Save elxris/9acdb110c67a4ae447570e62b9a89c55 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body class="indigo">
<div class="row" id="game">
<div class="col s8 offset-s2">
<div class="col s4" v-for="n in 9">
<a class="waves-effect waves-light btn"
v-on:click="jugada(n)">{{gato[n] || '_'}}</a>
</div>
<h4 class="white-text" v-if="!ganador">Es el turno de {{turno}}</h4>
<h4 class="white-text" v-if="ganador">Gana {{ganador}}!</h4>
</div>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.21/vue.min.js"></script>
<script type="text/javascript">
var data = {
gato: {
'0': '','1': '','2': '',
'3': '','4': '','5': '',
'6': '','7': '','8': ''
},
turno: 'x',
ganador: ''
};
var vue = new Vue({
el: '#game',
data: data,
methods: {
jugada: function(n) {
console.log(!!this.gato[n]);
if (this.gato[n]) {
return;
}
this.gato[n] = this.turno;
if(
this.gato && this.gato[0] === this.gato[1] === this.gato[2] ||
this.gato && this.gato[3] === this.gato[4] === this.gato[5] ||
this.gato && this.gato[6] === this.gato[7] === this.gato[8] ||
this.gato && this.gato[0] === this.gato[3] === this.gato[6] ||
this.gato && this.gato[1] === this.gato[4] === this.gato[7] ||
this.gato && this.gato[2] === this.gato[5] === this.gato[8] ||
this.gato && this.gato[0] === this.gato[4] === this.gato[8] ||
this.gato && this.gato[2] === this.gato[4] === this.gato[6]
) {
console.log('Gana', this.turno);
this.ganador = this.turno;
}
console.log(this.turno);
this.turno = this.turno === 'x' ? 'o' : 'x';
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment