Homework Assignment 8

An Interface for Pousse


CS 2530
Intermediate Computing


Due: Friday, November 2, at 5:00 PM

Extended to: Tuesday, November 6, at 8:00 AM


Introduction

For Homework 6, you implemented a Cell class to model one square on the board in a game of Pousse. A grid of Cell objects can provide much of the behavior of the game, despite there being no centralized control program.

For this assignment, you will implement classes needed for two people to play a game of Pousse on the computer. This will include at least an object that "wraps" a grid of Cells and enforces the rules of the game, and a graphical interface.

If you do not feel that your Cell is solid enough for use on this assignment, I will allow you to use my simplest version instead. (I'll make it available to the class by e-mail.) Ideally you can use my implementation to improve yours, but youl are allowed to use mine as-is.



Tasks

  1. Write a class named Pousse to implement the game.

    A Pousse object uses a grid of Cell objects to model the board. It ensures that moves alternate between two players and enforces rules about wins and losses.

    Your class must have a constructor that takes an integer n as an argument, where n is the size of the board. You may have other constructors, too, if you wish.

    An instance of class Pousse should be able to receive at least one message, move(String position). The value of position should a string of the form listed in the game description.

    Suggestion. Save the check for a losing move as the last behavior you implement. It requires a bit more thinking than the rest of the class. (How can we retrieve and store the state of the board after each move?)


  2. Write a class named PousseFrame to implement a graphical user interface for the game.

    A PousseFrame should receive a Pousse object as an argument when created. It will send moves -- user-generated events -- to that object. Note that this means the PousseFrame will not know about a grid of Cells, or any Cell at all.

    This frame will will serve as the interface used by both players. Imagine that the two players are sharing a single mouse (or keyboard).

    You can use any of the Java GUI components we have studied to display the board and get input from the user. For now, the Button class looks most useful as an input device. But soon we will study how to handle arbitrary mouse events, which might make for a more attractive interface. You may want to use private helper methods to isolate different parts of the class, so that they can be changed more easily later.


  3. Write a class named PlayPousse that contains [only] a main() method to launch the program.

    main() should create an instance Pousse, an instance of PousseFrame, and fire up the GUI.

    Allow the user to supply a command-line argument to specify the size of the board. If the user does not supply an argument, then the board size should default to 4.

You do not have to write any other classes to implement this assignment. However, you may write helper classes if you think they make your design more open to changes in the future.

What sort of changes might we want to make in the future? One comes immediately to mind (I'm an old AI researcher): We may want to replace one of the human players with a computer player. Are there others you can think of?



Deliverables

By the due date and time, submit a zipped directory named homework08.zip containing:

For your hardcopy, submit only your PlayPousse.java file.

Be sure that your submission follows all homework submission requirements. (Yes, this includes submitting hardcopy!)



Eugene Wallingford ..... wallingf@cs.uni.edu ..... October 26, 2012