6.6

Assignment 6

home work!

Programming Language BSL

Due Date Monday 02/04 at 9pm

Purpose To practice designing world programs and working with custom structures.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.

  • You must follow all the steps of the design recipe when completing this assignment.

  • Please be sure to look at the feedback for assignment 4 before submitting, as we will be grading you more harshly on things we have warned you about before.

  • You must submit this assignment with your new partner, assigned in lab on Friday, February 1st. Please make sure you can submit with your partner before 5pm on Monday or we cannot guarantee that you will be able to submit your homework before the deadline.

Graded Exercises

Exercise 1 Consider the following two data definitions:
; A Person.v1 is a (make-person String Nat String Nat Nat)
(define-struct person1 [name house-number street zipcode social])
; - where name is the person's full name
; - house-number is the person's house number
; - street is the name of the street the person lives on
; - zipcode is the zipcode the person lives in
; - and social is the person's social security number
 
; A Person.v2 is a (make-person String Address Nat)
(define-struct person2 [name address social])
; - where name is the person's full name
; - address is the address where the person lives
; - and social is the person's social security number
 
; An Address is a (make-address Nat String Nat)
(define-struct address [house-number street zipcode])
; - where house-number is the number of the house
; - street is the street the house is on
; - and zipcode is the zipcode the house is in
Which Person data definition is better designed? Why? Write your answer in a comment.

Exercise 2 Complete Exercise 77 in section 5.7 of the textbook. Be sure to follow all the steps of the data design recipe.

Exercise 3 Complete Exercise 81 in section 5.8 of the textbook.

Al Herpin is having trouble sleeping. His friends suggested that he count sheep but Al is not very good at counting so instead he is going to play a word game with the sheep. In the remainder of this assignment you will design a world program where a sheep moves across the screen from left to right with a word on it. The player has to type the word before the sheep reaches the right edge of the screen. If they manage to type the word, the sheep will disappear and a new sheep will appear at the left edge of the screen with another word on it. The new sheep will move faster than the old one. If the player fails to type the word in time, they lose and the game is over.

Exercise 4 Design a data definition for the world state of this program. Remember to follow all the steps of the data design recipe and keep in mind that your data definition should:
  • NOT store the set of possible words. These words will never change so you will not need to keep them in your worldstate.

  • follow good design practices so that each definition encompasses only one object (see Exercise 1 of this assignment).

Exercise 5 Design your world program. Here are some key things to note:
  • The program should take in the initial speed of the first sheep on the screen.

  • You need to draw the sheep at its current location, with the word the user needs to type on it, as well as drawing the text the user has typed sofar in a way that does not overlap with the sheep image.

  • When a sheep goes past the edge of the screen ENTIRELY the game should end.

  • You do not have to support backspace (that is, if you press the backspace or delete key you do not have to delete a character from what the user typed) but your program should not break or display nonsense if the user presses this key. In fact, your program should not break or display nonsense no matter which key the user presses.

  • When the user presses enter you should check if they have typed the correct word. If so, generate a new sheep on the left edge of the screen with a random word on it. The new sheep should move faster than the old one. You should select a random word from three non-empty distinct words of your choice. They could be sheep-related words but it’s not mandatory. If the user typed the wrong word, just clear the text that they typed so they can try again.