Project Two: WebSockets Checkers

Overview

The main objective of this project is to give you experience writing WebSockets code.

The project is due at 8am on the day of the final. I will clone your repositories for grading at that time.

The Project

In this project, you will take the infrastructure for a simple GUI game—checkers—and add WebSockets code that will allow the game to be played over a network.

The Existing Code

The code in this repository is in three packages. checkers.client contains GUI code for drawing a checkerboard. checkers.common contains some classes used by both the client and server: a kind of "lightweight" model of a checkerboard that represents the board, the squares on the board, and the players who may occupy those squares. The client, for example, will use this lightweight model to draw the board. Finally, checkers.server contains a "heavier" model which includes the rules of checkers— which jumps are legal? when does a checker get kinged? and so on. Note that the client will run as it is, but nothing will happen when you try to move a checker.

A Network Architecture

This code is ready to be embedded in a WebSockets application. Here's the idea: Once a "checkers server" starts, clients can connect in order to play. Once two clients have connected, the server lets them start playing. When a client tries to make a move, a message is sent to the server. If the move is not legal, an "illegal move" message is sent back to the client, and nothing else happens. If the move is legal, then the server sends a message to both clients, letting them know that the move has been made and indicating that it's the other player's turn. The clients, in turns, should update their display of the board and let the users know whose turn it is.

Important: when a user tries to make a move, the client should not display that move immediately—it MUST send the move to the server. The display should only ever be updated in response to a message from the server.

Of course, when a player wins, the server should send an appropriate message, and the clients, upon receiving that message, should end play.

What You Need to Do

The GUI code and checkers-model code is in good shape. Your focus is on communication: What kinds of messages will the clients send to the server? What kinds of messages will the server send to the clients?

How will your client code actually send messages to the server? When should such messages be sent?

On the server side, how will you code a relationship between the WebSockets endpoint and the checkers model?

Behavior

Your application should

  1. allow clients to connect to the server
  2. allow the clients to play a "legal" game of checkers
  3. inform players when a game has ended

You could also add extra functionality to make the game more enjoyable. For example, you might to incorporate a chat behavior so that the players can talk trash. (But please get the basic application working before you think much about extra stuff!) >