;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname Flower_Project1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;;Matt Flower ;;CSCI 1301 ;;Project1 ;; ============== These are the two predefined functions ==================== ;; You don't need to understand their code, only the contract and the purpose ;; =========================================================================== ;; ===================== You may skip to the sample code below ================ ;; get-choice: string, list of strings -> integer ;; the function displays a simple menu form with the given message ;; and a drop-down menu with the list of choices. The menu ;; initially displays "Make a choice". Once a different item is chosen, ;; that item is returned. ;; When a "Close" button is pressed, the form disappears. (define (get-choice message list-of-choices) (local ( (define the-choices (make-choice (cons "Make a choice" list-of-choices))) (define w (create-window (list (list (make-message message)) (list the-choices) (list (make-button "Close" (lambda (e) (hide-window w))))))) (define (process-result n) (cond [(> n 200) (hide-window w)] ;; timeout after 200 sec [(= (choice-index the-choices) 0) (and (sleep-for-a-while 1) (process-result (+ n 1)))] [else true]) ) ) (cond [(process-result 0) (list-ref list-of-choices (- (choice-index the-choices) 1))]))) ;; get-answer: string number -> string ;; The function displays a simple text input with a question ;; and returns the answer typed in by the user ;; The second parameter (delay) is the number of seconds ;; the function waits after the typing of the first character ;; before it returns the answer. If the user takes longer ;; than that, a partial answer may be returned ;; 5 sec delay is reasonable for a one-word answer (define (get-answer question delay) (local ((define the-answer (make-text question)) (define w (create-window (list (list the-answer) (list (make-button "Close" (lambda (e) (hide-window w))))))) (define (process-result n) (cond [(> n 200) (hide-window w)] ;; timeout after 200 sec [(string=? (text-contents the-answer) "") (and (sleep-for-a-while 1) (process-result (+ n 1)))] [else true] ;; the user starts typing ))) (cond [(process-result 0) (cond [(sleep-for-a-while delay) (text-contents the-answer)]) ]) )) ;; =========================== do not change anything above this line ============= ;; NOTE: The language is Intermediate Student with lambda ;; =========================== Your work goes here: =============================== (define (list-weapons alos lineNum) (cond [(empty? alos) true] [else (and (draw-solid-string (make-posn 20 (* lineNum 15)) (first alos)) (list-weapons (rest alos) (+ lineNum 1)) )] ) ) (define (clear-screen x y) (draw-solid-rect (make-posn 0 0) x y 'white) ) (define (type-writer string speed) ( ;; This is an example of one round of the accummulation stage of a game. ;; Your game will have multiple rounds. ;; the initial list of weapons: (define starting-weapons (list "cane" "rolling pin" "knife" "jackal" "onion")) ;; the first list of choices: (define weapon-choices1 (list "frying pan" "light saber")) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of weapons. weapon-list1 is the new list (define weapon-list1 (cons (get-choice "Choose your weapon" weapon-choices1) starting-weapons)) ;; calling a get-answer function to let the user type in their name ;; 5 is the number of seconds you expect the user to spend on typing ;; the answer (from the fisrt character to the last one). ;; Too short times may result in the program getting a partial answer ;; Feel free to adjust this time as needed (define character-name (get-answer "What's your name?" 5)) (start 400 300) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " now has a ", and the newly-added item in the ;; weapons list (define message (string-append character-name "'s inventory:")) ;; draws a string on the canvas at the given position ;; no control over the font or the ecolor, sorry... ;; you might want to add a drawing, too (draw-solid-string (make-posn 20 20) message) (list-weapons weapon-list1 3) (sleep-for-a-while 3) ;; clear the screen (clear-screen 400 300)