Skip to content

hils124/abandoned-text-game

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abandoned

A text-based mystery game

Players find themselves trapped in a house and have to collect and use items in order to find a way out.

Hilary Schulz


![](https://github.com/cpe305/fall2016-project-hils124/blob/master/Docs/AbandonedGamePlay2.png?raw=true)
## Setup

Clone source code to your machine on your terminal.
  Run:
    mvn clean install
  To Play Game:
    mvn exec:java


## How to Play This game is a terminal application and is completely text-based. Players move around, inspect objects and collect items by typing commands into the terminal.

Player Commands

  • describe wall
  • enter [PORTAL]
  • inspect [ELEMENT]
  • save
  • take [ITEM]
  • turn [LEFT, RIGHT, AROUND]
  • use [ITEM]
  • view inventory
  • quit
![](https://raw.githubusercontent.com/cpe305/fall2016-project-hils124/master/Docs/AbandonedGamePlay1.png)

Design Layout

Floor Plan

Software Architecture

Presentation Layer

User interaction with the terminal. Users type commands directly in the command prompt and visually see the narration of the game.

Business Logic Layer

Handles business logic of the application. Includes item actions and player commands

  • EntityUseType.java
  • CommandProcessor.java

Data Layer

Handles saving and loading of the game into files.

Related Classes:
  • GameSaver.java
  • GameLoader.java
Files:
  • HouseData.json
  • saveHouse.json
  • savePlayer.json

Source Code Documentation

abandoned.house

Package that stores all the classes that form the house:

  • Rooms
  • Walls
  • Portals
  • Containers

Class Diagram

abandoned.game

Package that stores all the game logic and the initial creation of the house itself.

JSON Serialization

The house is built from a JSON file called HouseData.json which holds all the data for each room in the house. HouseBuilder.java reads this file in and serializes the information into a java object which it then returns.

House house = mapper.readValue(new File("resources/HouseData.json"), House.class);

abandoned.entities

Package that stores items and specific actions for each one.

Item Actions

Item actions are handled with Java enums found in EntityUseType.java. Each item has a parameter useType which holds an enum to indicate the item's action.

  • keys -> new KeyAction()
  • scissors -> new ScissorsAction()

Each action class has a use() method that is specific to that item. This method is called by item's use() method.

abandoned.commands

Package that stores player commands and their specific actions

Command Pattern

Player actions are handled with the Command Pattern. There is a Command interface and multiple Command classes (such as SaveCommand, EnterCommand, etc...) that implement this interface.

Invoker.java sets the current Command action to be run. The function for each specific command is located in CommandProcessor.java


Design Patterns

Singleton Pattern

Creates one instance of a house and a player.

  • GlobalHouse.java
  • GlobalPlayer.java

Benefits:

  • All files able to access the current house and player
  • Avoids conflicting requests for the same resource

Command Pattern

Allows the requester of a particular command to be decoupled from the object that performs the command

Related Classes:

  • Invoker.java
  • Command.java
  • CommandProcessor.java
```java Initialize.cmdProcess.setProcess(name); switch (command) { case "describe": { Initialize.invoker.executeCommand(Initialize.describeCmd); break; } case "enter": { Initialize.invoker.executeCommand(Initialize.enterCmd); break; } } ```

Class Diagram

Benefits:

  • Extensibility - can add new commands without changing existing code
  • Puts all commands in one location

Favorite Parts of Project

  • Item Actions
  • Command Pattern with Player Actions
  • JSON Serialization

Key Takeaways

  • Outlining/structuring project before implementation
  • Importance of testing as you go
  • Design patterns can be very effective when used appropriately

About

fall2016-project-hils124 created by GitHub Classroom

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Java 100.0%