Business Programming

Course announcements for INFS1609 and INFS2609

Business Programming random header image

Lab Week 12 – Uno Game

Posted by on October 7th, 2012 · Labs

Download the Uno Game BlueJ project shown in the lecture.

Constructors

Use the debugger to watch how cards are constructed:

  1. Set a breakpoint in the WildDrawCard constructor (line 17).
  2. Create a new WildDrawCard by calling the constructor..
  3. Use the ‘step into’ button to step through the code. Observe how the super() call works.
  4. Repeat this process for the other kinds of cards.

Set up a game:

  1. Call Game.makeStandardDeck() to create a deck (ArrayList) of cards.
  2. Press the Get button to save this deck in a variable.
  3. Call the Game constructor, providing this deck as a parameter.
  4. Call the deal() method on the game you created to deal the cards.

Inheriting methods

  1. Create a selection of cards from the different card classes.
  2. Right-click on each card to observe the methods it implements and the methods it inherits.
  3. Where is the canPlay() method implemented on each card type?
  4. Where is the play() method implemented on each card type?
  5. Set a breakpoint in WildDrawCard.play() (line 26).
  6. Create a WildDrawCard and call its play() method. Use the debugger to step through the code.
  7. Observe the order the code is executed.

Add a new card type

  1. Change the rule for the NumberCard so it can only be played on another NumberCard of value one more or one less that itself. (i.e. a 5 can be only played on a 4 or 6). Numbers should wrap around, so a 0 can be played on a 9 and vice-versa.
  2. Create a Transfer card class which transfers 2 random cards from the player to the previous player.
  3. Add a new Reverse-Draw card class which reverses the direction of play thencauses the next player to draw. Does it have any code in common with other cards? What class would it be best to inherit from?
  4. Create your own card types.

 

No Comments so far ↓

Comments are closed.