@@ -5,22 +5,33 @@ Game = class Game {
this.players = [];
this.gameObjects = [];
this.currentPlayerIndex = 0;
this.board = new BoardController(10,10,21);
this.board = new BoardController();
this.gameState;
}

updateBoard() {
this.board.displayGame(this.gameObjects,this.players);
}


nextTurn() {

this.currentPlayer = this.players[this.currentPlayerIndex];
this.currentPlayer.endTurn();
this.currentplayerindex++;
this.players[this.currentPlayerIndex].startTurn();
this.currentPlayer = this.players[this.currentPlayerIndex];
this.currentPlayer.endTurn();
if(this.currentPlayerIndex == this.players.length -1){
this.currentPlayerIndex = 0;
}
else {
this.currentPlayerIndex++;
}
this.players[this.currentPlayerIndex].startTurn();
this.players[this.currentPlayerIndex].socket.emit('update-actionPoints',this.players[this.currentPlayerIndex].actionPoints);
}

addPlayer(player) {
this.playerCount = this.players.length;
this.players.push(player);
if(this.players.length == 0){
this.players[this.currentPlayerIndex].startTurn();
if(this.playerCount == 0){
player.startTurn();
}
console.log("Player " + player.id + " added to game.");
}
@@ -30,10 +41,22 @@ Game = class Game {
if (index > -1) this.players.splice(index, 1);
}

actionHandler(val) {
console.log(this.currentPlayerIndex)
this.currentPlayer = this.players[this.currentPlayerIndex];
this.currentPlayer.actionPoints+= val;
if (this.currentPlayer.actionPoints <= 0) {
this.nextTurn();
}
this.currentPlayer.socket.emit('update-actionPoints',this.currentPlayer.actionPoints);


}

startGame() {
gameState = True;
this.currentPlayer = this.players[this.currentPlayerIndex];
this.players[this.currentPlayerIndex].startTurn();
this.currentPlayer.startTurn();
}

endGame() {
@@ -12,7 +12,7 @@ GameObject = class GameObject {

getColor() {return this.color;}

setColor(r,g,b) {super.color = {r, g, b};}
setColor(r,g,b) {this.color = {r, g, b};}
}


@@ -1,11 +1,12 @@
var GameObject = require("./GameObject.js");


Player = class Player extends GameObject {
constructor (xPos,yPos,colorR,colorG,colorB, name) {
super(xPos,yPos,colorR,colorG,colorB);
super(xPos, yPos,colorR,colorG,colorB);
this.id;
this.name;
this.actionPoints;
this.actionPoints = 0;
this.inventory = [];
this.activeTurn;
this.socket;
@@ -19,6 +20,41 @@ Player = class Player extends GameObject {
this.socket = socket;
}

setRGBColor(color){
switch(color){
case 'Red':
this.setColor(255,0,0);
break;
case 'Green':
this.setColor(0,255,0);
break;
case 'Blue':
this.setColor(0,0,255);
break;
case 'Yellow':
this.setColor(255,255,0);
break;
case 'Orange':
this.setColor(255,165,0);
break;
case 'Pink':
this.setColor(255,192,203);
break;
case 'Gray':
this.setColor(128,128,128);
break;
case 'Brown':
this.setColor(165,42,42);
break;
case 'Purple':
this.setColor(128,0,128);
break;
default:
console.log('geen geldige kleur');
break;
}
}

setName(name) {
this.name = name;
}
@@ -27,29 +63,30 @@ Player = class Player extends GameObject {

endTurn() {
this.activeTurn = false;
this.socket.emit('message', 'kut');
this.socket.emit('endTurn');
}

startTurn() {
this.actionPoints += 10;
this.activeTurn = true;
this.socket.emit('message', this.activeTurn);
this.socket.emit('startTurn');

}

getActionPoints() {return this.actionPoints;}

setActionPoints(points) {this.actionPoints = points;}

move(direction){
let position = super.getPosition();
let position = this.getPosition();
switch (direction){
case 0: position.x++; break;
case 1: position.y++; break;
case 2: position.x--; break;
case 3: position.y--; break;
//default: console.log("No direction given with move. players name: " + this.name)
case 'right': position.x++; break;
case 'up': position.y++; break;
case 'left': position.x--; break;
case 'down': position.y--; break;
default: console.log("No direction given with move. players name: " + this.name)
}
super.setPosition(position.x, position.y);
this.setPosition(position.x, position.y);
//actionHandler();
}

@@ -1,11 +1,18 @@
module.exports.start = function (socket, player, game) {
socket.on("move", (direction) => {
player.move(direction);
game.updateBoard();
});
socket.on("endturn", () => {
game.nextTurn();
});
socket.on("currentstate", () => {
socket.emit("activeTurn",player.activeTurn());
});
socket.on("action", (val) => {
game.actionHandler(val);
});
socket.on("name", (name) => {
player.setName(name);
});
socket.on("color", (color) => {
player.setRGBColor(color);
});
};
@@ -8,7 +8,7 @@ var io = require('socket.io')(http);
var gameRoutes = require('./routes.js');
var gameController = require('./models/Game.js');
var PlayerController = require('./models/Player.js');
var boardController = require('./board/BoardController.js');
//var boardController = require('./board/BoardController.js');

app.use(express.static(path.join(__dirname, 'client')));

@@ -19,7 +19,7 @@ app.get('/', function (req, res) {
game = new Game();

io.on('connection', (socket) => {
let player = new Player();
let player = new Player(1,1,0,0,0);
player.setId(socket.id);
player.setSocket(socket);
game.addPlayer(player);