2017-02-09 96 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]))))