2014-11-06 2 views
0

총알 목록 및 총알 목록에 대한 속도를 기반으로 각 총알 위치를 업데이트하려고합니다. 그리고 업데이트 된 글 머리 목록을 반환합니다.계획은 위치 속도 방향으로 총알 위치 목록을 업데이트합니다.

나는 내 코드는 논리적으로 작동 생각하지만 방식은 나에게 오류 코드

function call: expected a function after the open parenthesis, 
but received (make-signature ...) 


;; A Bullet is (make-bullet Posn Number Direction Number) 
;; interpetation: represents a bullet, its current position, 
;;    its speed, its direction and its potential damage 
(define-struct bullet (location speed direction damage)) 

;; A Direction is one of 
;; - 'Up 
;; - 'Down 
;; - 'Left 
;; - 'Right 

;; a list of bullets(lob) is either 
;; - empty 
;; - (cons bullet lob) 

;; A location is Lof[location] 
;; A location is a Posn 

;; move-bullets: lob -> lob 
;; takes in a list of bullets and updates each bullet's location 
;; based on the bullets direction and speed 

(define (move-bullets lob) 
    (cond 
    [(empty? lob) empty] 
    [(cons? lob) (cons (create-new-bullet (first lob)) 
         lob)])) 

;; create-new-bullet: location direction speed-> location 
;; takes in a list of bullets' location and create the "moved" bullet 
;; base on given direction, speed 

(define (create-new-bullet location dir speed) 
    (cond 
    [(symbol=? 'Up dir) 
    (make-posn (posn-x location) (- (posn-y location) speed))] 
    [(symbol=? 'Down dir) 
    (make-posn (posn-x location) (+ (posn-y location) speed))] 
    [(symbol=? 'Left dir) 
    (make-posn (- (posn-x location) speed) (posn-y location))] 
    [(symbol=? 'Right dir) 
    (make-posn (+ (posn-x location) speed) (posn-y location))])) 

hummh을 제공합니다. 아무것도 여기에 잘못갑니다 ???

답변

2

글 머리표을 매개 변수로 전달하므로 각 구성 요소를 추출해야합니다. 이 시도 :

(define (create-new-bullet bullet) 
    (let ((location (bullet-location bullet)) 
     (speed (bullet-speed bullet)) 
     (direction (bullet-direction bullet)) 
     (damage (bullet-damage bullet))) 
    (cond 
     [(symbol=? 'Up direction) 
     (make-bullet 
     (make-posn (posn-x location) (- (posn-y location) speed)) 
     speed direction damage)] 
     [(symbol=? 'Down direction) 
     (make-bullet 
     (make-posn (posn-x location) (+ (posn-y location) speed)) 
     speed direction damage)] 
     [(symbol=? 'Left direction) 
     (make-bullet 
     (make-posn (- (posn-x location) speed) (posn-y location)) 
     speed direction damage)] 
     [(symbol=? 'Right direction) 
     (make-bullet 
     (make-posn (+ (posn-x location) speed) (posn-y location)) 
     speed direction damage)]))) 

는 또한, 당신은 재귀 발전하는 것을 잊었다 :

(define (move-bullets lob) 
    (cond 
    [(empty? lob) empty] 
    [(cons? lob) (cons (create-new-bullet (first lob)) 
         (move-bullets (rest lob)))])) 
+0

좋은 점을! 내가 시험해 볼게. – ads27

+0

테스트 :'(이동 - 글 머리 기호 (make-buln (make-posn 10 10) 4 'Up 10)))'총알 방향 : 1 개의 인수를 기대하지만 아무 것도 찾지 못했습니까? – ads27

+0

'create-new-bullet'에 버그가있어서 다시 복사해서 –