Skip to content

Commit

Permalink
Update board to handle new "squad" term.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanvugt committed Aug 26, 2020
1 parent 0b72ecb commit add05d0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/utils/engine-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function getReadableCauseOfDeath(death) {
return `Lost head-to-head with ${death.eliminatedBy}`;
case "wall-collision":
return "Moved out of bounds";
case "team-eliminated":
return "Team was eliminated";
case "squad-eliminated":
return "Squad was eliminated";
default:
return death.cause;
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/engine-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function singleSnakeData() {
return {
"http://localhost/games/123": gameResponse,
"ws://localhost/socket/123": framesResponse,
"images/snake/head/regular.svg": svgText,
"images/snake/tail/regular.svg": svgText
"images/snake/head/default.svg": svgText,
"images/snake/tail/default.svg": svgText
};
}

Expand All @@ -99,8 +99,8 @@ function multiSnakeData() {
URL: "http://localhost:5000",
Health: 1,
Body: [{ X: 3, Y: 3 }, { X: 3, Y: 4 }, { X: 3, Y: 5 }],
Head: "regular",
Tail: "regular"
Head: "default",
Tail: "default"
},
{
ID: "qwer",
Expand Down
14 changes: 7 additions & 7 deletions src/utils/game-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function formatSnake(snake) {
tail: snake.TailType && snake.TailType.toLowerCase(),
headSvg: snake.HeadSvg,
tailSvg: snake.TailSvg,
team: snake.Team
squad: snake.Squad
};
}

Expand Down Expand Up @@ -208,9 +208,9 @@ function oneLeft(snakes) {
return alive.length <= 1;
}

function getUniqueTeams(snakes) {
function getUniqueSquads(snakes) {
return snakes
.map(function (snake) { return snake.team; })
.map(function (snake) { return snake.squad; })
.filter(function (value) { return (typeof value !== "undefined" && value !== "") })
.filter(function (value, index, self) { return self.indexOf(value) === index })
.sort();
Expand All @@ -224,10 +224,10 @@ export function isLastFrameOfGame(frame) {
return true;
}

const remainingTeams = getUniqueTeams(aliveSnakes);
if (remainingTeams.length > 0) {
// Team Game, we're done if one team is left.
return remainingTeams.length === 1;
const remainingSquads = getUniqueSquads(aliveSnakes);
if (remainingSquads.length > 0) {
// Squad game, we're done if one squad is left.
return remainingSquads.length === 1;
}

if (snakes.length === 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/game-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ it("should not break on case sensitivity for head and tail types", () => {
Name: "snake 1",
URL: "http://snake1",
Health: 100,
HeadType: "rEgUlAr",
HeadType: "dEfaUlT",
TailType: "BOLT",
Color: "red",
Body: [{ X: 4, Y: 4 }, { X: 4, Y: 4 }, { X: 4, Y: 4 }]
Expand Down Expand Up @@ -195,7 +195,7 @@ it("should not break on case sensitivity for head and tail types", () => {
{ x: 4, y: 4, direction: "up", type: "tail", isOverlapped: true }
],
isDead: false,
head: "regular",
head: "default",
tail: "bolt",
headSvg: undefined,
tailSvg: undefined
Expand Down

0 comments on commit add05d0

Please sign in to comment.