Introduction to OOP: Chapter 11: Replacement and Refinement
[next]
[previous]
[audio]
[real]
[text]
Refinement in C++
// place a single card into a card pile
void CardPile::addCard(Card * aCard)
{
if (aCard != nilcard) {
aCard->setLink(top);
top = aCard;
top->moveTo(x, y);
}
}
// place a single card into a table pile
void TablePile::addCard(Card * aCard)
{ int tx, ty;
// pile is empty, just place it normally
if (top == nilcard)
CardPile::addCard(aCard);
else { // display it below other cards
tx = top->locx();
ty = top->locy();
// figure out where to place card
if (top->faceUp() && top->next() != nilcard &&
(top->next())->faceUp())
; // do nothing
else
ty += 30; // move down a bit
CardPile::addCard(aCard);
top->moveTo(tx, ty);
}
}
Intro OOP, Chapter 11, Slide 17