We spent several lectures discussing the classic children's
matching game Memory. In the course of our discussions we
talked about:
- Modeling the domain
- We did an in-class exercise to pick out
objects from the game's domain.
- We also considered different objects' capabilities.
- Incremental development
- We demonstrated how incremental development works, by starting
to build functionality with one class only, and by
building its functionality one small step at a time, verifying
its actual behavior against our expectations at each step.
- We began with the
Card class.
- Code is in the lecture code repository.
- Swapping - cards in the memory game have two images, one on the
front and one on the back of the card. We saw how to "flip" a
card by swapping the face-up image with the face-down image
(something which we learned how to do in lab 4.
- State pattern - we explored how to encode the two states of the
card (selected (face-up) and deselected (face-down)), and the
four states of the game (no card selected, one card selected,
two cards selected, game over) using a state pattern.
- Primtives - this example has also served as a vehicle for
introducing primitive types (e.g. boolean for determining
whether two cards match, and int for keeping track of the number
of matches.
- Control structures - the one-branch if statement and two-branch
if-else statement were both discussed in the context of this
example.
- Additional topics to cover (in the context of the memory game):
- loops: while loops, for-each loops
- java.util.HashSet<Type> collection
- java.util.ArrayList<Type> collection