logic game started
populate boards, trying create new games (join) need to show players.master
parent
df923c49a3
commit
b9b6760d2f
|
@ -48120,7 +48120,7 @@ var render = function() {
|
|||
return _c("tr", { key: game.gameID }, [
|
||||
_c("td", [_vm._v(_vm._s(game.gameID))]),
|
||||
_vm._v(" "),
|
||||
_c("td", [_vm._v(_vm._s(game.player1))]),
|
||||
_c("td", [_vm._v(_vm._s(game.players[0]))]),
|
||||
_vm._v(" "),
|
||||
_c("td", [
|
||||
_c(
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<tbody>
|
||||
<tr v-for="game in games" :key="game.gameID">
|
||||
<td>{{ game.gameID }}</td>
|
||||
<td>{{ game.player1 }}</td>
|
||||
<td>{{ game.players[0] }}</td>
|
||||
<td>
|
||||
<a class="btn btn-xs btn-primary" v-on:click.prevent="join(game)">Join</a>
|
||||
</td>
|
||||
|
@ -26,11 +26,11 @@
|
|||
methods: {
|
||||
join(game) {
|
||||
this.$emit('join-click', game);
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -22,6 +22,66 @@ class MemoryGame {
|
|||
this.piece2y=null;
|
||||
this.pontuacao = 0;
|
||||
this.winnerMessage = '';
|
||||
this.array = [];
|
||||
}
|
||||
|
||||
startGame(){
|
||||
switch(this.numPlayers) {
|
||||
case 1:
|
||||
case 2:
|
||||
this.line = 4;
|
||||
this.column = 4;
|
||||
gameStarted = true;
|
||||
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7];
|
||||
populateMainBoard();
|
||||
populateInvisibleBoard();
|
||||
break;
|
||||
case 3:
|
||||
this.line = 4;
|
||||
this.column = 6;
|
||||
gameStarted = true;
|
||||
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11];
|
||||
populateMainBoard();
|
||||
populateInvisibleBoard();
|
||||
break;
|
||||
case 4:
|
||||
this.line = 6;
|
||||
this.column = 6;
|
||||
gameStarted = true;
|
||||
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,
|
||||
12,12,13,13,14,14,15,15,16,16,17,17];
|
||||
populateMainBoard();
|
||||
populateInvisibleBoard();
|
||||
break;
|
||||
}
|
||||
zerarPontuacoes();
|
||||
this.winner = 0;
|
||||
this.gameEnded = false;
|
||||
}
|
||||
|
||||
zerarPontuacoes() {
|
||||
for ( var i = 0; i < this.playerScore.lenght; i++ ) {
|
||||
this.playerScore[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
populateMainBoard() {
|
||||
for(var i = 0; i < this.line; i++) {
|
||||
for(var j = 0; j < this.column; j++) {
|
||||
this.boardImages[i][j] = "hidden";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
populateInvisibleBoard() {
|
||||
shuffleArray();
|
||||
console.log(array);
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
this.boardImagens[i] = this.array[i];
|
||||
}
|
||||
console.log(this.boardHidden);
|
||||
|
||||
}
|
||||
|
||||
join(socketId){ // chamar pelo socket id do user
|
||||
|
@ -124,16 +184,19 @@ class MemoryGame {
|
|||
|
||||
}
|
||||
|
||||
shuffleArray(array){
|
||||
let arraySize = array.length;
|
||||
while(arraySize > 0){
|
||||
let index = Math.floor(Math.random()* arraySize);
|
||||
arraySize --;
|
||||
let temp = array[arraySize];
|
||||
array[arraySize] = array[index];
|
||||
array[index] = temp;
|
||||
}
|
||||
return array;
|
||||
shuffleArray(){
|
||||
// shuffle do array array
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var temp = null;
|
||||
|
||||
for (i = this.array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = this.array[i];
|
||||
this.array[i] = this.array[j];
|
||||
this.array[j] = temp;
|
||||
}
|
||||
return this.array;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue