Compare commits

...

5 Commits

Author SHA1 Message Date
Paulo Vieira 70ccaf34ef last commit
entrega final do projecto
2018-01-13 18:27:23 +00:00
Paulo Vieira 75023d7aa5 singleplayer
singleplayer esta funcional à mesma
settimeout é uma operaç\ao nao bloqueante então nao esta a 100%
2018-01-13 15:22:49 +00:00
Paulo Vieira fa30b844a1 single player
restart ja funca, falta timeout
2018-01-12 17:59:45 +00:00
Paulo Vieira afe07336e2 singleplayer
singleplayer já é jogável, com alguns problemas, mas já se joga <3
2018-01-12 17:00:22 +00:00
Paulo Vieira c924322c89 Board! 2018-01-12 11:41:23 +00:00
17 changed files with 699 additions and 402 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Auth;
use Mail;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
@ -70,4 +71,15 @@ class RegisterController extends Controller
'username' => $data['email']
]);
}
protected function sendEmail(Request $request)
{
$message = "Please click here to activate your account";
mail($request['email'], 'MemoryGame Activation Account', $message);
}
}

View File

@ -8,6 +8,7 @@ use Illuminate\Contracts\Support\Jsonable;
use App\Http\Resources\User as UserResource;
use Illuminate\Support\Facades\DB;
use App\Mail\Mail;
use App\User;
use App\StoreUserRequest;
use Hash;
@ -40,6 +41,11 @@ class UserControllerAPI extends Controller
$user->fill($request->all());
$user->password = Hash::make($user->password);
$user->save();
auth()->login($user);
\Mail::to($user)->send(new Mail);
return response()->json(new UserResource($user), 201);
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Mail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('confirm.email');
}
}

View File

@ -6,4 +6,21 @@
.error {
color: red;
}
}
.board {
max-width: 450px;
margin: 0 auto;
border-style: solid;
border-width: 0px 0 0 0px;
border-color: black;
}
.board img {
width: 80px;
height: 80px;
margin: 5px;
padding: 0;
border-style: none;
}

View File

@ -1409,9 +1409,9 @@ Vue.use(__WEBPACK_IMPORTED_MODULE_1_vue_socket_io___default.a, 'http://192.168.1
var user = Vue.component('user', __webpack_require__(43));
var login = Vue.component('login', __webpack_require__(59));
var logout = Vue.component('logout', __webpack_require__(62));
var register = Vue.component('register', __webpack_require__(67));
var singleplayer_game = Vue.component('singlegame', __webpack_require__(70));
var multiplayerGame = Vue.component('multiplayergame', __webpack_require__(75));
var register = Vue.component('register', __webpack_require__(66));
var singleplayer_game = Vue.component('singlegame', __webpack_require__(69));
var multiplayerGame = Vue.component('multiplayergame', __webpack_require__(74));
var routes = [{ path: '/', redirect: '/users' }, { path: '/users', component: user }, { path: '/login', component: login }, { path: '/logout', component: logout }, { path: '/register', component: register }, { path: '/singletictactoe', component: singleplayer_game }, { path: '/multitictactoe', component: multiplayerGame }];
@ -46770,13 +46770,16 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
headers: { 'Content-Type': 'application/json' }
}).then(function (response) {
// buscar o token do user logado
console.log('Response: ' + response);
console.log('Response: ');
console.log(response);
var token = response.data.access_token;
// guardar na localStorage o token
localStorage.setItem('token', token);
localStorage.setItem('token', JSON.stringify(token));
// user já se encontra logado e com a sessão guardada
_this.$router.push('/');
app.$forceUpdate();
console.log("after update view");
}).catch(function (loginError) {
// Something went wrong!
console.log('Login Error: ' + loginError);
@ -46922,7 +46925,7 @@ var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(65)
/* template */
var __vue_template__ = __webpack_require__(66)
var __vue_template__ = __webpack_require__(89)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -47043,15 +47046,15 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
var head = {
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('token'),
'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('token')),
'Accept': 'application/json'
}
};
axios.post('/api/logout', null, head).then(function (response) {
if (response.status == 200) {
window.localStorage.removeItem('token');
console.log("Token removed");
window.localStorage.clear();
console.log("logout sucessfull");
_this.$router.push('/login');
}
}).catch(function (error) {
@ -47065,66 +47068,12 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* 66 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("div", { staticClass: "container" }, [
_c("div", { staticClass: "row" }, [
_c("div", { staticClass: "col-md-8 col-md-offset-2" }, [
_c("h1", [_vm._v("Logout")]),
_vm._v(" "),
_c("p", [_c("em", [_vm._v(_vm._s(_vm.message))])]),
_vm._v(" "),
_c(
"div",
{ staticClass: "text-left" },
[
_c(
"button",
{
staticClass: "btn btn-primary",
on: {
click: function($event) {
_vm.logout()
}
}
},
[_vm._v("Logout")]
),
_vm._v(" "),
_c(
"router-link",
{ staticClass: "btn btn-default", attrs: { to: "/users" } },
[_vm._v("Cancel")]
)
],
1
)
])
])
])
}
var staticRenderFns = []
render._withStripped = true
module.exports = { render: render, staticRenderFns: staticRenderFns }
if (false) {
module.hot.accept()
if (module.hot.data) {
require("vue-hot-reload-api") .rerender("data-v-12a7f961", module.exports)
}
}
/***/ }),
/* 67 */
/***/ (function(module, exports, __webpack_require__) {
var disposed = false
var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(68)
var __vue_script__ = __webpack_require__(67)
/* template */
var __vue_template__ = __webpack_require__(69)
var __vue_template__ = __webpack_require__(68)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -47164,7 +47113,7 @@ module.exports = Component.exports
/***/ }),
/* 68 */
/* 67 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
@ -47203,6 +47152,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
//
//
//
/* harmony default export */ __webpack_exports__["default"] = ({
@ -47228,6 +47178,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
name: this.user.name,
username: this.user.email
}).then(function (response) {
// enviar email de autenticação
console.log(response);
_this.$router.push('/');
}).catch(function (registerError) {
@ -47241,7 +47192,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
});
/***/ }),
/* 69 */
/* 68 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
@ -47386,19 +47337,19 @@ if (false) {
}
/***/ }),
/* 70 */
/* 69 */
/***/ (function(module, exports, __webpack_require__) {
var disposed = false
function injectStyle (ssrContext) {
if (disposed) return
__webpack_require__(71)
__webpack_require__(70)
}
var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(73)
var __vue_script__ = __webpack_require__(72)
/* template */
var __vue_template__ = __webpack_require__(74)
var __vue_template__ = __webpack_require__(73)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -47437,13 +47388,13 @@ module.exports = Component.exports
/***/ }),
/* 71 */
/* 70 */
/***/ (function(module, exports, __webpack_require__) {
// style-loader: Adds some css to the DOM by adding a <style> tag
// load the styles
var content = __webpack_require__(72);
var content = __webpack_require__(71);
if(typeof content === 'string') content = [[module.i, content, '']];
if(content.locals) module.exports = content.locals;
// add the styles to the DOM
@ -47463,7 +47414,7 @@ if(false) {
}
/***/ }),
/* 72 */
/* 71 */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(2)(false);
@ -47471,13 +47422,13 @@ 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", ""]);
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\n\n\n", ""]);
// exports
/***/ }),
/* 73 */
/* 72 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
@ -47508,111 +47459,208 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
/* harmony default export */ __webpack_exports__["default"] = ({
data: function data() {
return {
title: 'TicTacToe',
showSuccess: false,
showFailure: false,
successMessage: '',
failMessage: '',
currentValue: 1,
gameEnded: false,
player1User: undefined,
player2User: undefined,
board: [0, 0, 0, 0, 0, 0, 0, 0, 0]
};
},
methods: {
pieceImageURL: function pieceImageURL(piece) {
var imgSrc = String(piece);
return 'img/' + imgSrc + '.png';
},
clickPiece: function clickPiece(index) {
if (this.board[index] || this.gameEnded) return;
this.board[index] = this.currentValue;
this.successMessage = this.currentPlayer + ' has Played';
this.showSuccess = true;
this.currentValue = this.currentValue == 1 ? 2 : 1;
this.checkGameEnded();
},
restartGame: function restartGame() {
console.log('restartGame');
this.board = [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.hasRow(1)) {
this.successMessage = this.playerName(1) + ' won the Game';
this.showSuccess = true;
this.gameEnded = true;
}
if (this.hasRow(2)) {
this.successMessage = this.playerName(2) + ' won the Game';
this.showSuccess = true;
this.gameEnded = true;
}
if (this.isBoardComplete()) {
this.successMessage = 'The Game ended in a Tie';
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;
},
// ----------------------------------------------------------------------------------------
// GAME LOGIC - END
// ----------------------------------------------------------------------------------------
playerName: function playerName(playerNumber) {
console.log(playerNumber);
console.log(this.player1User);
if (this.player1User != undefined && playerNumber == 1) {
return this.player1User.name;
}
if (this.player2User != undefined && playerNumber == 2) {
return this.player2User.name;
}
return 'Player ' + playerNumber;
}
},
computed: {
currentPlayer: function currentPlayer() {
console.log(this.currentValue);
console.log(this.playerName(this.currentValue));
return this.playerName(this.currentValue);
}
},
mounted: function mounted() {
if (this.$root.$data.player1) {
this.player1User = this.$root.$data.player1;
}
if (this.$root.$data.player2) {
this.player2User = this.$root.$data.player2;
}
}
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 (var i = 0; i < array.length; i++) {
this.boardImagens[i] = array[i];
}
this.populateMainBoard();
// console.log("created imagens " + this.boardImagens);
},
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;
}
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");
if (this.checkGameEnded()) {
this.successMessage = "Congratz, you won!";
this.gameEnded = true;
this.showSuccess = true;
}
} else {
// quer dizer que são diferentes
// volta-se a virar as cartas para imagem limpa
console.log("wait 2 seconds to play again!");
setTimeout(this.resetData, 2000); // non blocking operation!!
this.board[this.piece1] = "hidden";
this.board[this.piece2] = "hidden";
// console.log("piece1 = " + this.piece1);
// console.log("piece2 = " + this.piece2);
this.piece1 = null;
this.piece2 = null;
console.log("imagens diferentes");
}
this.numeroJogada = 0;
}
index = null;
},
resetData: function resetData() {
console.log("Wait 2 Seconds. Timeout fucntion()");
// this.board[this.piece1] = "hidden";
// this.board[this.piece2] = "hidden";
// this.piece1 = null;
// this.piece2 = null;
},
pieceImageURL: function pieceImageURL(piece) {
var imgSrc = String(piece);
//console.log(imgSrc);
return 'img/' + imgSrc + '.png';
},
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];
// 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
// ----------------------------------------------------------------------------------------
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;
}
}
});
/***/ }),
/* 74 */
/* 73 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
@ -47705,19 +47753,19 @@ if (false) {
}
/***/ }),
/* 75 */
/* 74 */
/***/ (function(module, exports, __webpack_require__) {
var disposed = false
function injectStyle (ssrContext) {
if (disposed) return
__webpack_require__(76)
__webpack_require__(75)
}
var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(78)
var __vue_script__ = __webpack_require__(77)
/* template */
var __vue_template__ = __webpack_require__(89)
var __vue_template__ = __webpack_require__(88)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -47756,13 +47804,13 @@ module.exports = Component.exports
/***/ }),
/* 76 */
/* 75 */
/***/ (function(module, exports, __webpack_require__) {
// style-loader: Adds some css to the DOM by adding a <style> tag
// load the styles
var content = __webpack_require__(77);
var content = __webpack_require__(76);
if(typeof content === 'string') content = [[module.i, content, '']];
if(content.locals) module.exports = content.locals;
// add the styles to the DOM
@ -47782,7 +47830,7 @@ if(false) {
}
/***/ }),
/* 77 */
/* 76 */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(2)(false);
@ -47796,14 +47844,14 @@ 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\
/***/ }),
/* 78 */
/* 77 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lobby_vue__ = __webpack_require__(79);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lobby_vue__ = __webpack_require__(78);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lobby_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__lobby_vue__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__game_tictactoe_vue__ = __webpack_require__(84);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__game_tictactoe_vue__ = __webpack_require__(83);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__game_tictactoe_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__game_tictactoe_vue__);
//
//
@ -47969,19 +48017,19 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
});
/***/ }),
/* 79 */
/* 78 */
/***/ (function(module, exports, __webpack_require__) {
var disposed = false
function injectStyle (ssrContext) {
if (disposed) return
__webpack_require__(80)
__webpack_require__(79)
}
var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(82)
var __vue_script__ = __webpack_require__(81)
/* template */
var __vue_template__ = __webpack_require__(83)
var __vue_template__ = __webpack_require__(82)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -48020,13 +48068,13 @@ module.exports = Component.exports
/***/ }),
/* 80 */
/* 79 */
/***/ (function(module, exports, __webpack_require__) {
// style-loader: Adds some css to the DOM by adding a <style> tag
// load the styles
var content = __webpack_require__(81);
var content = __webpack_require__(80);
if(typeof content === 'string') content = [[module.i, content, '']];
if(content.locals) module.exports = content.locals;
// add the styles to the DOM
@ -48046,7 +48094,7 @@ if(false) {
}
/***/ }),
/* 81 */
/* 80 */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(2)(false);
@ -48060,7 +48108,7 @@ 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\
/***/ }),
/* 82 */
/* 81 */
/***/ (function(module, exports) {
//
@ -48096,7 +48144,7 @@ module.exports = {
};
/***/ }),
/* 83 */
/* 82 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
@ -48112,8 +48160,6 @@ 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.playerName))]),
_vm._v(" "),
_c("td", [
_c(
"a",
@ -48160,19 +48206,19 @@ if (false) {
}
/***/ }),
/* 84 */
/* 83 */
/***/ (function(module, exports, __webpack_require__) {
var disposed = false
function injectStyle (ssrContext) {
if (disposed) return
__webpack_require__(85)
__webpack_require__(84)
}
var normalizeComponent = __webpack_require__(1)
/* script */
var __vue_script__ = __webpack_require__(87)
var __vue_script__ = __webpack_require__(86)
/* template */
var __vue_template__ = __webpack_require__(88)
var __vue_template__ = __webpack_require__(87)
/* template functional */
var __vue_template_functional__ = false
/* styles */
@ -48211,13 +48257,13 @@ module.exports = Component.exports
/***/ }),
/* 85 */
/* 84 */
/***/ (function(module, exports, __webpack_require__) {
// style-loader: Adds some css to the DOM by adding a <style> tag
// load the styles
var content = __webpack_require__(86);
var content = __webpack_require__(85);
if(typeof content === 'string') content = [[module.i, content, '']];
if(content.locals) module.exports = content.locals;
// add the styles to the DOM
@ -48237,7 +48283,7 @@ if(false) {
}
/***/ }),
/* 86 */
/* 85 */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(2)(false);
@ -48245,13 +48291,13 @@ exports = module.exports = __webpack_require__(2)(false);
// module
exports.push([module.i, "\n.gameseparator[data-v-d614d384]{\n border-style: solid;\n border-width: 2px 0 0 0;\n border-color: black;\n}\n", ""]);
exports.push([module.i, "\n.gameboard[data-v-d614d384]{\n border-style: solid;\n border-width: 2px 0 0 0;\n border-color: black;\n}\n", ""]);
// exports
/***/ }),
/* 87 */
/* 86 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
@ -48276,6 +48322,9 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
//
//
//
//
//
/* harmony default export */ __webpack_exports__["default"] = ({
props: ['game'],
@ -48341,6 +48390,9 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
}
},
methods: {
startGame: function startGame(game) {
this.$socket.emit('start_game', { gameID: game.gameID });
},
pieceImageURL: function pieceImageURL(pieceNumber) {
var imgSrc = String(pieceNumber);
return 'img/' + imgSrc + '.png';
@ -48348,29 +48400,24 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
closeGame: function closeGame() {
this.$parent.close(this.game);
},
clickPiece: function clickPiece(index) {
if (!this.game.gameEnded) {
if (this.game.playerTurn != this.ownPlayerNumber) {
alert("It's not your turn to play");
} else {
if (this.game.board[index] == 0) {
this.$parent.play(this.game, index);
}
}
clickPiece: function clickPiece(game, index) {
if (this.game.boardImages[index] == "hidden") {
this.$parent.play(this.game, index);
}
this.$socket.emit('play', { gameID: game.gameID, index: index });
}
}
});
/***/ }),
/* 88 */
/* 87 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("div", { staticClass: "gameseparator" }, [
return _c("div", { staticClass: "gameboard" }, [
_c("div", [
_c("h2", { staticClass: "text-center" }, [
_vm._v("Game " + _vm._s(_vm.game.gameID))
@ -48406,10 +48453,28 @@ var render = function() {
])
]),
_vm._v(" "),
_c("div", [
_c("p", [
_c(
"button",
{
staticClass: "btn btn-xs btn-success",
on: {
click: function($event) {
$event.preventDefault()
_vm.startGame(_vm.game)
}
}
},
[_vm._v("Start Game")]
)
])
]),
_vm._v(" "),
_c(
"div",
{ staticClass: "board" },
_vm._l(_vm.game.board, function(piece, index) {
_vm._l(_vm.game.boardImages, function(piece, index) {
return _c("div", [
_c("img", {
attrs: { src: _vm.pieceImageURL(piece) },
@ -48438,7 +48503,7 @@ if (false) {
}
/***/ }),
/* 89 */
/* 88 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
@ -48559,5 +48624,59 @@ if (false) {
}
}
/***/ }),
/* 89 */
/***/ (function(module, exports, __webpack_require__) {
var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("div", { staticClass: "container" }, [
_c("div", { staticClass: "row" }, [
_c("div", { staticClass: "col-md-8 col-md-offset-2" }, [
_c("h1", [_vm._v("Logout")]),
_vm._v(" "),
_c("p", [_c("em", [_vm._v(_vm._s(_vm.message))])]),
_vm._v(" "),
_c(
"div",
{ staticClass: "text-left" },
[
_c(
"button",
{
staticClass: "btn btn-primary",
on: {
click: function($event) {
_vm.logout()
}
}
},
[_vm._v("Logout")]
),
_vm._v(" "),
_c(
"router-link",
{ staticClass: "btn btn-default", attrs: { to: "/users" } },
[_vm._v("Cancel")]
)
],
1
)
])
])
])
}
var staticRenderFns = []
render._withStripped = true
module.exports = { render: render, staticRenderFns: staticRenderFns }
if (false) {
module.hot.accept()
if (module.hot.data) {
require("vue-hot-reload-api") .rerender("data-v-12a7f961", module.exports)
}
}
/***/ })
/******/ ]);

View File

@ -1,21 +1,24 @@
<template>
<div class="gameseparator">
<div class="gameboard">
<div>
<h2 class="text-center">Game {{ game.gameID }}</h2>
<br>
</div>
<div class="game-zone-content">
<div class="game-zone-content">
<div class="alert" :class="alerttype">
<strong>{{ message }} &nbsp;&nbsp;&nbsp;&nbsp;<a v-show="game.gameEnded" v-on:click.prevent="closeGame">Close Game</a></strong>
</div>
<div>
<p><button class="btn btn-xs btn-success" v-on:click.prevent="startGame(game)">Start Game</button></p>
</div>
<div class="board">
<div v-for="(piece, index) of game.board" >
<div v-for="(piece, index) of game.boardImages" >
<img v-bind:src="pieceImageURL(piece)" v-on:click="clickPiece(index)">
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</template>
<script type="text/javascript">
@ -32,7 +35,7 @@
return 1;
} else if (this.game.player2SocketID == this.$parent.socketId) {
return 2;
}
}
return 0;
},
ownPlayerName(){
@ -59,7 +62,7 @@
return "Game has ended. You Win.";
} else if (this.game.winner == 0) {
return "Game has ended. There was a tie.";
}
}
return "Game has ended and " + this.adversaryPlayerName + " has won. You lost.";
} else {
if (this.game.playerTurn == this.ownPlayerNumber) {
@ -78,18 +81,21 @@
return "alert-success";
} else if (this.game.winner == 0) {
return "alert-info";
}
}
return "alert-danger";
}
}
if (this.game.playerTurn == this.ownPlayerNumber) {
return "alert-success";
return "alert-success";
} else {
return "alert-info";
}
}
},
methods: {
startGame(game){
this.$socket.emit('start_game', {gameID: game.gameID});
},
pieceImageURL (pieceNumber) {
var imgSrc = String(pieceNumber);
return 'img/' + imgSrc + '.png';
@ -97,25 +103,21 @@
closeGame (){
this.$parent.close(this.game);
},
clickPiece(index){
if (!this.game.gameEnded) {
if (this.game.playerTurn != this.ownPlayerNumber) {
alert("It's not your turn to play");
} else {
if (this.game.board[index] == 0) {
this.$parent.play(this.game, index);
}
}
}
clickPiece(game, index){
if (this.game.boardImages[index] == "hidden") {
this.$parent.play(this.game, index);
}
this.$socket.emit('play', {gameID: game.gameID, index: index});
}
}
}
</script>
<style scoped>
.gameseparator{
<style scoped>
.gameboard{
border-style: solid;
border-width: 2px 0 0 0;
border-color: black;
}
</style>
</style>

View File

@ -10,7 +10,7 @@
<tbody>
<tr v-for="game in games" :key="game.gameID">
<td>{{ game.gameID }}</td>
<td>{{ game.playerName }}</td>
<!-- <td>{{ data.currentPlayer }}</td> -->
<td>
<a class="btn btn-xs btn-primary" v-on:click.prevent="join(game)">Join</a>
</td>

View File

@ -1,4 +1,4 @@
<template v-if="localStorage.getItem('token') == null">
<template v-if=" JSON.parse(localStorage.getItem('token')) == null">
<form @submit.prevent="login(user)">
<div class="text-left">
@ -44,13 +44,16 @@ export default {
headers: {'Content-Type' : 'application/json'}
}).then(response => {
// buscar o token do user logado
console.log('Response: ' + response);
console.log('Response: ');
console.log(response);
let token = response.data.access_token;
// guardar na localStorage o token
localStorage.setItem('token', token);
localStorage.setItem('token', JSON.stringify(token));
// user já se encontra logado e com a sessão guardada
this.$router.push('/');
app.$forceUpdate();
console.log("after update view");
}).catch(loginError => {
// Something went wrong!
console.log('Login Error: ' + loginError);

View File

@ -1,4 +1,4 @@
<template>
<template v-if="JSON.parse(localStorage.getItem('token')) != null">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
@ -31,7 +31,7 @@ export default {
let head = {
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('token'),
'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('token')),
'Accept': 'application/json',
},
};
@ -39,8 +39,8 @@ export default {
axios.post('/api/logout', null, head)
.then(response => {
if(response.status == 200){
window.localStorage.removeItem('token');
console.log("Token removed");
window.localStorage.clear();
console.log("logout sucessfull");
this.$router.push('/login');
}
}).catch(error => {

View File

@ -1,3 +1,4 @@
php
<template>
<form @submit.prevent="register(user)">
@ -55,6 +56,7 @@ export default {
name : this.user.name,
username : this.user.email
}).then(response => {
// enviar email de autenticação
console.log(response);
this.$router.push('/');
}).catch(registerError => {

View File

@ -7,10 +7,10 @@
<br>
</div>
<div class="game-zone-content">
<div class="alert alert-success" v-if="showSuccess">
<button type="button" class="close-btn" v-on:click="showSuccess=false">&times;</button>
<strong>{{ successMessage }} &nbsp;&nbsp;&nbsp;&nbsp;<a v-show="gameEnded" v-on:click.prevent="restartGame">Restart</a></strong>
</div>
<div class="alert alert-success" v-if="showSuccess">
<button type="button" class="close-btn" v-on:click="showSuccess=false">&times;</button>
<strong>{{ successMessage }} &nbsp;&nbsp;&nbsp;&nbsp;<a v-show="gameEnded" v-on:click.prevent="restartGame">Restart</a></strong>
</div>
<div class="board">
<div v-for="(piece, key) of board" >
@ -26,7 +26,7 @@
export default {
data: function(){
return {
title: 'TicTacToe',
title: 'Memory Game',
showSuccess: false,
showFailure: false,
successMessage: '',
@ -34,32 +34,148 @@
currentValue: 1,
gameEnded:false,
player1User: undefined,
player2User: undefined,
board: [0,0,0,0,0,0,0,0,0]
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() {
// 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);
},
methods: {
pieceImageURL: function (piece) {
populateMainBoard: function() {
for (var i = 0; i < this.board.length; i++) {
this.board[i] = "hidden";
}
},
clickPiece: function(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!";
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");
if (this.checkGameEnded()) {
this.successMessage = "Congratz, you won!";
this.gameEnded = true;
this.showSuccess = true;
}
} else { // quer dizer que são diferentes
// volta-se a virar as cartas para imagem limpa
console.log("wait 2 seconds to play again!");
setTimeout(this.resetData, 2000); // non blocking operation!!
this.board[this.piece1] = "hidden";
this.board[this.piece2] = "hidden";
// console.log("piece1 = " + this.piece1);
// console.log("piece2 = " + this.piece2);
this.piece1 = null;
this.piece2 = null;
console.log("imagens diferentes");
}
this.numeroJogada = 0;
}
index = null;
},
resetData: function() {
console.log("Wait 2 Seconds. Timeout fucntion()");
// this.board[this.piece1] = "hidden";
// this.board[this.piece2] = "hidden";
// this.piece1 = null;
// this.piece2 = null;
},
pieceImageURL: function (piece) {
var imgSrc = String(piece);
//console.log(imgSrc);
return 'img/' + imgSrc + '.png';
},
clickPiece: function(index) {
if(this.board[index] || this.gameEnded) return;
this.board[index] = this.currentValue;
this.successMessage = this.currentPlayer+' has Played';
this.showSuccess = true;
this.currentValue = (this.currentValue == 1)? 2 : 1;
this.checkGameEnded();
},
restartGame:function(){
console.log('restartGame');
this.board= [0,0,0,0,0,0,0,0,0];
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]
// 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
@ -75,39 +191,23 @@
((this.board[2]==value) && (this.board[4]==value) && (this.board[6]==value));
},
checkGameEnded: function(){
if (this.hasRow(1)) {
this.successMessage = this.playerName(1) + ' won the Game';
this.showSuccess = true;
this.gameEnded = true;
}
if (this.hasRow(2)) {
this.successMessage = this.playerName(2) + ' won the Game';
this.showSuccess = true;
this.gameEnded = true;
}
if (this.isBoardComplete()) {
this.successMessage = 'The Game ended in a Tie';
this.successMessage = this.playerName(1) + ', you win!';
this.showSuccess = true;
this.gameEnded = true;
}
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;
},
// ----------------------------------------------------------------------------------------
// GAME LOGIC - END
// ----------------------------------------------------------------------------------------
playerName: function(playerNumber){
console.log(playerNumber);
console.log(this.player1User);
playerName: function(playerNumber){
if(this.player1User != undefined && playerNumber == 1){
return this.player1User.name;
}
@ -116,11 +216,13 @@
}
return 'Player '+playerNumber;
}
},
computed:{
currentPlayer: function(){
console.log(this.currentValue);
console.log(this.playerName(this.currentValue));
},
// ----------------------------------------------------------------------------------------
// GAME LOGIC - END
// ----------------------------------------------------------------------------------------
computed:{
currentPlayer: function(){
return this.playerName(this.currentValue);
}
},
@ -128,9 +230,6 @@
if(this.$root.$data.player1){
this.player1User = this.$root.$data.player1;
}
if(this.$root.$data.player2 ){
this.player2User = this.$root.$data.player2;
}
}
}
</script>

View File

@ -21,7 +21,7 @@
border-style: solid;
border-width: 0px 0 0 0px;
border-color: black;
div{
display: inline-block;
border-style: solid;
@ -39,6 +39,3 @@
border-style: none;
}
}

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1> <a>Confirm you email right here <a></h1>
</body>
</html>

View File

@ -4,12 +4,13 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
@yield('metatags')
<title>@yield('title')</title>
@yield('extrastyles')
<!-- Latest compiled and minified CSS & JS -->
<link rel="stylesheet" href="{{ URL::asset('css/app.css') }}">
<link rel="stylesheet" href="{{ URL::asset('css/style.css') }}">
</head>
<body>

View File

@ -4,13 +4,12 @@
@section('content')
<router-link to="/users">Users</router-link> -
@if(!Auth::user())
{{-- @if(!Auth::user())--}}
<router-link to="/login">Login</router-link> -
<router-link to="/register">Register</router-link> -
@else
{{-- @else--}}
<router-link to="/logout">Logout</router-link> -
@endif
{{-- @endif--}}
<router-link to="/singletictactoe">SinglePlayer TicTacToe</router-link> -
<router-link to="/multitictactoe">Multiplayer TicTacToe</router-link>

View File

@ -10,8 +10,8 @@ class MemoryGame {
this.gameOwner= gameOwnerSocket;
this.playerTurn = 1;
this.winner = 0;
this.boardImages;
this.boardHidden;
this.boardImages = [];
this.boardHidden = [];
this.numPlayers = 0;
this.players = [];
this.playerScore = [];
@ -23,65 +23,34 @@ class MemoryGame {
this.array = [];
}
startGame(){
switch(this.numPlayers) {
case 1:
case 2:
this.line = 4;
this.column = 4;
this.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;
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];
populateMainBoard();
populateInvisibleBoard();
break;
case 4:
this.line = 6;
this.column = 6;
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,
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++ ) {
for ( let i = 0; i < this.playerScore.lenght; i++ ) {
this.playerScore[i] = 0;
}
}
populateMainBoard() {
for(var i = 0; i < this.line*this.column; i++) {
let max = this.line*this.column;
for(let i = 0; i < max; i++) {
this.boardImages[i] = "hidden";
}
}
populateInvisibleBoard() {
shuffleArray();
console.log(array);
this.shuffleArray();
//console.log(this.array);
for (var i = 0; i < array.length; i++) {
this.boardImages[i] = this.array[i];
for (let i = 0; i < this.array.length; i++) {
this.boardHidden[i] = this.array[i];
}
console.log(this.boardHidden);
}
join(socketId){ // chamar pelo socket id do user
for(var i = 0; i < this.players.lenght; i++){
for(let i = 0; i < this.players.lenght; i++){
if (this.players[i] == socketId) { // se já estiver no jogo, então não conta
return;
}
@ -94,14 +63,7 @@ class MemoryGame {
checkGameEnded(){
//1 Board complete ??
if (this.isBoardComplete()) {
//
// for(let i=0; i<this.numPlayers; i++){
// this.playerScore[i] = 0; //inicializa a pontuaçao do player a 0
// this.calculateScore(i); //calcula o score do player
// }
if (this.isBoardComplete() && this.gameEnded) {
// buscar o player com maior pontuação
for(let a = 0; a < this.players.lenght; a++) {
if (this.playerScore[a] > this.pontuacao) {
@ -110,32 +72,23 @@ class MemoryGame {
}
}
// mostrá-lo
console.log('player' + this.players[this.winner]);
console.log('position ' + this.winner);
console.log('pontuacao: ' + this.pontuacao);
this.winnerMessage = this.players[this.winner] + ' won the game with ' + this.pontuacao + ' pontos.';
console.log('winnerMessage: ' + this.winnerMessage);
this.gameEnded = true;
return true;
}
//ou se empataram
//se nao estiver complete return false
return false;
}
isBoardComplete(){
for(var i=0; i<this.boardImages.lenght; i++){
if (this.boardImages[i] == "hidden") { //se houver alguma img hidden entao a board nao esta completa logo nao acabou o Jogo
return false;
}
}
for(let i=0; i<this.boardImages.lenght; i++){
if (this.boardImages[i] == "hidden") { //se houver alguma img hidden entao a board nao esta completa logo nao acabou o Jogo
return false;
}
}
return true;
}
@ -149,34 +102,42 @@ class MemoryGame {
//jogo ainda nao acabou
if(this.gameEnded) {
return false;
}
//Estado da quadricula ? hidden ? Jogada valida
if (this.boardImages[index] == "hidden") {
if (this.boardImages[index] != "hidden") {
return false;
}
//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 ++
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.piece1 = index;
console.log(this.piece1);
this.boardImages[index] = this.boardHidden[index];
isPair(playerNumber);
this.playerTurn = 1;
console.log(this.boardImages[this.piece1]);
this.playerTurn++;
} else {
// se playerTurn = 2 vira se a 2ª carta
console.log("2ª play");
this.piece2 = index;
console.log(this.piece2);
this.boardImages[index] = this.boardHidden[index];
console.log(this.boardImages[this.piece2]);
this.isPair(playerNumber);
this.playerTurn = 1;
this.checkGameEnded();
}
return true;
}
isPair(playerNumber) {
if (this.boardImages[this.piece1] === this.boardImages[this.piece2]) {
if (this.boardHidden[this.piece1] === this.boardHidden[this.piece2]) {
console.log("You found a pair!");
// pontuação ++
this.playerScore[playerNumber]++;
@ -188,7 +149,7 @@ class MemoryGame {
this.boardImages[this.piece1] = "hidden";
this.boardImages[this.piece2] = "hidden";;
nextTurn(playerNumber);
this.nextTurn(playerNumber);
}
}
@ -204,7 +165,7 @@ class MemoryGame {
var j = 0;
var temp = null;
for (i = this.array.length - 1; i > 0; i--) {
for (let 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];
@ -214,6 +175,40 @@ class MemoryGame {
}
startGame(){
switch(this.numPlayers) {
case 1:
case 2:
this.line = 4;
this.column = 4;
this.gameStarted = true;
this.array = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7];
this.populateMainBoard();
this.populateInvisibleBoard();
break;
case 3:
this.line = 4;
this.column = 6;
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.populateMainBoard();
this.populateInvisibleBoard();
break;
case 4:
this.line = 6;
this.column = 6;
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,
12,12,13,13,14,14,15,15,16,16,17,17];
this.populateMainBoard();
this.populateInvisibleBoard();
break;
}
this.zerarPontuacoes();
this.winner = 0;
this.gameEnded = false;
}
}
module.exports = MemoryGame;

View File

@ -36,7 +36,7 @@ io.on('connection', function (socket) {
console.log('client has connected');
socket.on('create_game', function (data){
let game = games.createGame(data.playerName, socket.id);
let game = games.createGame(socket.id);
socket.join(game.gameID);
console.log('game was created');
// Notifications to the client
@ -70,18 +70,20 @@ io.on('connection', function (socket) {
socket.emit('invalid_play', {'type': 'Invalid_Game', 'game': null});
return;
}
let playerSocket = socket.id;
/*if (playerTurn > game.players.length || playerTurn < 0) {
socket.emit('invalid_play', {'type': 'Invalid_Player', 'game': game});
return;
}*/
if (game.play( playerSocket, data.x, data.y)) {
io.to(game.gameID).emit('game_changed', game);
} else {
socket.emit('invalid_play', {'type': 'Invalid_Play', 'game': game});
return;
var playerNumber = 0;
/*
if(game.player1SocketID == socket.id){
playerNumber = 1;
}else if(game.player2SocketID == socket.id){
playerNumber = 2;
}
});
if(game.play(playerNumber, data.index)){
io.to(game.gameID).emit('game_change', game);
}
*/
});
socket.on('get_game', function (data){
let game = games.gameByID(data.gameID);