to checkhit ; We use an IF statement to see if we hit the target. Note the ; use of AND to see if both guesses are correct before doing a checkhit. make "truth and :guessdistance = :distance :guessbearing = :bearing if and :guessdistance = :distance :guessbearing = :bearing ~ [print [Safe Landing!!!] stop] ; If we didn't hit it, we ask for another input, then we ; increment our guess number so we can track the number of guesses. print [Missed, try again!] make "guessnumber :guessnumber + 1 ; We now must move the turtle back to it's original starting location back :guessdistance left :guessbearing ; and we play the game again playgame end to colors ;This creates pen colors by checking for the remainder when dividing guessnumber ;by 4. The reason to add 4 first is that guess number starts at 0 ;The reason to divide by 4 is it gives black, red, green, and blue in order. make "colordriver remainder :guessnumber + 4 4 ; show :colordriver ifelse :colordriver = 1 [make "red 255] [make "red 0] ifelse :colordriver = 2 [make "green 255] [make "green 0] ifelse :colordriver = 3 [make "blue 255] [make "blue 0] setpc (list :red :green :blue) end to drawtarget ; here we move to where the target is located, and we draw a target ; Note that we start with the pen up. penup right :bearing forward :distance pendown left 90 forward 5 right 90 repeat 3 [fd 10 rt 90] forward 5 right 90 ; After drawing the target, we move bask to the origin. Note that we make opposite movements. penup back :distance left :bearing end to getguess ; Here, we get the guess and we assign the list to a variable. We then parse ; the list to get the first term for the distance and the second term for the bearing. print [Enter a distance and bearing to the target:] make "guess readlist make "guessdistance first :guess make "guessbearing last :guess end to launch ; We call colors to set pen colors before ; putting the pendown to draw the line colors pendown right :guessbearing forward :guessdistance end to picktarget ; We use random numbers to set the target distance and bearing. For distance, ; we add 100 so that the minimum distance is 100 and the maximum is 300. ; The bearing just comes from the number of degrees in a circle. make "distance 100 + random 200 make "bearing random 360 end to playgame getguess launch checkhit end to rocket setup playgame end to setup ; This clears the screen, sets initial variables, and creates the target. CS make "guessnumber 0 picktarget drawtarget end