Engineering Computing

PI: Laboratory 6: Communicating Applications

Overview

There are two parts to this laboratory assignment. In the first part, you will build a simple graphical user interface and some additional infrastructure. In the second half of this lab, you will augment that work. By the end of this project, you will have built a very simple two-player video game.


Introduction

The game that you will be creating in this lab is called Cat and Mouse. (In other languages, we've been told, it might be more appropriate to call it Dog and Cat. If you have other creative suggestions, please let us know and we may change its name if we get a good enough suggestion; however, in this description of the problem set, we'll use Cat and Mouse.)

A quick definitional note: In this lab the term Mouse (capital M) is used to describe the Mouse portion of the problem set (as opposed to the Cat portion) which the term mouse (lower case m) is used to describe the pointing devise.

Cat and Mouse is a very simple network game. Two computers are involved. Each sees a window containing colored dots. One player (running the Cat program) will see two dots: the Cat dot, which s/he controls by moving the mouse, and the Mouse dot, which s/he does not control. You may choose what the Cat and Mouse dots should look like. For example, the Cat might be a big red dot, while the Mouse might be a small black dot. That might look like this:

The other player (running the Mouse program) sees the Mouse dot, which s/he controls by moving the mouse. When the Mouse player moves the Mouse dot, it should move on both screens: the Cat player's screen and the Mouse player's screen. You may also design what the Mouse player's display looks like, including choosing whether the Mouse player can see the Cat dot. (Mike says it's not fair unless it can.) In any case, the Mouse dot on both screens should move when the Mouse player moves the mouse. Any Cat dots should move when the Cat player moves the mouse.

The object of this game is for the Cat player to click on the Mouse dot. If the Cat and Mouse dots overlap when the Cat clicks, then both players should receive a message that the Cat catches the Mouse. Otherwise, both players should receive a message that the Cat failed to catch the Mouse.

Running the Demo

It is highly recommended that you run the demo before you attempt this lab; it will make the instructions a lot easier to understand.

In order to run the demo, you need to start up two separate programs on two separate computers. One is the Cat, and one the Mouse. When you start up each of these applications, you will be asked for some information. You will need to know the name (or the IP address) of the computer that the Mouse is running on. The way that we have set up the demo, the Mouse must supply the requested information first.

You can demo the program on your machine by first downloading the appropriate jar file: cat.jar mouse.jar

Then open a command prompt at the directory you saved the mouse jar to and execute

java -cp mouse.jar catandmouse.MouseDemo

on one machine, and then open a command prompt at the directory you saved the cat jar to and execute:

java -cp cat.jar catandmouse.CatDemo

on another machine.

You will be asked for a port (and, for the Cat, hostname).

  • Both the Cat and the Mouse should use the same port number; the one that is listed as a default is fine, or you can pick any other (but it should be at least 1024).
  • The Cat will also be prompted for a hostname. You should supply the ip address of the machine that the Mouse is running on. (You can get this on Mouse's machine by typing ipconfig at a command prompt on a Windows machine; or ifconfig on a unix-based machine.)
  • The Mouse has to supply its information first, so that there will be a connection in place before the Cat tries to access it.

Once the MouseDemo program is running, you should start the CatDemo program. Later, we will discuss why this ordering constraint is important. When you start up the demo programs, a dialog will appear. You should supply the following information to the CatDemo:

The hostname is the ip address of the computer to which you wish to connect. This will be the ip address of the computer on which the MouseDemo program is running. The port number must match the port number that the MouseDemo is using. If you don't do anything special, this will be 4321. If you change the number in the MouseDemo dialog box, you will need to change the number in the CatDemo dialog box to match it.

Questions, comments, gripes and other communication to pi-staff@lists.cognition.olin.edu
This course is a part of Lynn Andrea Stein's Rethinking CS101 project at the Computers and Cognition Laboratory and the Electrical and Computer Engineering area at Franklin W. Olin College of Engineering. Olin College Logo