我是一名初级程序员,我正在尝试使用 Delphi Pascal 语言制作一款基于文本的 RPG 游戏(如 Zork)。 我做了一个事件,主角打开箱子并找到一些元素:
begin
text1.text := 'You see a chest. It is unlocked.';
end;
if edit1.Text = 'Open Chest' then
text1.Text := 'You found 50 Gold Pieces, a Short Sword, a Cloth Armor and a Satchel Bag.';
end;
但我想以一种方式做到这一点,每当有人在第一次之后打开箱子时,箱子就会是空的,因为玩家已经拿走了元素。 换句话说,当有人第二次在 TEdit 中输入“打开箱子”时,它会显示类似“它是空的”之类的内容。
但是如何呢?
最佳答案
你必须使用额外的变量来告诉你箱子是否已经被打开。
var
ChestOpened: boolean;
// initialize at beginning
ChestOpened := false;
...
if Edit1.text = 'Open Chest' then
begin
if ChestOpened then
Text1.Text := 'Chest is empty'
else
begin
ChestOpened := true;
Text1.Text := 'You found 50 Gold Pieces, a Short Sword, a Cloth Armor and a Satchel Bag.'
end;
end;
关于delphi - 如何使 Delphi 中的事件只发生一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28705670/