Roguelike Iterative Test-Driven Development in Java, Part 3

From RogueBasin
Revision as of 14:25, 11 August 2012 by Qbradq (talk | contribs)
Jump to navigation Jump to search

In this part we finally get to write some code! This part corresponds to HWR15 Part 3. In a traditional waterfall development pattern this is the easiest part to implement because it's the most basic. It's also the time during which you have the most opportunity to make a design mistake that will cause you grief later on.

Requirements

  1. Screen Output
  2. Keyboard Input
  3. Main Menu
  4. Game Mode
    1. Message Display
    2. Test Character Display
    3. Movement Keys

Personally I like to start with a main menu. It seems like when I design a game starting with the game mode it's harder to add a menu later.

Design

The main menu and game modes are part of our view layer, or the user-facing interface. Our view layer has no functional requirements, only aesthetic requirements: does it look good, is it intuitive, is all pertinent information displayed, etc. Aesthetic requirements are tested in the acceptance testing phase by the customer who, in this case, will be me. We'll use an abstract base class to provide common functionality.

Screen output has already been abstracted for us by libjcsi. Unfortunately so has keyboard input, and it's part of the same abstraction layer. We need to provide an abstraction of user input that is not directly tied to the keyboard so we can support key bindings and macros later on. We also need to expose the raw input for special situations, like naming a character or selecting items by letter. We won't be doing unit tests that are driven by input (because we're not unit testing the game modes) so we won't need a testing layer for this.

Surprisingly enough this leaves us with nothing to unit test.

So here's what our class diagram looks like:

  • net.slashie.libjcsi.ConsoleSystemInterface - Console system interface provided by libjcsi
    • com.qbradq.durok.lib.ConsoleSystem - Base class wrapping our screen output and keyboard input services
      • com.qbradq.durok.impl.test.TestConsoleSystem - Stub implementation of console services for testing
      • com.qbradq.durok.impl.JCursesConsoleSystem - Implementation based on JCurses
      • com.qbradq.durok.impl.WSwingConsoleSystem - Implementation based on WSwing
      • com.qbradq.durok.impl.ConsoleSystemFactory - Factory provider for ConsoleSystem implementations
  • com.qbradq.durok.lib.InputProviderInterface - Interface for the input service provider
    • com.qbradq.durok.impl.test.TestInputProvider - Implementation specializing in providing pre-defined test input streams
    • com.qbradq.durok.impl.InteractiveInputProvider - Implementation that converts interactive user input into input streams
  • com.qbradq.durok.game.GameModeInterface - Interface for anything that enters an input consumption loop
    • com.qbradq.durok.game.GameModeBase - Base implementation of a game mode providing sane default behavior
      • com.qbradq.durok.game.MainMenuMode - The main menu
      • com.qbradq.durok.game.GameMode - The main game interface

Tests