Giter Site home page Giter Site logo

benpollarduk / bp.adventureframework Goto Github PK

View Code? Open in Web Editor NEW
51.0 2.0 3.0 3.32 MB

A C# library that provides a framework for building text adventures and interactive stories in .NET.

License: MIT License

C# 100.00%
adventure framework text csharp game engine game-engine interactive interactive-story story

bp.adventureframework's Introduction

BP.AdventureFramework

A C# library that provides a framework for building text adventures and interactive stories in .NET.

main-ci codecov Quality Gate Status Maintainability Rating Security Rating Vulnerabilities Bugs GitHub release License Documentation Status

Overview

BP.AdventureFramework is a .NET Standard 2.0 implementation of a framework for building text based adventures.

BP AdventureFrameworkDemo_example

At its core BP.AdventureFramework provides simple classes for developing game elements:

Environments

Environments are broken down in to three elements - Overworld, Region and Room. An Overworld contains one or more Regions. A Region contains one or more Rooms. A Room can contain up to six exits (north, south, east, west, up and down).

Overworld
├── Region
│   ├── Room
│   ├── Room
│   ├── Room
├── Region
│   ├── Room
│   ├── Room

Exits

Rooms contain exits. Exits can be locked to block progress through the game.

// create a test room
var room = new Room("Test Room", "A test room.");
        
// add an exit to the north
room.AddExit(new Exit(Direction.North));

Items

Items add richness the game. Items support interaction with the player, rooms, other items and NPC's. Items can morph in to other items. For example, using item A on item B may cause item B to morph into item C.

var sword = new Item("Sword", "The heroes sword.");

Playable Character

Each BP.AdventureFramework game has a single playable character. The game is played through the view point of the playable character.

var player = new PlayableChracter("Dave", "The hero of the story.");

Non-playable Characters

