ShufflerDirection.ts 977 B

1234567891011121314151617181920212223242526272829
  1. /// <reference path="../Shuffler.ts" />
  2. /// <reference path="RoomRandomMap.ts" />
  3. class ShufflerDirection extends Shuffler<number> {
  4. private preferredGrowth : number;
  5. private directionsArray : Array<number>;
  6. public runner : number = 0;
  7. public constructor (array : Array<number>, preferredGrowth : number, rng? : () => number) {
  8. super(array, rng);
  9. this.preferredGrowth = preferredGrowth;
  10. let goodDirections = [];
  11. let badDirections = [];
  12. for (let direction = this.getOne(); direction != undefined; direction = this.getOne()) {
  13. if (RoomRandomMap.isDirectionPreferred(direction, this.preferredGrowth)) {
  14. goodDirections.push(direction);
  15. } else {
  16. badDirections.push(direction);
  17. }
  18. }
  19. this.directionsArray = goodDirections.concat(badDirections);
  20. }
  21. public getDirection () {
  22. return this.directionsArray[this.runner++];
  23. }
  24. }