2015-02-24 87 views
2

我是一名初學者程序員,我正在嘗試使用Delphi Pascal語言製作基於文本的RPG遊戲(如Zork)。 我做了其中的主角打開一個箱子,找到一些項目事件:如何在Delphi中創建一個事件只發生一次?

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中輸入「Open Chest」時,它會說「它是空的」。

但是如何?

+0

第一次打開標誌(布爾值)爲true時。 – 2015-02-24 20:37:55

+5

試圖通過'TEdit' GUI控件編寫遊戲邏輯會導致一團糟。時間重新思考。 – 2015-02-24 20:48:18

+0

@David。他應該關注哪個方向的任何建議? – 2015-02-24 23:53:39

回答

4

你必須使用額外的變量,它會告訴你胸部是否已經打開。

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;