parent
b9b6760d2f
commit
5db4cdaaa3
|
@ -46787,12 +46787,8 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
||||||
register: function register() {
|
register: function register() {
|
||||||
this.$router.push('/register');
|
this.$router.push('/register');
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
computed: function computed() {
|
|
||||||
|
|
||||||
this.$forceUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -47241,10 +47237,6 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
||||||
console.log('Login Error: ' + registerError);
|
console.log('Login Error: ' + registerError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
computed: function computed() {
|
|
||||||
|
|
||||||
this.$forceUpdate();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48120,7 +48112,7 @@ var render = function() {
|
||||||
return _c("tr", { key: game.gameID }, [
|
return _c("tr", { key: game.gameID }, [
|
||||||
_c("td", [_vm._v(_vm._s(game.gameID))]),
|
_c("td", [_vm._v(_vm._s(game.gameID))]),
|
||||||
_vm._v(" "),
|
_vm._v(" "),
|
||||||
_c("td", [_vm._v(_vm._s(game.players[0]))]),
|
_c("td", [_vm._v(_vm._s(game.playerName))]),
|
||||||
_vm._v(" "),
|
_vm._v(" "),
|
||||||
_c("td", [
|
_c("td", [
|
||||||
_c(
|
_c(
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="game in games" :key="game.gameID">
|
<tr v-for="game in games" :key="game.gameID">
|
||||||
<td>{{ game.gameID }}</td>
|
<td>{{ game.gameID }}</td>
|
||||||
<td>{{ game.players[0] }}</td>
|
<td>{{ game.playerName }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-xs btn-primary" v-on:click.prevent="join(game)">Join</a>
|
<a class="btn btn-xs btn-primary" v-on:click.prevent="join(game)">Join</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -64,12 +64,6 @@ export default {
|
||||||
this.$router.push('/register');
|
this.$router.push('/register');
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
computed() {
|
|
||||||
|
|
||||||
this.$forceUpdate();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,7 @@ export default {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
computed(){
|
|
||||||
|
|
||||||
this.$forceUpdate();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<router-link to="/users">Users</router-link> -
|
<router-link to="/users">Users</router-link> -
|
||||||
@if(!Auth::user())
|
@if(!Auth::user())
|
||||||
<router-link to="/login">Login</router-link> -
|
<router-link to="/login">Login</router-link> -
|
||||||
|
|
||||||
<router-link to="/register">Register</router-link> -
|
<router-link to="/register">Register</router-link> -
|
||||||
@else
|
@else
|
||||||
<router-link to="/logout">Logout</router-link> -
|
<router-link to="/logout">Logout</router-link> -
|
||||||
@endif
|
@endif
|
||||||
<router-link to="/singletictactoe">SinglePlayer TicTacToe</router-link> -
|
<router-link to="/singletictactoe">SinglePlayer TicTacToe</router-link> -
|
||||||
<router-link to="/multitictactoe">Multiplayer TicTacToe</router-link>
|
<router-link to="/multitictactoe">Multiplayer TicTacToe</router-link>
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class GameList {
|
||||||
createGame(socketID) {
|
createGame(socketID) {
|
||||||
this.contadorID = this.contadorID+1;
|
this.contadorID = this.contadorID+1;
|
||||||
var game = new MemoryGame(this.contadorID, socketID);
|
var game = new MemoryGame(this.contadorID, socketID);
|
||||||
//game.players[1] = socketID;
|
|
||||||
this.games.set(game.gameID, game);
|
this.games.set(game.gameID, game);
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class MemoryGame {
|
||||||
this.gameEnded = false;
|
this.gameEnded = false;
|
||||||
this.gameStarted = false;
|
this.gameStarted = false;
|
||||||
this.gameOwner= gameOwnerSocket;
|
this.gameOwner= gameOwnerSocket;
|
||||||
this.playerTurn = 0;
|
this.playerTurn = 1;
|
||||||
this.winner = 0;
|
this.winner = 0;
|
||||||
this.boardImages;
|
this.boardImages;
|
||||||
this.boardHidden;
|
this.boardHidden;
|
||||||
|
@ -16,10 +16,8 @@ class MemoryGame {
|
||||||
this.players = [];
|
this.players = [];
|
||||||
this.playerScore = [];
|
this.playerScore = [];
|
||||||
this.join(gameOwnerSocket);
|
this.join(gameOwnerSocket);
|
||||||
this.piece1x=null;
|
this.piece1;
|
||||||
this.piece2x=null;
|
this.piece2;
|
||||||
this.piece1y=null;
|
|
||||||
this.piece2y=null;
|
|
||||||
this.pontuacao = 0;
|
this.pontuacao = 0;
|
||||||
this.winnerMessage = '';
|
this.winnerMessage = '';
|
||||||
this.array = [];
|
this.array = [];
|
||||||
|
@ -31,7 +29,7 @@ class MemoryGame {
|
||||||
case 2:
|
case 2:
|
||||||
this.line = 4;
|
this.line = 4;
|
||||||
this.column = 4;
|
this.column = 4;
|
||||||
gameStarted = true;
|
this.gameStarted = true;
|
||||||
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7];
|
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7];
|
||||||
populateMainBoard();
|
populateMainBoard();
|
||||||
populateInvisibleBoard();
|
populateInvisibleBoard();
|
||||||
|
@ -39,7 +37,7 @@ class MemoryGame {
|
||||||
case 3:
|
case 3:
|
||||||
this.line = 4;
|
this.line = 4;
|
||||||
this.column = 6;
|
this.column = 6;
|
||||||
gameStarted = true;
|
this.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];
|
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();
|
populateMainBoard();
|
||||||
populateInvisibleBoard();
|
populateInvisibleBoard();
|
||||||
|
@ -47,7 +45,7 @@ class MemoryGame {
|
||||||
case 4:
|
case 4:
|
||||||
this.line = 6;
|
this.line = 6;
|
||||||
this.column = 6;
|
this.column = 6;
|
||||||
gameStarted = true;
|
this.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,
|
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];
|
12,12,13,13,14,14,15,15,16,16,17,17];
|
||||||
populateMainBoard();
|
populateMainBoard();
|
||||||
|
@ -66,10 +64,8 @@ class MemoryGame {
|
||||||
}
|
}
|
||||||
|
|
||||||
populateMainBoard() {
|
populateMainBoard() {
|
||||||
for(var i = 0; i < this.line; i++) {
|
for(var i = 0; i < this.line*this.column; i++) {
|
||||||
for(var j = 0; j < this.column; j++) {
|
this.boardImages[i] = "hidden";
|
||||||
this.boardImages[i][j] = "hidden";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +74,7 @@ class MemoryGame {
|
||||||
console.log(array);
|
console.log(array);
|
||||||
|
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
this.boardImagens[i] = this.array[i];
|
this.boardImages[i] = this.array[i];
|
||||||
}
|
}
|
||||||
console.log(this.boardHidden);
|
console.log(this.boardHidden);
|
||||||
|
|
||||||
|
@ -86,10 +82,11 @@ class MemoryGame {
|
||||||
|
|
||||||
join(socketId){ // chamar pelo socket id do user
|
join(socketId){ // chamar pelo socket id do user
|
||||||
for(var i = 0; i < this.players.lenght; i++){
|
for(var i = 0; i < this.players.lenght; i++){
|
||||||
if (this.players[i] == socketId) { //compara o socket id dos jogadores
|
if (this.players[i] == socketId) { // se já estiver no jogo, então não conta
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// assegurado que o player é novo no jogo/lobby
|
||||||
this.numPlayers ++; //add 1 ao contador de jogadores
|
this.numPlayers ++; //add 1 ao contador de jogadores
|
||||||
this.players.push(socketId); // push do socket id do novo jogador para o jogo a que se juntou
|
this.players.push(socketId); // push do socket id do novo jogador para o jogo a que se juntou
|
||||||
}
|
}
|
||||||
|
@ -134,58 +131,75 @@ class MemoryGame {
|
||||||
|
|
||||||
isBoardComplete(){
|
isBoardComplete(){
|
||||||
|
|
||||||
for(let x=0; x<this.line; x++){
|
for(var i=0; i<this.boardImages.lenght; i++){
|
||||||
for(let y=0; y<this.column; y++){
|
if (this.boardImages[i] == "hidden") { //se houver alguma img hidden entao a board nao esta completa logo nao acabou o Jogo
|
||||||
if (this.boardHidden[x][y] == "hidden") { //se houver alguma img hidden em x e/ou y entao a board nao esta completa logo nao acabou o Jogo
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
calculatePlayerScore(player){
|
|
||||||
|
|
||||||
//calcula o score com base na posiçao x e y que carregou
|
|
||||||
for(let x=0; x<this.line; x++){
|
|
||||||
for(let y=0; y<this.column; y++){
|
|
||||||
if (this.boardImages[x][y] == player){
|
|
||||||
this.playerScore[player]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
play(playerNumber, index){
|
play(playerNumber, index){
|
||||||
|
|
||||||
//jogo ja começou
|
//jogo ja começou
|
||||||
|
if(!this.gameStarted) {
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
//jogo ainda nao acabou
|
//jogo ainda nao acabou
|
||||||
|
if(this.gameEnded) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//Estado da quadricula ? hidden ? Jogada valida
|
//Estado da quadricula ? hidden ? Jogada valida
|
||||||
|
if (this.boardImages[index] == "hidden") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//player turn = 1 entao 1ª jogada do jogador e tem de virar a 2ª peça
|
//player turn = 1 entao 1ª jogada do jogador e tem de virar a 2ª peça
|
||||||
// SE o player turn =1 vira 1ª carta e playerturn ++
|
// SE o player turn =1 vira 1ª carta e playerturn ++
|
||||||
|
if (this.playerTurn == 1) {
|
||||||
|
this.piece1 = index;
|
||||||
|
this.boardImages[index] = this.boardHidden[index];
|
||||||
|
this.playerTurn++;
|
||||||
|
console.log("1ª play");
|
||||||
|
} else if (this.playerTurn == 2) {
|
||||||
|
// se playerTurn = 2 vira se a 2ª carta
|
||||||
|
this.piece2 = index;
|
||||||
|
this.boardImages[index] = this.boardHidden[index];
|
||||||
|
isPair(playerNumber);
|
||||||
|
this.playerTurn = 1;
|
||||||
|
console.log("2ª play");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// se playerTurn = 2 vira se a 2ª carta
|
isPair(playerNumber) {
|
||||||
|
if (this.boardImages[this.piece1] === this.boardImages[this.piece2]) {
|
||||||
// obter o "nome" das 2 cartas e comprar
|
console.log("You found a pair!");
|
||||||
|
// pontuação ++
|
||||||
// se for par (as duas o mesmo nome) entao pontuaçao++, cartas escolhidas visiveis sempre, e o plyer tem novo playerTurn
|
this.playerScore[playerNumber]++;
|
||||||
|
// main board fica virado para cima nas duas posições
|
||||||
//se nao passa a jogada pro proximo jogador.
|
this.boardImages[this.piece1] = this.boardHidden[this.piece1];
|
||||||
// cartas hidden (mesmo as que foram escolhidas) player playerTurn=1
|
this.boardImages[this.piece2] = this.boardHidden[this.piece2];
|
||||||
|
} else {
|
||||||
//return true
|
console.log("Nice try, it's not a pair! MUAHAHAHAHAHAH");
|
||||||
|
this.boardImages[this.piece1] = "hidden";
|
||||||
|
this.boardImages[this.piece2] = "hidden";;
|
||||||
|
|
||||||
|
nextTurn(playerNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextTurn() {
|
||||||
|
this.players[playerNumber++];
|
||||||
|
if(this.playerNumber > this.players.lenght) {
|
||||||
|
this.playerNumber = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shuffleArray(){
|
shuffleArray(){
|
||||||
// shuffle do array array
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var j = 0;
|
var j = 0;
|
||||||
var temp = null;
|
var temp = null;
|
||||||
|
|
|
@ -36,7 +36,7 @@ io.on('connection', function (socket) {
|
||||||
console.log('client has connected');
|
console.log('client has connected');
|
||||||
|
|
||||||
socket.on('create_game', function (data){
|
socket.on('create_game', function (data){
|
||||||
let game = games.createGame(socket.id);
|
let game = games.createGame(data.playerName, socket.id);
|
||||||
socket.join(game.gameID);
|
socket.join(game.gameID);
|
||||||
console.log('game was created');
|
console.log('game was created');
|
||||||
// Notifications to the client
|
// Notifications to the client
|
||||||
|
|
Loading…
Reference in New Issue