Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 球拍的游戏循环_Loops_Racket_Main_Cycle - Fatal编程技术网

Loops 球拍的游戏循环

Loops 球拍的游戏循环,loops,racket,main,cycle,Loops,Racket,Main,Cycle,我正在制作一个非常基本的记忆游戏,它向用户展示7个从1到10的随机数字,并要求他们按相同的顺序输入数字。我可以让它工作一次,但我希望它持续运行,直到用户退出。(重复主程序)关于如何实现这一点有什么想法吗 (require math/base) ; ======================================= ; Functions ; ======================================= ; set essentially constants (de

我正在制作一个非常基本的记忆游戏,它向用户展示7个从1到10的随机数字,并要求他们按相同的顺序输入数字。我可以让它工作一次,但我希望它持续运行,直到用户退出。(重复主程序)关于如何实现这一点有什么想法吗

(require math/base)

; =======================================
; Functions
; =======================================
; set essentially constants
(define lowerLimit 1)
(define upperLimit 11)
(define amount 7)


; builds a list with random integers between lowerLimit and upperLimit
(define (buildSimon x L)
  (cond [(= x 0) L]
        [else (buildSimon (- x 1) (cons (random-integer lowerLimit upperLimit) L))]))

; adds element to back of the list
(define (addBack L e)
  (if (null? L)
      (list e)
      (cons (first L) (addBack (rest L) e))))

; gets input from user and builds list
(define (getInput n x L)
  (cond [(= n 1) (addBack L x)]
        [else (getInput (- n 1) (read) (addBack L x))]))

; =======================================
; Main program below here
; =======================================
; Generate new random number sequence
(printf "Simon says: ")
(define sequence (buildSimon amount (list)))
(display sequence) (newline)
(printf "== Memorize and guess ==\n")
(printf "== Type 'go' and hit enter to guess ==\n")
(read)

; Add spacing to hide numbers
(printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
(printf "== Type the numbers in order as they appeared. ==\n")
(printf "== Hit ENTER in between each number. ==\n")

; Gather input for comparison
(define answer (getInput amount (read) (list)))

; Do comparison
(if (equal? sequence answer)
    (printf "Correct! Congratulations on your perfect memory.\n")
    (printf "Wrong! I'm sorry your memory has failed you.\n"))

提前感谢。

您可以创建一个包含所有主代码的函数,函数的最后一行递归地调用自己