-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from AgenoDrei/development
Development [MultiLanguage, Minischach winCondition formalization; incorp. all in into Editor]
- Loading branch information
Showing
39 changed files
with
1,316 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```shell | ||
db.lvls.find().toArray().forEach(function(doc){doc.description={"de":doc.description,"en":""};db.lvls.update({_id:doc._id},doc)}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const Promise = require('promise'); | ||
const shortid = require('shortid'); | ||
const gameTypes = require('../constants').gameType; | ||
const conStates = require('../constants').connectionState; | ||
const gameStates = require('../constants').gameState; | ||
const playerType = require('../constants').playerType; | ||
const helper = require('../helper'); | ||
const Board = require('./gameBoard/gameBoard'); | ||
const Chip = require('./gameBoard/chip'); | ||
//var ProgressModel = require('./progressModel'); | ||
const GameEnd = require('./gameEnds/gameEnd'); | ||
const ChipGameEnd = require('./gameEnds/chipGameEnd'); | ||
const FigureGameEnd = require('./gameEnds/figureGameEnd'); | ||
const LastRowGameEnd = require('./gameEnds/lastRowGameEnd'); | ||
const GameEndManager = require('./gameEnds/gameEndManager'); | ||
const History = require('./history'); | ||
|
||
|
||
class Game { | ||
constructor(type, mode, local, level, name) { | ||
this.name = name; | ||
this.toBeNext = playerType.PLAYERONE; | ||
this.type = type; | ||
this.mode = mode; | ||
this.local = (local == 'true'); | ||
this.level = level; | ||
this.id = shortid.generate(); | ||
this.player1 = { | ||
connection: null, | ||
state: conStates.EMPTY, | ||
joinId: shortid.generate() | ||
}; | ||
this.player2 = { | ||
connection: null, | ||
state: conStates.EMPTY, | ||
joinId: shortid.generate() | ||
}; | ||
this.board = new Board(this); | ||
this.board.loadLevel(this.level); | ||
this.win = new GameEndManager(); | ||
|
||
this.history = new History(this.board); | ||
console.log('New Game created with ID ' + this.id + ' and name ' + this.name + ', using level ' + this.level._id); | ||
} | ||
|
||
getId() { | ||
return this.id; | ||
} | ||
|
||
/* | ||
* Overwrite | ||
*/ | ||
turn(origX, origY, destX, destY, player) { | ||
} | ||
|
||
undo() { | ||
return this.history.undo(); | ||
} | ||
|
||
connect(joinId, connection) { | ||
var player1 = this.player1; | ||
var player2 = this.player2; | ||
return new Promise(function(fulfill, reject) { | ||
if (joinId == player1.joinId && player1.state == conStates.JOINED) { | ||
player1.connection = connection; | ||
player1.state = conStates.CONNECTED; | ||
fulfill(playerType.PLAYERONE); | ||
} else if (joinId == player2.joinId && player2.state == conStates.JOINED) { | ||
player2.connection = connection; | ||
player2.state = conStates.CONNECTED; | ||
fulfill(playerType.PLAYERTWO); | ||
} | ||
reject('Invalid joinId or already joined'); | ||
}); | ||
} | ||
|
||
sendToAll(message) { | ||
console.log("Server> ", message); | ||
try { | ||
this.player1.connection.sendUTF(JSON.stringify(message)); | ||
if(!this.local) this.player2.connection.sendUTF(JSON.stringify(message)); | ||
} catch(e) { | ||
console.log('Error on sending to all in game...'); | ||
} | ||
} | ||
|
||
endGame() { | ||
console.log("Server> Game finished"); | ||
this.sendToAll({type: "exit"}); | ||
} | ||
|
||
} | ||
|
||
module.exports = Game; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const GameEnd = require('./gameEnd'); | ||
const playerType = require('../../constants').playerType; | ||
const gameType = require('../../constants').gameType; | ||
const gameState = require('../../constants').gameState; | ||
const winCondition = require('../../constants').winCondition; | ||
|
||
class ChipGameEnd extends GameEnd { | ||
constructor(board) { | ||
super(board); | ||
} | ||
|
||
isWin() { | ||
if(this.chips[playerType.PLAYERTWO] == 0 && this.chips[playerType.BOTH] == 0 | ||
&& this.score[playerType.PLAYERONE] > this.score[playerType.PLAYERTWO]) { | ||
return gameState.WIN_PLAYER1; | ||
} else if(this.chips[playerType.PLAYERONE] == 0 && this.chips[playerType.BOTH] == 0 | ||
&& this.score[playerType.PLAYERONE] < this.score[playerType.PLAYERTWO]) { | ||
return gameState.WIN_PLAYER2; | ||
} else if(this.chips[playerType.PLAYERTWO] == 0 && this.chips[playerType.PLAYERONE] == 0 && this.chips[playerType.BOTH] == 0 | ||
&& this.score[playerType.PLAYERONE] == this.score[playerType.PLAYERTWO]) { | ||
return gameState.WIN_DRAW; | ||
} | ||
return gameState.VALID_TURN; | ||
} | ||
} | ||
|
||
module.exports = ChipGameEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const GameEnd = require('./gameEnd'); | ||
const playerType = require('../../constants').playerType; | ||
const gameType = require('../../constants').gameType; | ||
const gameState = require('../../constants').gameState; | ||
const winCondition = require('../../constants').winCondition; | ||
|
||
class FigureGameEnd extends GameEnd { | ||
constructor(board) { | ||
super(board); | ||
} | ||
|
||
isWin() { | ||
if(this.figures[playerType.PLAYERONE] == 0) | ||
return gameState.WIN_PLAYER2; | ||
else if(this.figures[playerType.PLAYERTWO] == 0) | ||
return gameState.WIN_PLAYER1; | ||
return gameState.VALID_TURN; | ||
} | ||
} | ||
|
||
module.exports = FigureGameEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const GameEnd = require('./gameEnd'); | ||
const playerType = require('../../constants').playerType; | ||
const gameType = require('../../constants').gameType; | ||
const gameState = require('../../constants').gameState; | ||
const winCondition = require('../../constants').winCondition; | ||
const figureType = require('../../constants').figureType; | ||
const Pawn = require('../gameBoard/pawn'); | ||
const helper = require('../../helper'); | ||
|
||
class FigureReachFieldGameEnd extends GameEnd { | ||
constructor(board, figure, field, player) { | ||
super(board); | ||
this.winFigure = figure; | ||
this.winField = field; | ||
this.winPlayer = player; | ||
} | ||
|
||
isWin() { | ||
let curFigure = this.board.getField(this.winField.x,this.winField.y).getFigure(); | ||
if(curFigure == null) | ||
return gameState.VALID_TURN; | ||
// console.log(curFigure.constructor.name); | ||
if(figureType[curFigure.constructor.name.toUpperCase()] == this.winFigure) { | ||
if(curFigure.player == this.winPlayer) | ||
return (this.winPlayer + 1); // +1 such that transition from constants.playerType to constants.gameState ! | ||
} | ||
return gameState.VALID_TURN; | ||
} | ||
} | ||
|
||
module.exports = FigureReachFieldGameEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var playerType = require('../../constants').playerType; | ||
const gameType = require('../../constants').gameType; | ||
const gameState = require('../../constants').gameState; | ||
const winCondition = require('../../constants').winCondition; | ||
const helper = require('../../helper'); | ||
|
||
class GameEnd { | ||
constructor(board) { | ||
this.board = board; | ||
this.chips = [this.board.chips[0], this.board.chips[1], this.board.chips[2]]; | ||
this.figures = this.board.figures; | ||
this.turnCount = 0; | ||
this.score = [0, 0]; | ||
console.log("WinCondition created!"); | ||
} | ||
|
||
isWin() { | ||
return gameState.VALID_TURN; | ||
} | ||
|
||
captureFigure(player, type) { | ||
this.figures[player]--; | ||
} | ||
|
||
captureChip(player, type) { | ||
var currentPlayer = null; | ||
if(player == playerType.PLAYERONE) { | ||
currentPlayer = playerType.PLAYERONE; | ||
} else if(player == playerType.PLAYERTWO) { | ||
currentPlayer = playerType.PLAYERTWO; | ||
} | ||
|
||
switch(type) { | ||
case playerType.PLAYERONE: //Yellow Chip | ||
this.chips[playerType.PLAYERONE]--; | ||
this.score[playerType.PLAYERTWO]++; | ||
break; | ||
case playerType.PLAYERTWO: //Blue Chip | ||
this.chips[playerType.PLAYERTWO]--; | ||
this.score[playerType.PLAYERONE]++; | ||
break; | ||
case playerType.BOTH: //Green Chip | ||
this.chips[playerType.BOTH]--; | ||
this.score[currentPlayer]++; | ||
break; | ||
} | ||
} | ||
|
||
countUpTurn() { | ||
this.turnCount++; | ||
} | ||
}; | ||
|
||
module.exports = GameEnd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const gameState = require('../../constants').gameState; | ||
const GameEnd = require('./gameEnd'); | ||
const ChipGameEnd = require('./chipGameEnd'); | ||
const FigureGameEnd = require('./figureGameEnd'); | ||
const LastRowGameEnd = require('./lastRowGameEnd'); | ||
|
||
|
||
class GameEndManager { | ||
constructor() { | ||
this.ends = []; | ||
} | ||
|
||
addGameEnd(end) { | ||
this.ends.push(end); | ||
} | ||
|
||
checkGameEnd() { | ||
for(let end of this.ends) { | ||
let win = end.isWin(); | ||
if(win != gameState.VALID_TURN) | ||
return win; | ||
} | ||
return gameState.VALID_TURN; | ||
} | ||
|
||
captureFigure(player, type) { | ||
if(this.ends.length > 0) | ||
this.ends[0].captureFigure(player, type); | ||
} | ||
|
||
captureChip(player, type) { | ||
if(this.ends.length > 0) | ||
this.ends[0].captureChip(player, type); | ||
} | ||
|
||
countUpTurn() { | ||
for(let end of this.ends) { | ||
end.countUpTurn(); | ||
} | ||
} | ||
|
||
}; | ||
|
||
module.exports = GameEndManager; |
Oops, something went wrong.