Object-Oriented Programming with Java, Spring 2008

Programming Assignment 1a - An Example Solution


Table of Contents

Introduction
  • Player API
  • Eagle's-Wing Implementation
  • Example Client
  • Tests
  • Index macro, disabling it.
  • Introduction

    This page is an example solution for the first programming assisignment. This solution implements a back-end for Eagle's Wing, a one-deck solitaire card game.

    Player API

    The playerAPI package contains all the classes needed to write further code for playing Eagle's Wing games. A majority of the classes are interfaces or enums, but Eagle's Wing itself is an abstract class that uses a simple factory to create game instances.

    An Eagle's Wing Game

    The Eagle's Wing game interface is implemented as an abstract class to isolate the implementation parts from the interface parts (which was not completely successful).

    Card Piles

    A Card

    Eagle's Wing Status Values

    Eagle's-Wing Implementation

    The Eagle's Wing implementation is relatively straightforward, with most of the interesting details in the concrete class extending the EaglesWing abstract class in the playerAPI package. The implementation classes belong to the impl package.

    Eagle's-Wing Implementation

    movesPossible() Implementation

    movesPossible() should return true if there are moves possible in the current game configuration and false otherwise. Conceptually, implementing movesPossible() is simple: search through all possible moves looking for a legal move. Implementing movesPossible() is simple too, thanks to CardPiles.pairIterate(). The only real work that needs to be done is defining the method used in the pair iteration. A given pair of piles represents a possible move if the pair represents a legitimate move, the move is successful, and the move is non-trivial.
    <Eagle's Wing implementation tests>= (U→)
    
    void stockToWingTest() 
    

    Card-Pile Implementation

    Deck Implementation

    A deck is a specific card pile with the usual 52 cards; a deck is shuffled.

    Card Implementation

    Example Client

    This class is a quick and dirty example of an Eagle's Wing game implemented using the playerAPI. It uses the terminal and repeatedly prints the card piles and then prompts for a move.

    Tests

    Index


    This page last modified on 16 April 2008.

    Creative
    Commons License