我正在尝试制作一个以各种步骤接受用户输入的程序。在程序开始时,玩家通过外部函数命名自己,该函数应该返回一个玩家对象,稍后会多次引用它。
#lang racket
(define player
(class object%
(init-field
name
money
lives
health)
(super-new)
(define/public (get-money)
money)
)
)
;None of this function runs/the user is never prompted...
(define (start-game)
(print "What do you want to name yourself?")
(define name (read-line))
(define start-mon (random 1000 5000))
(print "You're starting with ")
(print start-mon)
(print " dollars.")
(new player [name name]
[money 0]
[lives 2]
[health 100])
)
(define (main)
(define player start-game)
(let/ec break
(let loop ()
(print ":")
(define input (read-line))
(cond [(string=? input "health") (send player get-health)]
[(string=? input "exit") (break)]
[else (print "sorry, command not recognized. Type help for commands.")])
(loop)))
(print "exiting..."))
(main)
我的问题是,如何正确地将玩家变量分配给函数start-game的返回对象,同时让整个函数执行并提示用户?
谢谢!