Generate one warp location for each link to other star systems
This commit is contained in:
parent
f7eb13abe1
commit
83d4b0f97f
|
@ -50,10 +50,10 @@ module SpaceTac.Game {
|
|||
result.push(new StarLocation(this, StarLocationType.STAR, 0, 0));
|
||||
|
||||
// Add warp locations around the star
|
||||
var warps = 3;
|
||||
while (warps--) {
|
||||
var links = this.getLinks();
|
||||
links.forEach((link: StarLink) => {
|
||||
result.push(this.generateOneLocation(StarLocationType.WARP, result, this.radius * 0.3, random));
|
||||
}
|
||||
});
|
||||
|
||||
// Add random locations
|
||||
while (count--) {
|
||||
|
@ -63,6 +63,19 @@ module SpaceTac.Game {
|
|||
return result;
|
||||
}
|
||||
|
||||
// Get the number of links to other stars
|
||||
getLinks(): StarLink[] {
|
||||
var result: StarLink[] = [];
|
||||
|
||||
this.universe.starlinks.forEach((link: StarLink) => {
|
||||
if (link.first === this || link.second === this) {
|
||||
result.push(link);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private generateOneLocation(type: StarLocationType, others: StarLocation[], radius: number, random: RandomGenerator): StarLocation {
|
||||
var x = (random.throw(2) - 1) * radius;
|
||||
var y = (random.throw(2) - 1) * radius;
|
||||
|
|
|
@ -24,6 +24,7 @@ module SpaceTac.Game {
|
|||
super();
|
||||
|
||||
this.stars = [];
|
||||
this.starlinks = [];
|
||||
this.radius = 50;
|
||||
}
|
||||
|
||||
|
@ -157,5 +158,12 @@ module SpaceTac.Game {
|
|||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Add a link between two stars
|
||||
addLink(first: Star, second: Star): void {
|
||||
if (!this.areLinked(first, second)) {
|
||||
this.starlinks.push(new StarLink(first, second));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/app/game/specs/Star.spec.ts
Normal file
22
src/app/game/specs/Star.spec.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||
|
||||
module SpaceTac.Game.Specs {
|
||||
"use strict";
|
||||
|
||||
describe("Star", () => {
|
||||
it("lists links to other stars", () => {
|
||||
var universe = new Universe();
|
||||
universe.stars.push(new Star(universe, 0, 0));
|
||||
universe.stars.push(new Star(universe, 1, 0));
|
||||
universe.stars.push(new Star(universe, 0, 1));
|
||||
universe.stars.push(new Star(universe, 1, 1));
|
||||
universe.addLink(universe.stars[0], universe.stars[1]);
|
||||
universe.addLink(universe.stars[0], universe.stars[3]);
|
||||
|
||||
var result = universe.stars[0].getLinks();
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0]).toEqual(new StarLink(universe.stars[0], universe.stars[1]));
|
||||
expect(result[1]).toEqual(new StarLink(universe.stars[0], universe.stars[3]));
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue