parent
afe07336e2
commit
fa30b844a1
|
@ -47471,7 +47471,7 @@ exports = module.exports = __webpack_require__(2)(false);
|
|||
|
||||
|
||||
// module
|
||||
exports.push([module.i, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", ""]);
|
||||
exports.push([module.i, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", ""]);
|
||||
|
||||
// exports
|
||||
|
||||
|
@ -47508,164 +47508,201 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
|||
//
|
||||
|
||||
/* harmony default export */ __webpack_exports__["default"] = ({
|
||||
data: function data() {
|
||||
return {
|
||||
title: 'Memory Game',
|
||||
showSuccess: false,
|
||||
showFailure: false,
|
||||
successMessage: '',
|
||||
failMessage: '',
|
||||
currentValue: 1,
|
||||
gameEnded: false,
|
||||
player1User: undefined,
|
||||
board: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
numeroJogada: 0,
|
||||
piece1: 0,
|
||||
piece2: 0,
|
||||
pontuacao: 0,
|
||||
boardImagens: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
};
|
||||
},
|
||||
created: function created() {
|
||||
// populate array
|
||||
var array = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
|
||||
// shuffle do array array
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var temp = null;
|
||||
data: function data() {
|
||||
return {
|
||||
title: 'Memory Game',
|
||||
showSuccess: false,
|
||||
showFailure: false,
|
||||
successMessage: '',
|
||||
failMessage: '',
|
||||
currentValue: 1,
|
||||
gameEnded: false,
|
||||
player1User: undefined,
|
||||
board: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
numeroJogada: 0,
|
||||
piece1: 0,
|
||||
piece2: 0,
|
||||
pontuacao: 0,
|
||||
boardImagens: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
};
|
||||
},
|
||||
created: function created() {
|
||||
// populate array
|
||||
var array = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
|
||||
// shuffle do array array
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var temp = null;
|
||||
|
||||
for (i = array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
// console.log("created " + array);
|
||||
for (i = array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
// console.log("created " + array);
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
this.boardImagens[i] = array[i];
|
||||
}
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
this.boardImagens[i] = array[i];
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.board.length; i++) {
|
||||
this.board[i] = "hidden";
|
||||
}
|
||||
// console.log("created imagens " + this.boardImagens);
|
||||
this.populateMainBoard();
|
||||
|
||||
},
|
||||
// console.log("created imagens " + this.boardImagens);
|
||||
},
|
||||
|
||||
methods: {
|
||||
methods: {
|
||||
populateMainBoard: function populateMainBoard() {
|
||||
for (var i = 0; i < this.board.length; i++) {
|
||||
this.board[i] = "hidden";
|
||||
}
|
||||
},
|
||||
|
||||
clickPiece: function clickPiece(index) {
|
||||
// console.log("created clickepiece " + this.boardImagens);
|
||||
if (this.board[index] != "hidden") {
|
||||
return;
|
||||
}
|
||||
clickPiece: function clickPiece(index) {
|
||||
// console.log("created clickepiece " + this.boardImagens);
|
||||
if (this.board[index] != "hidden") {
|
||||
return;
|
||||
}
|
||||
|
||||
this.board[index] = this.boardImagens[index];
|
||||
this.numeroJogada++;
|
||||
if (this.numeroJogada == 1) {
|
||||
this.piece1 = index;
|
||||
console.log("Jogada 1");
|
||||
console.log(this.boardImagens[index]);
|
||||
this.showSuccess = true;
|
||||
this.showSuccess = "Para jogar novamente, feche esta cena!";
|
||||
}
|
||||
if (this.numeroJogada == 2) {
|
||||
this.piece2 = index;
|
||||
console.log("Jogada 2");
|
||||
console.log(this.boardImagens[index]);
|
||||
this.showSuccess = true;
|
||||
this.showSuccess = "Para jogar novamente, feche esta cena!";
|
||||
this.board[index] = this.boardImagens[index];
|
||||
this.numeroJogada++;
|
||||
if (this.numeroJogada == 1) {
|
||||
this.piece1 = index;
|
||||
console.log("Jogada 1");
|
||||
console.log(this.boardImagens[index]);
|
||||
this.showSuccess = true;
|
||||
this.showSuccess = "Para jogar novamente, feche esta cena!";
|
||||
}
|
||||
if (this.numeroJogada == 2) {
|
||||
this.piece2 = index;
|
||||
console.log("Jogada 2");
|
||||
console.log(this.boardImagens[index]);
|
||||
this.showSuccess = true;
|
||||
this.showSuccess = "Para jogar novamente, feche esta cena!";
|
||||
|
||||
if (this.boardImagens[this.piece1] == this.boardImagens[this.piece2]) {
|
||||
// comparar no vetor boardImagens com as posições do arrayJogadas
|
||||
// bloqueio das posições selecionadas
|
||||
// pontuação ++;
|
||||
this.pontuacao = this.pontuacao + 10;
|
||||
this.boardImagens[this.piece1] = this.boardImagens[this.piece1];
|
||||
this.boardImagens[this.piece2] = this.boardImagens[this.piece2];
|
||||
// same player playing
|
||||
console.log("imagens iguais");
|
||||
} else {
|
||||
// quer dizer que são diferentes
|
||||
// volta-se a virar as cartas para imagem limpa
|
||||
this.board[this.piece1] = "hidden";
|
||||
this.board[this.piece2] = "hidden";
|
||||
this.piece1 = null;
|
||||
this.piece2 = null;
|
||||
if (this.boardImagens[this.piece1] == this.boardImagens[this.piece2]) {
|
||||
// comparar no vetor boardImagens com as posições do arrayJogadas
|
||||
// bloqueio das posições selecionadas
|
||||
// pontuação ++;
|
||||
this.pontuacao = this.pontuacao + 10;
|
||||
this.boardImagens[this.piece1] = this.boardImagens[this.piece1];
|
||||
this.boardImagens[this.piece2] = this.boardImagens[this.piece2];
|
||||
// same player playing
|
||||
console.log("imagens iguais");
|
||||
} else {
|
||||
// quer dizer que são diferentes
|
||||
// volta-se a virar as cartas para imagem limpa
|
||||
setTimeout(this.resetData, 2000);
|
||||
// this.board[this.piece1] = "hidden";
|
||||
// this.board[this.piece2] = "hidden";
|
||||
// this.piece1 = null;
|
||||
// this.piece2 = null;
|
||||
// console.log("imagens diferentes");
|
||||
}
|
||||
this.numeroJogada = 0;
|
||||
if (this.isBoardComplete()) {
|
||||
this.successMessage = "Congratz, you won!";
|
||||
this.gameEnded = true;
|
||||
this.showSuccess = true;
|
||||
}
|
||||
}
|
||||
index = null;
|
||||
},
|
||||
resetData: function resetData() {
|
||||
this.board[this.piece1] = "hidden";
|
||||
this.board[this.piece2] = "hidden";
|
||||
this.piece1 = null;
|
||||
this.piece2 = null;
|
||||
console.log("imagens diferentes");
|
||||
},
|
||||
pieceImageURL: function pieceImageURL(piece) {
|
||||
var imgSrc = String(piece);
|
||||
//console.log(imgSrc);
|
||||
return 'img/' + imgSrc + '.png';
|
||||
},
|
||||
|
||||
console.log("imagens diferentes");
|
||||
}
|
||||
this.numeroJogada = 0;
|
||||
}
|
||||
index = null;
|
||||
},
|
||||
restartGame: function restartGame() {
|
||||
console.log('restartGame');
|
||||
this.board = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
this.showSuccess = false;
|
||||
this.showFailure = false;
|
||||
this.successMessage = '';
|
||||
this.failMessage = '';
|
||||
this.currentValue = 1;
|
||||
this.gameEnded = false;
|
||||
this.numeroJogada = 0, this.piece1 = 0, this.piece2 = 0, this.pontuacao = 0, this.boardImagens = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
pieceImageURL: function pieceImageURL(piece) {
|
||||
var imgSrc = String(piece);
|
||||
//console.log(imgSrc);
|
||||
return 'img/' + imgSrc + '.png';
|
||||
},
|
||||
// populate array
|
||||
var array = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
|
||||
// shuffle do array array
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var temp = null;
|
||||
|
||||
restartGame: function restartGame() {
|
||||
console.log('restartGame');
|
||||
this.board = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
this.showSuccess = false;
|
||||
this.showFailure = false;
|
||||
this.successMessage = '';
|
||||
this.failMessage = '';
|
||||
this.currentValue = 1;
|
||||
this.gameEnded = false;
|
||||
},
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// GAME LOGIC - START
|
||||
// ----------------------------------------------------------------------------------------
|
||||
hasRow: function hasRow(value) {
|
||||
return this.board[0] == value && this.board[1] == value && this.board[2] == value || this.board[3] == value && this.board[4] == value && this.board[5] == value || this.board[6] == value && this.board[7] == value && this.board[8] == value || this.board[0] == value && this.board[3] == value && this.board[6] == value || this.board[1] == value && this.board[4] == value && this.board[7] == value || this.board[2] == value && this.board[5] == value && this.board[8] == value || this.board[0] == value && this.board[4] == value && this.board[8] == value || this.board[2] == value && this.board[4] == value && this.board[6] == value;
|
||||
},
|
||||
checkGameEnded: function checkGameEnded() {
|
||||
if (this.isBoardComplete()) {
|
||||
this.successMessage = this.playerName(1) + ', you win!';
|
||||
this.showSuccess = true;
|
||||
this.gameEnded = true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isBoardComplete: function isBoardComplete() {
|
||||
var returnValue = true;
|
||||
this.board.forEach(function (element) {
|
||||
if (element === 0) {
|
||||
returnValue = false;
|
||||
return;
|
||||
}
|
||||
});
|
||||
return returnValue;
|
||||
},
|
||||
for (i = array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
// console.log("created " + array);
|
||||
|
||||
playerName: function playerName(playerNumber) {
|
||||
if (this.player1User != undefined && playerNumber == 1) {
|
||||
return this.player1User.name;
|
||||
}
|
||||
if (this.player2User != undefined && playerNumber == 2) {
|
||||
return this.player2User.name;
|
||||
}
|
||||
return 'Player ' + playerNumber;
|
||||
}
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
this.boardImagens[i] = array[i];
|
||||
}
|
||||
|
||||
},
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// GAME LOGIC - END
|
||||
// ----------------------------------------------------------------------------------------
|
||||
computed: {
|
||||
currentPlayer: function currentPlayer() {
|
||||
return this.playerName(this.currentValue);
|
||||
}
|
||||
},
|
||||
mounted: function mounted() {
|
||||
if (this.$root.$data.player1) {
|
||||
this.player1User = this.$root.$data.player1;
|
||||
}
|
||||
}
|
||||
this.populateMainBoard();
|
||||
|
||||
// console.log("created imagens " + this.boardImagens);
|
||||
},
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// GAME LOGIC - START
|
||||
// ----------------------------------------------------------------------------------------
|
||||
hasRow: function hasRow(value) {
|
||||
return this.board[0] == value && this.board[1] == value && this.board[2] == value || this.board[3] == value && this.board[4] == value && this.board[5] == value || this.board[6] == value && this.board[7] == value && this.board[8] == value || this.board[0] == value && this.board[3] == value && this.board[6] == value || this.board[1] == value && this.board[4] == value && this.board[7] == value || this.board[2] == value && this.board[5] == value && this.board[8] == value || this.board[0] == value && this.board[4] == value && this.board[8] == value || this.board[2] == value && this.board[4] == value && this.board[6] == value;
|
||||
},
|
||||
checkGameEnded: function checkGameEnded() {
|
||||
if (this.isBoardComplete()) {
|
||||
this.successMessage = this.playerName(1) + ', you win!';
|
||||
this.showSuccess = true;
|
||||
this.gameEnded = true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isBoardComplete: function isBoardComplete() {
|
||||
for (var i = 0; i < this.board.lenght; i++) {
|
||||
if (this.board[i] == "hidden") {
|
||||
//se houver alguma img hidden entao a board nao esta completa logo nao acabou o Jogo
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
playerName: function playerName(playerNumber) {
|
||||
if (this.player1User != undefined && playerNumber == 1) {
|
||||
return this.player1User.name;
|
||||
}
|
||||
if (this.player2User != undefined && playerNumber == 2) {
|
||||
return this.player2User.name;
|
||||
}
|
||||
return 'Player ' + playerNumber;
|
||||
}
|
||||
|
||||
},
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// GAME LOGIC - END
|
||||
// ----------------------------------------------------------------------------------------
|
||||
computed: {
|
||||
currentPlayer: function currentPlayer() {
|
||||
return this.playerName(this.currentValue);
|
||||
}
|
||||
},
|
||||
mounted: function mounted() {
|
||||
if (this.$root.$data.player1) {
|
||||
this.player1User = this.$root.$data.player1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -62,15 +62,17 @@
|
|||
this.boardImagens[i] = array[i];
|
||||
}
|
||||
|
||||
this.populateMainBoard();
|
||||
|
||||
for (var i = 0; i < this.board.length; i++) {
|
||||
this.board[i] = "hidden";
|
||||
}
|
||||
// console.log("created imagens " + this.boardImagens);
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
populateMainBoard: function() {
|
||||
for (var i = 0; i < this.board.length; i++) {
|
||||
this.board[i] = "hidden";
|
||||
}
|
||||
},
|
||||
|
||||
clickPiece: function(index) {
|
||||
// console.log("created clickepiece " + this.boardImagens);
|
||||
|
@ -93,7 +95,7 @@
|
|||
console.log(this.boardImagens[index]);
|
||||
this.showSuccess = true;
|
||||
this.showSuccess = "Para jogar novamente, feche esta cena!";
|
||||
|
||||
|
||||
if (this.boardImagens[this.piece1] == this.boardImagens[this.piece2]){ // comparar no vetor boardImagens com as posições do arrayJogadas
|
||||
// bloqueio das posições selecionadas
|
||||
// pontuação ++;
|
||||
|
@ -104,24 +106,30 @@
|
|||
console.log("imagens iguais");
|
||||
} else { // quer dizer que são diferentes
|
||||
// volta-se a virar as cartas para imagem limpa
|
||||
this.board[this.piece1] = "hidden";
|
||||
this.board[this.piece2] = "hidden";
|
||||
this.piece1 = null;
|
||||
this.piece2 = null;
|
||||
setTimeout(this.resetData, 2000);
|
||||
// this.board[this.piece1] = "hidden";
|
||||
// this.board[this.piece2] = "hidden";
|
||||
// this.piece1 = null;
|
||||
// this.piece2 = null;
|
||||
// console.log("imagens diferentes");
|
||||
|
||||
console.log("imagens diferentes");
|
||||
}
|
||||
this.numeroJogada = 0;
|
||||
|
||||
|
||||
|
||||
if (this.isBoardComplete()) {
|
||||
this.successMessage = "Congratz, you won!";
|
||||
this.gameEnded = true;
|
||||
this.showSuccess = true;
|
||||
}
|
||||
}
|
||||
index = null;
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
resetData: function() {
|
||||
this.board[this.piece1] = "hidden";
|
||||
this.board[this.piece2] = "hidden";
|
||||
this.piece1 = null;
|
||||
this.piece2 = null;
|
||||
console.log("imagens diferentes");
|
||||
},
|
||||
pieceImageURL: function (piece) {
|
||||
var imgSrc = String(piece);
|
||||
//console.log(imgSrc);
|
||||
|
@ -137,6 +145,34 @@
|
|||
this.failMessage= '';
|
||||
this.currentValue= 1;
|
||||
this.gameEnded= false;
|
||||
this.numeroJogada = 0,
|
||||
this.piece1 = 0,
|
||||
this.piece2 = 0,
|
||||
this.pontuacao = 0,
|
||||
this.boardImagens = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
|
||||
// populate array
|
||||
var array = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8];
|
||||
// shuffle do array array
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var temp = null;
|
||||
|
||||
for (i = array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
// console.log("created " + array);
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
this.boardImagens[i] = array[i];
|
||||
}
|
||||
|
||||
this.populateMainBoard();
|
||||
|
||||
// console.log("created imagens " + this.boardImagens);
|
||||
},
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// GAME LOGIC - START
|
||||
|
@ -160,14 +196,12 @@
|
|||
return false;
|
||||
},
|
||||
isBoardComplete:function(){
|
||||
var returnValue = true;
|
||||
this.board.forEach(function(element) {
|
||||
if (element === 0) {
|
||||
returnValue = false;
|
||||
return;
|
||||
}
|
||||
});
|
||||
return returnValue;
|
||||
for(let i=0; i<this.board.lenght; i++){
|
||||
if (this.board[i] == "hidden") { //se houver alguma img hidden entao a board nao esta completa logo nao acabou o Jogo
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
playerName: function(playerNumber){
|
||||
|
|
Loading…
Reference in New Issue