Try Firefox!

Lab 14: A UDP game client


Overview
In this lab you will create a UDP client program that allows you to act as a player in a distributed game called Worm World. You client's role is to contact the server to initate play and be assigned a worm color, and then to read player actions (↑, ↓, ←, → and space-bar) and send them along to the WormWorld server. We'll be using UDP to make all this happen. You can see what WormWorld looks like with AI players by giving the following command:
bash$ /home/wcbrown/bin/ic221/demo

The life of your client
The life of your client program is pretty simple. It'll be run from the command-line something like this
bash$ wwclient banshee 18000
and do the followin:
  1. Get hostname and port number from command-line.
  2. Send an empty message to server at given hostname and port numer.
  3. Read server response I: a new port number
  4. Read server response II: the color of your worm
  5. Print out color so player knows the color of the worm he is assigned, and use the new port number for all subsequent communication.
  6. Read player keystrokeand respond by sending server one of the following single-character messages:
    • N to move north
    • S to move south
    • E to move ease
    • W to move west
    • T to stop
  7. goto step 6

The details
Download clientskel.c (Note: in MI316 use this version, i.e. for Dr. Crabbe's Class) . You should use it as a starting point for your client. It includes most of the information you need. Notice that it includes code to put the terminal in unbuffered mode, so as soon as a key is pressed, it is read by the program. Also, it describes how non-ASCII keys (like the arrow keys) can be handled.

Submission
Your instructor will explain WormWorld's rules to you. Running the demo probably explains it pretty well on it's own, though. Once several people have their clients ready, you can play a match: many worms enter, one worm leaves. Your instructor will tell you what to submit and how to submit it.


Christopher W Brown
Last modified: Mon Apr 20 16:37:00 EDT 2009