Added star system names
This commit is contained in:
parent
83d4b0f97f
commit
b76a83c157
29
src/app/game/NameGenerator.ts
Normal file
29
src/app/game/NameGenerator.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
module SpaceTac.Game {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// A unique name generator
|
||||||
|
export class NameGenerator {
|
||||||
|
// List of available choices
|
||||||
|
private choices: string[];
|
||||||
|
|
||||||
|
// Random generator to use
|
||||||
|
private random: RandomGenerator;
|
||||||
|
|
||||||
|
constructor(choices: string[], random: RandomGenerator = new RandomGenerator()) {
|
||||||
|
this.choices = choices.slice(0);
|
||||||
|
this.random = random;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a new unique name from available choices
|
||||||
|
getName(): string {
|
||||||
|
if (this.choices.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = this.random.throwInt(0, this.choices.length - 1);
|
||||||
|
var result = this.choices[index];
|
||||||
|
this.choices.splice(index, 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,67 @@ module SpaceTac.Game {
|
||||||
|
|
||||||
// A star system
|
// A star system
|
||||||
export class Star extends Serializable {
|
export class Star extends Serializable {
|
||||||
|
|
||||||
|
// Available names for star systems
|
||||||
|
static NAMES_POOL = [
|
||||||
|
"Alpha Prime",
|
||||||
|
"Bright Skies",
|
||||||
|
"Costan Sector",
|
||||||
|
"Duncan's Legacy",
|
||||||
|
"Ethiopea",
|
||||||
|
"Fringe Space",
|
||||||
|
"Gesurd Deep",
|
||||||
|
"Helios",
|
||||||
|
"Justice Enclave",
|
||||||
|
"Kovak Second",
|
||||||
|
"Lumen Circle",
|
||||||
|
"Manoa Society",
|
||||||
|
"Neptune's Record",
|
||||||
|
"Ominous Murmur",
|
||||||
|
"Pirate's Landing",
|
||||||
|
"Quasuc Effect",
|
||||||
|
"Roaring Thunder",
|
||||||
|
"Safe Passage",
|
||||||
|
"Time Holes",
|
||||||
|
"Unknown Territory",
|
||||||
|
"Vulcan Terror",
|
||||||
|
"Wings Aurora",
|
||||||
|
"Xenos Trading",
|
||||||
|
"Yu's Pride",
|
||||||
|
"Zoki's Hammer",
|
||||||
|
"Astral Tempest",
|
||||||
|
"Burned Star",
|
||||||
|
"Crystal Bride",
|
||||||
|
"Death Star",
|
||||||
|
"Ether Bending",
|
||||||
|
"Forgotten Realm",
|
||||||
|
"Galactic Ring",
|
||||||
|
"Hegemonia",
|
||||||
|
"Jorgon Trails",
|
||||||
|
"Kemini System",
|
||||||
|
"Light Rain",
|
||||||
|
"Moons Astride",
|
||||||
|
"Nubia's Sisters",
|
||||||
|
"Opium Hide",
|
||||||
|
"Paradise Quest",
|
||||||
|
"Quarter Horizon",
|
||||||
|
"Rising Dust",
|
||||||
|
"Silence of Forge",
|
||||||
|
"Titan Feet",
|
||||||
|
"Unicorn Fly",
|
||||||
|
"Violated Sanctuary",
|
||||||
|
"World's Repose",
|
||||||
|
"Xanthia's Travel",
|
||||||
|
"Yggdrasil",
|
||||||
|
"Zone of Ending",
|
||||||
|
];
|
||||||
|
|
||||||
// Parent universe
|
// Parent universe
|
||||||
universe: Universe;
|
universe: Universe;
|
||||||
|
|
||||||
|
// Name of the system (unique in the universe)
|
||||||
|
name: string;
|
||||||
|
|
||||||
// Location in the universe
|
// Location in the universe
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
|
|
@ -71,6 +71,8 @@ module SpaceTac.Game {
|
||||||
generateStars(count: number, random: RandomGenerator = new RandomGenerator()): Star[] {
|
generateStars(count: number, random: RandomGenerator = new RandomGenerator()): Star[] {
|
||||||
var result: Star[] = [];
|
var result: Star[] = [];
|
||||||
|
|
||||||
|
var names = new NameGenerator(Star.NAMES_POOL);
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
var x = random.throw() * this.radius * 2.0 - this.radius;
|
var x = random.throw() * this.radius * 2.0 - this.radius;
|
||||||
var y = random.throw() * this.radius * 2.0 - this.radius;
|
var y = random.throw() * this.radius * 2.0 - this.radius;
|
||||||
|
@ -81,6 +83,7 @@ module SpaceTac.Game {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
star.name = names.getName();
|
||||||
result.push(star);
|
result.push(star);
|
||||||
|
|
||||||
count--;
|
count--;
|
||||||
|
|
17
src/app/game/specs/NameGenerator.spec.ts
Normal file
17
src/app/game/specs/NameGenerator.spec.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||||
|
|
||||||
|
module SpaceTac.Game.Specs {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("NameGenerator", () => {
|
||||||
|
it("generates unique names", () => {
|
||||||
|
var random = new RandomGenerator(0.48, 0.9, 0.1);
|
||||||
|
var gen = new NameGenerator(["a", "b", "c"], random);
|
||||||
|
|
||||||
|
expect(gen.getName()).toEqual("b");
|
||||||
|
expect(gen.getName()).toEqual("c");
|
||||||
|
expect(gen.getName()).toEqual("a");
|
||||||
|
expect(gen.getName()).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -71,6 +71,12 @@ module SpaceTac.View {
|
||||||
sprite.input.useHandCursor = true;
|
sprite.input.useHandCursor = true;
|
||||||
|
|
||||||
this.stars.addChild(sprite);
|
this.stars.addChild(sprite);
|
||||||
|
|
||||||
|
var name = new Phaser.Text(this.game, star.x, star.y, star.name,
|
||||||
|
{align: "center", font: "bold 14px Arial", fill: "#90FEE3"});
|
||||||
|
name.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
||||||
|
name.anchor.set(0.5, -0.4);
|
||||||
|
this.stars.addChild(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue