Project 2b

Due Date: Tue 8 Nov

Group Project

Please see here.

Objectives

An understanding of
  • object-oriented modeling and design
  • SOLID and other design principles
  • basic design patterns and their implementation in C#
    • strategy
    • observer
    • decorator
    • singleton
    • iterator
  • graph representation and algorithms

Description

This project builds on your design work from the previous project, but your coding will be from scratch.

Locations

Your first job is to create an interface for locations. Locations are the basic units of the terrain where the game is played. They are responsible for having zero or more neighbors; this relationship allows an actor to move from this location to a neighbor (in this one direction only; there might or might not be a relationship for the opposite direction, but this is the neighbor's responsibility).

Start by creating an enumerated type to represent the directions for the six possible neighbors in three dimensions: the four cardinal directions as well as up and down.

Now create a location interface ILocation that maps zero or more directions to actual neighboring locations. There should be a mapping only when the corresponding neighbor is present. The interface should specify these capabilities:
  • add a neighbor at a certain direction
  • remove the neighbor at a certain direction (if it exists)
  • provide a list of neighbors
  • allow an actor to enter the location
  • allow an actor to leave the location
Finally, create a class Location that implements this interface. Reuse suitable building blocks from the .NET framework. This implementation should be able to 
  • have a unique string name
  • produce a string representation of the location in a standard way (ToString)
  • report whenever an actor enters or leaves by printing, e.g. "cell <cname> entered by actor <aname>"

Actors

Your next job is to create an interface IActor for actors that move around the terrain. For now, the actors have limited capabilities. They are able to explore the terrain, giving a starting location. 

Now create an abstract class Actor that keeps track of its name and current location.

Finally, create a class Player that inherits from Actor that is able to explore the terrain in different ways. For now, players only operate on autopilot as described below. (At a later stage of this project, we will also allow users to control players with input devices such as the keyboard.)

Carriable Items

Now your job is to create an interface ICarriable for carriable items. For now, this item does not need any specific capabilities.

Create an Marker class that implements ICarriable. Markers come in different colors (use System.Drawing.Color).

Location Enhancements

For good reasons discussed in class, additional capabilities of locations are provided not using inheritance but in the form of wrapper or plugin classes that enhance individual location instances as needed. For now, we will support two capabilities or characteristics:
  • holding zero or more objects (such as markers)
  • being exit locations (considered part of the perimeter of the terrain)
Your job is to design these enhancements in such a way that they allow actors to explore the terrain. This means that locations need to provide the actor with a way to find out what enhancements are present at a given location.

You should not use either of the following approaches to enhance the capabilities of a location:
  • inheritance
  • implementing the capabilities in the Location class itself

Terrain Exploration

A player is able to explore any terrain by dropping green markers in the locations they visit as they move through the terrain. When they get to a dead end, they back out and replace the green marker with a red one. The exploration ends when the player encounters an exit.

Main Program and Specific Terrain

Build a terrain you would not want to be trapped in:
  • at least 20 location cells
  • dead ends
  • one-way passages
  • one-way cycles
  • two or three exits
Then have your player explore the terrain on autopilot as described above until she/he finds an exit. Note that the locations will automatically report the movement of the player.

Output Part 1: Trip Recorder

Create a unique, globally accessible trip recorder instance that gets notified by any location whenever the player enters or leaves that location. Whenever the trip recorder receives notification, it prints output such as

    Player entered Banquet Hall.
    Player left Banquet Hall.
    Player entered Dungeon.
    Player left Dungeon.
    ...

Output Part 2: Terrain

Define a terrain printer that starts with a given location and prints the remainder of terrain reachable from this location as a tree.

    Great Entrance Hall: green marker
        North -> Banquet Hall: red marker
            Down -> Dungeon: red marker
        South -> Walled Garden: green marker
            Up -> Castle Hill: exit, green marker

Hint: the terrain printer might want to use its own, invisible markers so as not to get stuck in a circle.

Written Portion

In about 600-900 words (two to three pages), succinctly describe how you used each of the following design principles and patterns in your implementation and discuss to what extent the pattern simplified or complicated matters.
  • single responsibility principle
  • interface segregation principle
  • Decorator
  • Observer
  • Singleton
  • factoring out for future expansion (Coad, Design with interfaces, section 3.3.4)
In particular, discuss whether you used wrappers or plugins for providing enhanced capabilities to locations.

Have fun!!!

Nonfunctional Requirements

  • Try to adhere to these C# coding guidelines.
  • More importantly, continue to follow test-driven development (TDD) by creating automated unit tests for your various program components.
  • Reuse suitable .NET library components whenever possible instead of building your own.

Extra Credit

Give your player the option of exploring the entire terrain in addition to finding the first exit. Implement this choice using suitable design patterns to be discussed in class and in the discussion group.

Other extra credit ideas are welcome pending instructor approval.

Grading

Required part, total 20:
  • 0.5 Directions
  • 0.5 ILocation
  • 1 Location (Observable for entry/exit events for trip recorder)
  • 0.5 IActor
  • 0.5 Actor
  • 0.5 Player
  • 0.5 ICarryable
  • 0.5 Marker
  • 0.5 ItemContainer (Decorator or Plugin)
  • 0.5 ExitLocation (Decorator or Plugin)
  • 1 trip recorder (Singleton, Observer connected to Locations)
  • 2 sample terrain
  • 2 find first exit algorithm
  • 2 terrain printing algorithm
  • 2.5 testing
  • 2 code documentation (including inline and XML comments)
  • 3 written portion (0.5 for addressing each required pattern and principle)
Extra credit:
  • 2 Composite for terrain that is Observable to outside and Observer of all its Locations
  • 2 find all exits algorithm for player switchable by using Strategy pattern to represent the algorithms

Submission

Please submit your code and written portion following the usual online submission procedure.
Comments