Non-playable characters (NPC's) can be added to rooms and can help drive the narrative. NPC's can hold conversations, contains items, and interact with items.

var npc = new NonPlayableChracter("Gary", "The antagonist of the story.");

Commands

BP.AdventureFramework provides commands for interacting with game elements:

  • Drop X - drop an item.
  • Examine X - allows items, characters and environments to be examined.
  • Take X - take an item.
  • Talk to X - talk to a NPC, where X is the NPC.
  • Use X on Y - use an item. Items can be used on a variety of targets. Where X is the item and Y is the target.
  • N, S, E, W, U, D - traverse through the rooms in a region.

BP.AdventureFramework also provides global commands to help with game flow and option management:

  • About - display version information.
  • CommandsOn / CommandsOff - toggle commands on/off.
  • Exit - exit the game.
  • Help - display the help screen.
  • KeyOn / KeyOff - turn the Key on/off.
  • Map - display the map.
  • New - start a new game.

Custom commands can be added to games without the need to extend the existing interpretation.

Interpretation

BP.AdventureFramework provides classes for handling interpretation of input. Interpretation is extensible with the ability for custom interpreters to be added outside of the core BP.AdventureFramework library.

Conversations

Conversations can be held between the player and a NPC. Conversations support multiple lines of dialogue and responses.

image

Attributes

All game assets support customisable attributes. This provides the possibility to build systems within a game, for example adding currency and trading, adding HP to enemies, MP to your character, durability to Items etc.

Rendering

BP.AdventureFramework provides frames for rendering the various game screens. These are fully extensible and customisable. These include:

  • Scene frame.
  • Help frame.
  • Map frame.
  • Title frame.
  • Completion frame.
  • Game over frame.
  • Transition frame.
  • Conversation frame.

Maps

Maps are automatically generated for regions and rooms, and can be viewed with the map command:

image

Maps display visited rooms, exits, player position, if an item is in a room, lower floors and more.

Prerequisites

Getting Started

Clone the repo

Clone the repo to the local machine.

git clone https://github.com/benpollarduk/adventure-framework.git

Hello World

// create the player. this is the character the user plays as
var player = new PlayableCharacter("Dave", "A young boy on a quest to find the meaning of life.");

/// create region maker. the region maker simplifies creating in game regions. a region contains a series of rooms
var regionMaker = new RegionMaker("Mountain", "An imposing volcano just East of town.")
{
    // add a room to the region at position x 0, y 0, z 0
    [0, 0, 0] = new Room("Cavern", "A dark cavern set in to the base of the mountain.")
};

// create overworld maker. the overworld maker simplifies creating in game overworlds. an overworld contains a series or regions
var overworldMaker = new OverworldMaker("Daves World", "An ancient kingdom.", regionMaker);

// create the callback for generating new instances of the game
// - the title of the game
// - an introduction to the game, displayed at the start
// - about the game, displayed on the about screen
// - a callback that provides a new instance of the games overworld
// - a callback that provides a new instance of the player
// - a callback that determines if the game is complete, checked every cycle of the game
// - a callback that determines if it's game over, checked every cycle of the game
var gameCreator = Game.Create(
    "The Life Of Dave",
    "Dave awakes to find himself in a cavern...",
    "A very low budget adventure.",
    overworldMaker.Make,
    () => player,
    _ => EndCheckResult.NotEnded,
    _ => EndCheckResult.NotEnded);

// begin the execution of the game
Game.Execute(gameCreator);

Tutorial

The quickest way to start getting to grips with BP.AdventureFramework is to take a look at the Getting Started page.

Example game

An example game is provided in the BP.AdventureFramework.Examples directory and have been designed with the aim of showcasing the various features.

Running the examples

The example applications can be used to execute the example BP.AdventureFramework game and demonstrate the core principals of the framework. Set the BP.AdventureFramweork.Examples project as the start up project and build and run to start the application.

Documentation

Please visit https://benpollarduk.github.io/BP.AdventureFramework-docs/ to view the BP.AdventureFramework documentation.

For Open Questions

Visit https://github.com/benpollarduk/BP.AdventureFramework/issues

bp.adventureframework's People

Contributors

benpollarduk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bp.adventureframework's Issues

Text parser needs refactoring

Lots of unneeded methods.
Class too long.
Too complex parsing methods need to be broken down.
Magic numbers.
Constants needed.
Unit tests needed.

Emoji/ extended Unicode support.

Most terminals support Emoji characters. Emoji is a great way to have graphics in text games.
🪦 gravestone
🪧 sign
⛏️ pickaxe
⚔️ sword
🏰 castle
🏹 bow
🐉 dragon
🧙 wizard

Wikipedia Unicode blocks

Background

On Windows platforms cmd.exe has terrible text output support. However, the new Windows Terminal wt.exe has excellent support for formatting.

// Enable UTF8 output to support emoji (required to display the below emoji correctly)
Console.OutputEncoding = Encoding.UTF8;

// Displays a smiley emoji 😀
Console.Write("\U0001F600");

Markup

Having a string extension to convert human readable markup to emoji. Could be a good feature.

// dagger🗡️
Console.WriteLine(":dagger:".Markup());

Game over condition needs to be added

Currently the game ends when the player is no longer alive. This happens in Game.Execute. This needs to be changed - the player dying is only one of many possible game over conditions - dying should be just one such condition.

Persistence and Serialization

It would be great to have two types of persistence:

Creation

Save the state Game after creation (Unmodified Overworld). We could do something like:

var creator = Game.Load("MyCustomGame");
Game.Execute(creator);

Save Game

Create a save or load ICommand that allows users to manually create/restore snapshot of the game. Could even have an Item in a safe room that the user interacts that allows saving.

Getting Started Doc shows wrong lamda

What did you do?
Followed along with a great tutorial.

What happened?
When I reached the section Creating The Game, the line x => overworldMaker.Make() generates the following error: CS1593 Delegate 'OverworldCreationCallback' does not take 1 arguments.

What did you expect to happen?
For there to not be an error.

Additional details
When viewing the page directly in Firefox or Edge (unsure of other browsers), that line of code is displayed. When I looked at the source code, it's nowhere to be found. The example given in the ReadMe uses () => overworldMaker.Make();. Using this instead, the error clears.

Add collectibles

Is your feature request related to a problem? Please describe.
Currently there is no way to collect multiples of simple items, for example currency. This makes implementing things like buying and selling items difficult.
Describe the solution you'd like
A simple way to add collectibles to all characters.
Describe alternatives you've considered
There is a difference between normal items and collectibles, I considered all items collectibles but it doesn't fit as most items should be singular.

Simplify templates

Templates for PlayableCharacter, Item, NonPlayableCharacter etc are uninutaive and overly complex. They can simplified in line with the equivalent templates in Ktaf.

See ItemTemplate.kt for Ktaf functional equivalent of Item template.cs

Ansi Color support

Instead of RenderColor enum, create a custom type that can support foreground and background colors.
See Ansi Colors for color examples. Colors can be embedded directly into strings.

Console.WriteLine("\x1b[38;5;10mWelcome to Game\x1b[0m v0.1");

🤔 Having a string extension to convert human readable markup to ansi codes. Could be a good feature.

Console.WriteLine("[style:header]Welcome to Game[style:default] v0.1".Markup());

Refactor game class to make it more testable

The Game class as a whole, especially the execute loop, is hard to test and has poor coverage. Refactor the class, particularly the loop to have higher coverage and less complexity. Aiming for >80%.

Item Shop

Add the ability to buy items from a shop or NPC

Localization

It would be great to have localization support for multiple languages. Hardcoded strings would use some lut (look up table) to get the correct locale string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.