1
0
Fork 0
spacetac/src/core/Player.spec.ts

42 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-11-21 22:14:27 +00:00
import { testing } from "../common/Testing";
import { Player } from "./Player";
import { StarLocationType } from "./StarLocation";
import { Universe } from "./Universe";
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
testing("Player", test => {
test.case("keeps track of visited locations", check => {
let player = new Player();
let universe = new Universe();
let star1 = universe.addStar();
let star2 = universe.addStar();
let loc1a = star1.addLocation(StarLocationType.PLANET);
let loc1b = star1.addLocation(StarLocationType.PLANET);
let loc2a = star2.addLocation(StarLocationType.PLANET);
let loc2b = star2.addLocation(StarLocationType.PLANET);
universe.updateLocations();
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
function checkVisited(s1 = false, s2 = false, v1a = false, v1b = false, v2a = false, v2b = false) {
check.same(player.hasVisitedSystem(star1), s1);
check.same(player.hasVisitedSystem(star2), s2);
check.same(player.hasVisitedLocation(loc1a), v1a);
check.same(player.hasVisitedLocation(loc1b), v1b);
check.same(player.hasVisitedLocation(loc2a), v2a);
check.same(player.hasVisitedLocation(loc2b), v2b);
}
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
checkVisited();
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
player.fleet.setLocation(loc1b);
checkVisited(true, false, false, true, false, false);
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
player.fleet.setLocation(loc1a);
checkVisited(true, false, true, true, false, false);
2017-01-29 18:34:38 +00:00
2019-11-21 22:14:27 +00:00
player.fleet.setLocation(loc2a);
checkVisited(true, true, true, true, true, false);
player.fleet.setLocation(loc2a);
checkVisited(true, true, true, true, true, false);
});
});