mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 20:51:23 +00:00
Implemented picking turn method
This commit is contained in:
parent
82ed2a461e
commit
2f07de1d1c
2 changed files with 70 additions and 1 deletions
|
@ -171,7 +171,31 @@ Gather.prototype.modifyGatherer = (user, callback) => {
|
|||
return this.gatherers
|
||||
.filter(gatherer => gatherer.id === user.id)
|
||||
.forEach(callback);
|
||||
}
|
||||
};
|
||||
|
||||
// Determines picking order of teams
|
||||
// Marine 1 pick first
|
||||
// 2 picks for each team subsequently
|
||||
|
||||
Gather.prototype.pickingTurn = () => {
|
||||
if (this.current !== 'selection') return null;
|
||||
let alienCount = this.aliens().length;
|
||||
let marineCount = this.marines().length;
|
||||
let total = marineCount + alienCount;
|
||||
if (alienCount + marineCount === 2) return "marine";
|
||||
if (marineCount > alienCount) return "alien";
|
||||
if (marineCount < alienCount) return "marine";
|
||||
switch (total) {
|
||||
case 4:
|
||||
return "alien";
|
||||
case 6:
|
||||
return "marine";
|
||||
case 8:
|
||||
return "alien";
|
||||
case 10:
|
||||
return "marine";
|
||||
}
|
||||
};
|
||||
|
||||
Gather.prototype.moveToMarine = user => {
|
||||
if (this.marines().length >= this.TEAM_SIZE) return;
|
||||
|
|
|
@ -217,6 +217,51 @@ describe("Gather Model:", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("pickingTurn", function () {
|
||||
var marineLeader, alienLeader;
|
||||
beforeEach(function () {
|
||||
gatherers.forEach(function (gatherer, index) {
|
||||
gather.addGatherer(gatherer);
|
||||
});
|
||||
gatherers.forEach(function (gatherer, index) {
|
||||
let candidate = gather.gatherers[index % 2];
|
||||
gather.selectLeader(gatherer, candidate);
|
||||
});
|
||||
marineLeader = gather.marineLeader();
|
||||
alienLeader = gather.alienLeader();
|
||||
assert.isNotNull(marineLeader);
|
||||
assert.isNotNull(alienLeader);
|
||||
assert.equal(gather.current, "selection");
|
||||
});
|
||||
it ("returns null if current state is not selection", function () {
|
||||
gather = Gather();
|
||||
assert.isNull(gather.pickingTurn());
|
||||
});
|
||||
it ("gives first pick to aliens, then 2 for each side after", function () {
|
||||
var gathererCursor = 2; // Picking i=2 gatherer next
|
||||
var assertMarineNextMove = function () {
|
||||
assert.equal(gather.pickingTurn(), "marine");
|
||||
gather.moveToMarine(gather.gatherers[gathererCursor], marineLeader);
|
||||
gathererCursor++;
|
||||
};
|
||||
var assertAlienNextMove = function () {
|
||||
assert.equal(gather.pickingTurn(), "alien");
|
||||
gather.moveToAlien(gather.gatherers[gathererCursor], alienLeader);
|
||||
gathererCursor++;
|
||||
};
|
||||
assertMarineNextMove();
|
||||
assertAlienNextMove();
|
||||
assertAlienNextMove();
|
||||
assertMarineNextMove();
|
||||
assertMarineNextMove();
|
||||
assertAlienNextMove();
|
||||
assertAlienNextMove();
|
||||
assertMarineNextMove();
|
||||
assertMarineNextMove();
|
||||
assertAlienNextMove();
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveToLobby", function () {
|
||||
it ("moves a player to lobby", function () {
|
||||
gather.addUser(user);
|
||||
|
|
Loading…
Reference in a new issue