So, I will review the first chapter, "How to Develop Programs for the Second Edition." I believe that I have achieved good success. But there is a βsuggestionβ to add another graphic to the grid. Every time I try, I get an error message. At this moment I am stuck. Below is the code and error.
Note: the ROCKET image is in chapter 1. I just copied and pasted it into the IDE.
Note. "Suggestion": How to change the program so that the rocket lands on a flat rock bed, which is 10 pixels above the bottom of the stage? Remember to also change the scenery.
HTDP Chapter 1
This is where the code works.
(define BOARDWIDTH 200) (define BOARDHEIGHT 200) (define STARTPOSITION 50) (define BOARDBKGR "blue") (define GAMEBOARD (empty-scene BOARDWIDTH BOARDHEIGHT BOARDBKGR)) (define ROCKET .) (define UFO (overlay (circle 10 "solid" "red") (rectangle 40 4 "solid" "green"))) (define FLATBED (rectangle 60 10 "outline" "black")) (define (SPACESHIP option) (cond [(= option 1) ROCKET] [(= option 2) UFO])) (define SHOWNSHIP (SPACESHIP 1)) (define V 20) ;Velocity (define A 1) ;Acceleration (define (distance t) ;t = Time (- (* V t) (* 1/2 A (sqr t)))) (define SPACESHIP-BOTTOM (- BOARDHEIGHT (/ (image-height SHOWNSHIP) 2))) (define (render-shownship xy) (place-image SHOWNSHIP xy GAMEBOARD)) (define (create-rocket-scene.v7 t) (cond [(<= (distance t) SPACESHIP-BOTTOM) (render-shownship STARTPOSITION (distance t))] [(> (distance t) SPACESHIP-BOTTOM) (render-shownship STARTPOSITION SPACESHIP-BOTTOM)]))
Here's the code that doesn't work:
(define BOARDWIDTH 200) (define BOARDHEIGHT 200) (define STARTPOSITION 50) (define BOARDBKGR "blue") (define GAMEBOARD (empty-scene BOARDWIDTH BOARDHEIGHT BOARDBKGR)) (define ROCKET .) (define UFO (overlay (circle 10 "solid" "red") (rectangle 40 4 "solid" "green"))) (define FLATBED (rectangle 60 10 "outline" "black")) (define (SPACESHIP option) (cond [(= option 1) ROCKET] [(= option 2) UFO])) (define SHOWNSHIP (SPACESHIP 1)) (define V 20) ;Velocity (define A 1) ;Acceleration (define (distance t) ;t = Time (- (* V t) (* 1/2 A (sqr t)))) (define SPACESHIP-BOTTOM (- BOARDHEIGHT (/ (image-height SHOWNSHIP) 2))) (define (render-shownship xy) (place-image SHOWNSHIP xy GAMEBOARD) (place-image FLATBED STARTPOSITION 195 GAMEBOARD)) ;offender (define (create-rocket-scene.v7 t) (cond [(<= (distance t) SPACESHIP-BOTTOM) (render-shownship STARTPOSITION (distance t))] [(> (distance t) SPACESHIP-BOTTOM) (render-shownship STARTPOSITION SPACESHIP-BOTTOM)]))
And I get the error:
define: only one expression is expected for the function body, but 1 additional part is found
source share