A1.x: Narcotic
George Heineman ( heineman@cs.wpi.edu
)
Version: 1.2
2-08-2008
1. A1.Analysis
This is the analysis document for the Narcotic solitaire variation. The entity, boundary, and control objects share the following relationship as shown below:
Entity Boundary Controller
After working on this analysis document, I realized that I had incorrectly programmed the
Narcotic plug-in. It worked, for sure, but I had “cut corners” that I didn’t realize until I sat down to develop this analysis document. Please take this lesson to heart: Any objectoriented program can be improved through careful analysis
1.1. Entity Objects
These objects will represent the “state” of the solitaire game. Note that for the purposes of KombatSolitaire , every solitaire variation must define a “score” and a “number of cards left”.
Deck deck
Pile pile1
Pile pile2
Pile pile3
Pile pile4
MutableInteger score
MutableInteger numLeft
1.2. Boundary Objects
Boundary objects are the visible presence of the Entity objects. Players of the game seemingly interact with these entities by pressing, clicking and dragging.
DeckView deckView
PileView pileView1
PileView pileView2
PileView pileView3
PileView pileView4
IntegerView scoreView
IntegerView numLeftView
Each Boundary View widget can be associated with a MouseAdapter (handles PRESS,
RELEASE, CLICK), MouseMotionAdapter (handles MOVE, DRAG), UndoAdapter
(handles UNDO). Note that the DRAG controllers are provided for you free of charge , but you will still need to construct them properly.
1.3. Controller Objects
We use controllers to map the mouse interaction into moves recognized by the Narcotic solitaire variation, as shown in the following table:
Deal
Move
Reset
Mouse Mapping
Mouse Press on DeckView
Mouse Press on PileView , followed by Mouse Release on a second PileView
Mouse press on DeckView
RemoveAll Double Click on the left-most pile
1.3.1. NarcoticDeckController Class
This class is responsible for processing a deal move (if the deck is not empty) and the reset move (when deck is empty).
NarcoticDeckController extends MouseAdapter
NarcoticDeckController (Narcotic theGame) void mousePressed (MouseEvent me)
# Narcotic narcoticGame
The mousePressed() method is responsible for controlling the entities as stored within the Narcotic solitaire plugIn.
1.3.2. NarcoticPileController Class
This class is responsible for processing requests to move cards between Piles (PRESS on source PileView and RELEASE on target PileView), removeAll Cards (double click on the leftmost Pile)
NarcoticPileController extends MouseAdapter
NarcoticPileController (Narcotic theGame) void mousePressed (MouseEvent me) void mouseClicked (MouseEvent me) void mouseReleased (MouseEvent me)
# Narcotic narcoticGame; // point to game
# PileView source; // which PileView (if any) to match with RELEASE
The mouseClicked(), mousePressed, mouseReleased methods are responsible for controlling the entities as stored within the Narcotic solitaire plugIn.
1.3.3. SolitaireMouseMotionAdapter Class
This class is responsible for processing any DRAG request and is provided as is. During design, you will learn how to interact with the container so drag will work properly.
SolitaireMouseMotionAdapter extends MouseMotionAdapter
SolitaireMouseMotionAdapter (Solitaire theGame) void mouseDragged (MouseEvent me)
# Solitaire theGame; // point to game
If you are curious as to how this method operates, look at the Solitaire source code.
1.3.4. SolitaireUndoAdapter Class
This class is responsible for processing any right click events as Undo requests. This class is provided for you as is. During design you will learn its interface and how to interact with it. For now (in Analysis) we will not discuss Undo further.
SolitaireUndoAdapter extends UndoAdapter
SolitaireUndoAdapter (Solitaire theGame) void undoRequested ()
# Solitaire theGame; // point to game
1.4. Game Object
In class we have mentioned the elusive “super object” the one that is the brains of the solitaire plug in. This special class must extend the Solitaire class, and we will add specific methods to correspond with the moves as identified in A1.Model.
NarcoticGame extends Solitaire void initialize () boolean dealFour (Deck d) boolean moveCard (Card c, Pile fromPile, Pile toPile) boolean removeAll (Card removed[]) boolean resetDeck (Deck d)
# boolean toLeftOf (Pile p1, Pile p2) // is p1 left of p2
# Deck deck
# Pile pile1, pile2, pile3, pile4
# DeckView deckView
# PileView pileView1, pileView2, pileView3, pileView4
# IntegerView numLeftView, scoreView
# PileView fromPileView
Each of the methods above ( dealFour , moveCard , removeAll , resetDeck ) will be based on the A1.Model moves. Each move returns true if the move can proceed. removeAll has extra information that is returned in the Card removed[] array: removed[1] is the card removed from Pile1, removed[2] is the card removed from Pile2, etc.
You must include full definitions (as used in A1.Model) of the moves within this section.
If you made some slight mistakes on A1.Model, here is your chance to get them right.
2. Summary
For this solitaire plug-in, we need the following control objects.
NarcoticDeckController deckController
NarcoticPileController pileController
SolitaireMouseMotionAdapter standardDragController
SolitaireUndoAdapter standardUndoController
The associations will be as follows:
{deckView, pileView1, pileView2, pileView3, pileView4}
standardUndoController
{scoreView, numLeftView}
standardUndoController
{deckView, pileView1, pileView2, pileView3, pileView4}
standardDragController
{scoreView, numLeftView} standardDragController
{pileView1, pileView2, pileView3, pileView4}
pileController
{deckView}
deckController