U WS 01
Universe Worksheet 01
-
Name at least one job a server performs.
-
Explain at least one thing the client does that the server does not do.
-
When world1 sends a message, where is the first place the message goes?
-
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.
-
In our class, we label all of the worlds with some information. What is it?
-
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
- Make an example model
m1
showing the world with id 2 has its posn at (90,40). - Write a check-expect for the mouse handler showing what happens to
m1
when you move the mouse to (100, 30). - Write a check-expect for the key handler showing what happens to
m1
when you hit the “w” key. - 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.
-
A single Player has an
id
number, a stringname
, and a string conversation (co
).- Define the player structure.
- Create a player called
p1
with identification number 6, name “Waldo” and conversation, “Good to meet you.”
-
When you type, the keys are added to your conversation. When you hit enter (
"\r"
), two things happen:- Reset the conversation to be empty (
""
). - 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. - Reset the conversation to be empty (
-
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?