;; SNAKE! (define GRID-SQSIZE 10) (define BOARD-HEIGHT 20) ;; in grid squares (define BOARD-WIDTH 30) ;; in grid squares (define BACKGROUND (empty-scene (* GRID-SQSIZE BOARD-WIDTH) (* GRID-SQSIZE BOARD-HEIGHT))) (define TICK-RATE 0.3) (define SEG-RADIUS (quotient GRID-SQSIZE 2)) (define SEG-IMAGE (circle SEG-RADIUS "solid" "red")) (define FOOD-RADIUS (floor (* 0.9 SEG-RADIUS))) (define FOOD-IMAGE (circle FOOD-RADIUS "solid" "green")) ;; Snake World (define-struct world (snake food)) ;; A World is a (make-world Snake Food) ;; A Food is a Posn (in grid square coords) (define-struct snake (segs direction)) ;; A Snake is a (make-snake Segs Direction) ;; A Segs is one of: ;; - empty ;; - (cons Posn Segs) ;; where posn is in grid square coords ;; A Snake must contain at least one segment ;; The head is the first element in Segs ;; A NESegs is one of: ;; - (cons Posn empty) ;; - (cons Posn NESegs) ;; A Direction is one of: ;; - "up" ;; - "down" ;; - "left" ;; - "right" ;; Initial wish-list ;; world->scene : World -> Image ;; render the current world ;; food+scene : Food Image -> Image ;; adds the food to a scene ;; snake+scene: Snake Image -> Image ;; add the snake to the scene ;; world->world : World -> World ;; produce the next world ;; snake-slither : Snake -> Snake ;; move snake in direction it's headed in ;; snake-grow : Snake -> Snake ;; grow the snake ;; eating? : World -> Boolean ;; is this an eating scenario? ;; key-handler : World KeyEvt -> World ;; place-image-on-grid : Image Number Number ;; game-over? : World -> Boolean ;; wall-collide? : Snake -> Boolean ;; self-collide? : Snake -> Boolean ;; create-food : World -> World ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define food1 (make-posn 5 3)) (define snake1 (make-snake (cons (make-posn 6 10) empty) "left")) (define world1 (make-world snake1 food1)) ;; world->scene : World -> Image ;; render the current world (define (world->scene w) ...) ;; food+scene : Food Image -> Image ;; adds the food to a scene ;; snake+scene: Snake Image -> Image ;; add the snake to the scene ;; **** Your job: construct examples for world->scene, food+scene, snake+scene **** #;(big-bang world0 (to-draw world->scene) (on-tick world->world) (on-key key-handler) (stop-when game-over?))