U WS 01

Universe Worksheet 01

  1. Name at least one job a server performs.

  2. Explain at least one thing the client does that the server does not do.

  3. When world1 sends a message, where is the first place the message goes?

  4. Which of the following types of information are allowed in a message?

    A. Number. B. Boolean. C. Color. D. String. E. Posn. F. Image. G. List of Numbers. H. Model struct defined in your program.

  5. In our class, we label all of the worlds with some information. What is it?

  6. What kind of information do we always include in our messages? Why?

Coding 1

A simple animation has a model with an id and a posn. The posn changes to the coordinates of the mouse whenever you move the mouse. Hitting a key sends the current coordinates as a message and then jumps the posn to (50, 100).

(define-struct model (id pos))
(define-struct msg (from x y)) ;; #:prefab if on computer
  1. Make an example model m1 showing the world with id 2 has its posn at (90,40).
  2. Write a check-expect for the mouse handler showing what happens to m1 when you move the mouse to (100, 30).
  3. Write a check-expect for the key handler showing what happens to m1 when you hit the “w” key.
  4. Write the code for the key handler.

Coding 2

This section describes a simple “chat” app, where each world sends a one-line message. As described, for super-simplicity there is no “chat history” at all. (That is, only the most recently sent message is remembered.) Note: see the last part below before coding on the computer.

  1. A single Player has an id number, a string name, and a string conversation (co).

    1. Define the player structure.
    2. Create a player called p1 with identification number 6, name “Waldo” and conversation, “Good to meet you.”
  2. When you type, the keys are added to your conversation. When you hit enter ("\r"), two things happen:

    1. Reset the conversation to be empty ("").
    2. A message is sent with the name of the world and a colon in front of the conversation. “WorldName: Conversation” (You should not literally send that string.)

    Write a check-expect showing that your key handler key-h has this behavior.

  3. One huge drawback of this setup is that a world cannot even remember what you have been typing in it before it receives a message. What changes would be necessary in order for each world to remember all of the messages it gets from other worlds?

Last modified August 18, 2023: 2022-2023 End State (7352e87)