Dodawanie Poziomów
Poziom jest kolejnym obiektem JavaScript:
const Level1 = {
  // Level definition.
};
Zacznijmy od napisania opisu oraz wskazówki dla naszego poziomu:
const Level1 = {
  description:
    "You've entered the ancient castle of Eastwatch to escape from a blizzard. But it's deadly cold inside too.",
  tip:
    "Call `warrior.walk()` to walk forward in the Player's `playTurn` method.",
};
Musimy również zdefiniować dwie liczby: premię czasową i wynik ace. Gracz dostaje premię czasową w zależności jak szybko ukończy poziom (jest zmniejszany tura po turze zanim nie dojdzie do zera). Natomiast wynik ace jest używany do obliczania poziomu klasy (tylko w trybie epickim). Jakikolwiek wynik większy lub równy wynikowi ace dostanie S. Dodajmy te numery:
const Level1 = {
  description:
    "You've entered the ancient castle of Eastwatch to escape from a blizzard. But it's deadly cold inside too.",
  tip:
    "Call `warrior.walk()` to walk forward in the Player's `playTurn` method.",
  timeBonus: 15,
  aceScore: 10,
};
Te dwie liczby będą musiały być odpowiednio nastrojone podczas testowania wieży. W tym przewodniku już to zrobiliśmy.
Następną rzeczą do zrobienia jest zdefiniowanie piętra poziomu, zaczynając od jego rozmiaru:
const Level1 = {
  description:
    "You've entered the ancient castle of Eastwatch to escape from a blizzard. But it's deadly cold inside too.",
  tip:
    "Call `warrior.walk()` to walk forward in the Player's `playTurn` method.",
  timeBonus: 15,
  aceScore: 10,
  floor: {
    size: {
      width: 8,
      height: 1,
    },
  },
};
Następnie musimy umieścić schody, aby umożliwić Wojownikowi przejście na następny poziom:
const Level1 = {
  description:
    "You've entered the ancient castle of Eastwatch to escape from a blizzard. But it's deadly cold inside too.",
  tip:
    "Call `warrior.walk()` to walk forward in the Player's `playTurn` method.",
  timeBonus: 15,
  aceScore: 10,
  floor: {
    size: {
      width: 8,
      height: 1,
    },
    stairs: {
      x: 7,
      y: 0,
    },
  },
};
Mówiąc o wojowniku, zdefiniujmy go dla tego poziomu:
const Level1 = {
  description:
    "You've entered the ancient castle of Eastwatch to escape from a blizzard. But it's deadly cold inside too.",
  tip:
    "Call `warrior.walk()` to walk forward in the Player's `playTurn` method.",
  timeBonus: 15,
  aceScore: 10,
  floor: {
    size: {
      width: 8,
      height: 1,
    },
    stairs: {
      x: 7,
      y: 0,
    },
    warrior: {
      character: '@',
      maxHealth: 20,
      position: {
        x: 0,
        y: 0,
        facing: 'east',
      },
    },
  },
};
Gdy to zrobimy poziom jest ukończony. Przed kontynuowaniem, zdefiniujmy kolejny poziom:
const Level2 = {
  description:
    'The cold became more intense. In the distance, you see a pair of deep and blue eyes, a blue that burns like ice.',
  tip:
    "Use `warrior.feel().isEmpty()` to see if there's anything in front of you, and `warrior.attack()` to fight it. Remember, you can only do one action per turn.",
  clue:
    'Add an if/else condition using `warrior.feel().isEmpty()` to decide whether to attack or walk.',
  timeBonus: 20,
  aceScore: 26,
  floor: {
    size: {
      width: 8,
      height: 1,
    },
    stairs: {
      x: 7,
      y: 0,
    },
    warrior: {
      character: '@',
      maxHealth: 20,
      position: {
        x: 0,
        y: 0,
        facing: 'east',
      },
    },
  },
};
Ponieważ to wszystko zaczęło być większym wyzwaniem dla gracza, tym razem dodaliśmy wskazówkę. Wskazówki są opcjonalne i będą pokazywane tylko na żądanie.
Teraz musimy dodać te dwa poziomy do wieży. Poziomy są dodawane do tablicy wieży o nazwie levels:
module.exports = {
  name: 'Game of Thrones',
  description:
    'There is only one war that matters: the Great War. And it is here.',
  levels: [Level1, Level2],
};
Znakomicie! Ale jak może zauważyliście, kazaliśmy graczowi wywołać warrior.attack(), warrior.feel(), oraz warrior.walk(), lecz nie nauczyliśmy Wojownika jak wykonywać te czynności. Zróbmy to teraz!