Skip to content

Commit 4992051

Browse files
committed
Capitilised const names. Made a field const.
1 parent 0271803 commit 4992051

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

arena.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let _worms_lastLength;
1313
let _participantPromises;
1414
class Direction{
1515
constructor(name){
16-
Object.defineProperty(this, 'name', {
16+
Object.defineProperty(this, 'NAME', {
1717
value: name,
1818
writable: false,
1919
enumerable: true,
@@ -26,7 +26,7 @@ const Directions = {'FORWARD': new Direction('Forward'), 'BACKWARD': new Directi
2626
Object.freeze(Directions);
2727
class Placeable{
2828
constructor(space=null, team=null){
29-
Object.defineProperty(this, 'team', {
29+
Object.defineProperty(this, 'TEAM', {
3030
value: team,
3131
writable: false,
3232
enumerable: true,
@@ -56,9 +56,12 @@ class Controllable extends Placeable{
5656
if(this.constructor.name === 'SolidWorm'){
5757
BODY.push(this);
5858
}
59-
this.getPlace = () => {
60-
return BODY.indexOf(this);
61-
}
59+
Object.defineProperty(this, 'BODY_INDEX', {
60+
value: BODY.indexOf(this),
61+
writable: false,
62+
enumerable: true,
63+
configurable: true
64+
});
6265
this.getLength = () => {
6366
return BODY.length;
6467
}
@@ -102,7 +105,7 @@ class SolidWorm extends Controllable{
102105
}
103106
}
104107
this.getParticipant = ()=>{
105-
return _participants.get(this.team, 0);
108+
return _participants.get(this.TEAM, 0);
106109
}
107110
this.kill = ()=>{
108111
_worms.splice(this.getWormIndex(), 1);
@@ -134,7 +137,7 @@ class SolidWorm extends Controllable{
134137
}
135138
class TrailingBody extends Controllable{
136139
constructor(body){
137-
super(body, body[0].team);
140+
super(body, body[0].TEAM);
138141
this.getHead = ()=>body[0];
139142
}
140143
}
@@ -160,7 +163,7 @@ class Space{
160163
constructor(x, y, z){
161164
const CHALLENGERS = new Array();
162165
const GRAVE = new Array();
163-
Object.defineProperty(this, 'pos', {
166+
Object.defineProperty(this, 'POS', {
164167
value: Object.freeze({x: x, y: y, z: z}),
165168
writable: false,
166169
enumerable: true,
@@ -183,7 +186,7 @@ class Space{
183186
if(CHALLENGERS.length === 1){
184187
CHALLENGERS.forEach(solidWorm => {
185188
if(_settings.rules.winner === 'MostPoints'){
186-
_participants.addScore(solidWorm.team, eatables);
189+
_participants.addScore(solidWorm.TEAM, eatables);
187190
}
188191
while(0 < eatables){
189192
eatables--;
@@ -193,7 +196,7 @@ class Space{
193196
}
194197
}
195198
this.executeChallenge = ()=>{
196-
let willBeUnoccupied = occupiedBy === null ? true : !(occupiedBy instanceof Wall) && occupiedBy.getLength()-1 === occupiedBy.getPlace();
199+
let willBeUnoccupied = occupiedBy === null ? true : !(occupiedBy instanceof Wall) && occupiedBy.getLength()-1 === occupiedBy.BODY_INDEX;
197200
CHALLENGERS.forEach(solidWorm => {
198201
if(willBeUnoccupied){
199202
solidWorm.move(this);
@@ -240,7 +243,7 @@ function getPos(solidWorm){
240243
}
241244
}
242245
}
243-
ArenaHelper.postAbort('', 'Position of SolidWorm:'+solidWorm.team+' not found.');
246+
ArenaHelper.postAbort('', 'Position of SolidWorm:'+solidWorm.TEAM+' not found.');
244247
}
245248
function getNextPos(pos, direction){
246249
pos = JSON.parse(JSON.stringify(pos));
@@ -292,7 +295,7 @@ function updateDirection(participant){
292295
}
293296
}
294297
function rotateDirection(solidWorm, direction){
295-
switch(solidWorm.team){
298+
switch(solidWorm.TEAM){
296299
case 1:
297300
switch(direction){
298301
case Directions.FORWARD: return Directions.BACKWARD;
@@ -367,8 +370,8 @@ function parseArena(){
367370
type: placeable.constructor.name
368371
};
369372
if(!(placeable instanceof Wall)){
370-
occupiedBy.team = placeable.team;
371-
occupiedBy.isLastTrailingBody = placeable.getLength()-1 === placeable.getPlace();
373+
occupiedBy.team = placeable.TEAM;
374+
occupiedBy.isLastTrailingBody = placeable.getLength()-1 === placeable.BODY_INDEX;
372375
}
373376
}
374377
row.push({
@@ -377,7 +380,7 @@ function parseArena(){
377380
grave: space.getGrave().map(placeable => {
378381
return {
379382
type: placeable.constructor.name,
380-
team: placeable.team
383+
team: placeable.TEAM
381384
}
382385
}
383386
)});
@@ -451,7 +454,7 @@ function tick(){
451454
default:
452455
case 'WallOuterArea':
453456
spaces.forEach(space => {
454-
if(space.pos.x === _shrinks || space.pos.x === _settings.arena.size-1-_shrinks || space.pos.y === _shrinks || space.pos.y === _settings.arena.size-1-_shrinks || _settings.arena.threeDimensions && (space.pos.z === _shrinks || space.pos.z === _arena.length-1-_shrinks)){
457+
if(space.POS.x === _shrinks || space.POS.x === _settings.arena.size-1-_shrinks || space.POS.y === _shrinks || space.POS.y === _settings.arena.size-1-_shrinks || _settings.arena.threeDimensions && (space.POS.z === _shrinks || space.POS.z === _arena.length-1-_shrinks)){
455458
wall(space);
456459
}
457460
});
@@ -510,7 +513,7 @@ function tick(){
510513
_worms.forEach(solidWorm => {
511514
let arenaClone = JSON.parse(JSON.stringify(parsedArena));
512515
let rotate;
513-
switch(solidWorm.team){
516+
switch(solidWorm.TEAM){
514517
case 0: rotate = 0; break;
515518
case 1: rotate = 2; break;
516519
case 2: rotate = 3; break;
@@ -569,7 +572,7 @@ function tick(){
569572
});
570573
if(_settings.rules.winner === 'LastWormStanding' && _worms_lastLength !== _worms.length){
571574
_worms.forEach(solidWorm => {
572-
_participants.addScore(solidWorm.team, 1);
575+
_participants.addScore(solidWorm.TEAM, 1);
573576
});
574577
}
575578
_worms_lastLength = _worms.length;

0 commit comments

Comments
 (0)