2017-02-09 74 views
0

我正在參加一個介紹編程課。我們在DrRacket中使用學生語言。基本球拍:結束值

問題:我想在大爆炸比賽結束後返回一個特定值(要求2htdp /宇宙)`。

電流輸出:當遊戲結束時,DrRacket返回我目前worldstate,這是我在遊戲中使用結構的列表。

對解決進展情況:好像也許能夠幫助我,但我不知道如何使用它。

TL; DR:
問題:遊戲結束 - >返回世界國家(結構列表)
旺旺:遊戲結束 - >返回其他值(數字)

讓我知道如果我能以任何方式澄清!謝謝!

編輯:我想我找到了解決辦法。我用我通常所說的表達方式來表達我的意思?函數,並將其作爲cond分支放入我的on-tick函數中。當我的on-tick函數調用該函數時,它會將世界狀態更改爲我想要輸出的任何內容。那麼,在我的最後?函數,我只是檢查世界狀態是否與通常情況不同。

感謝您的幫助!

解決方案:

; A Test Case (TC) is a (make-tc Number) 
(define-struct tc [number ticks]) 
; number is a number used to test this problem 

; TC -> Number 
; Begins the main big-bang function; outputs the inverse of tick speed 
; times the number of ticks elapsed when the game ends. 
(define (main tick-speed) 
    (* (/ 1 tick-speed) 
     (tc-ticks (big-bang (make-tc 0 0) 
      [to-draw draw] 
      [on-tick check tick-speed] 
      [stop-when end? end-scene])))) 
+0

你定義一個主要功能和使用設計的配方? –

+0

是的!我至少這麼認爲 - 主要功能只需要簽名和目的聲明。它處於世界狀態並輸出世界狀態。 我只是不知道如何向世界狀態從結構改變了一些程序結束前的。 – Julian

+0

更多信息:我在製作第一個更大的程序時提出了這個問題,所以我繼續輸入了一個更小的版本,我正在使用它來測試哪些方法可行。 在此模型中,DrRacket在結束時輸出「(make-tc 3)」,但我希望它輸出與「hello」完全不同的內容。 – Julian

回答

0

回答原帖:

; A Test Case (TC) is a (make-tc Number) 
(define-struct tc [number ticks]) 
; number is a number used to test this problem 

; TC -> Number 
; Begins the main big-bang function; outputs the inverse of tick speed 
; times the number of ticks elapsed when the game ends. 
(define (main tick-speed) 
    (* (/ 1 tick-speed) 
     (tc-ticks (big-bang (make-tc 0 0) 
      [to-draw draw] 
      [on-tick check tick-speed] 
      [stop-when end? end-scene]))))