增加塔層
塔層是另一個JavaScript物件:
const Level1 = {
// Level definition.
};
讓我們開始為塔層寫上描述及提示:
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.",
};
我們還需要定義兩個數字:時間獎勵 (time bonus) 及王牌分數 (ace score)。 時間獎勵是取決於玩家完成塔層的速度所賺得的獎勵(這個獎勵會按回合遞減,直到零分)。 另一方面,王牌分數則是用來計算塔層的等級 (只限史詩模式)。 任何等如或大於王牌分數的成績都會得到S的評級,讓我們加入以下數字:
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,
};
這兩個數字需要我們測試塔層以進行仔細調整。在這份指南,我們已測試好數字。
下一步就是定義塔層的地面,由它的尺寸開始:
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,
},
},
};
然後,我們需要決定樓梯的位置,讓勇士能夠移動到下一層:
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,
},
},
};
既然提及到勇士,就讓我們定義這一層的勇士:
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',
},
},
},
};
就這樣,這一層就完成了,不過在繼續之前,先讓我們定義另一個塔層:
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',
},
},
},
};
由於勇士面對的挑戰越來越大,這次我們加了一個線索。線索是可選的,只會在有需要的時候才會顯示。
現在我們需要將這兩個塔層加到層塔了,將它們加到塔的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],
};
太出色了! 但你或者都留意到,雖然我們指示了勇士召叫warrior.attack()
, warrior.feel()
及 warrior.walk()
,但我們還未教他要做些什麼, 現在讓我們進行下一步吧!