diff --git a/BP.AdventureFramework.Examples/Assets/Player/Player.cs b/BP.AdventureFramework.Examples/Assets/Player/Player.cs index 7d879fa8..71f7ded7 100644 --- a/BP.AdventureFramework.Examples/Assets/Player/Player.cs +++ b/BP.AdventureFramework.Examples/Assets/Player/Player.cs @@ -26,7 +26,7 @@ public PlayableCharacter Instantiate() { var player = new PlayableCharacter(Name, Description, new Knife().Instantiate()) { - Interaction = (i, _) => + Interaction = i => { if (i == null) return new InteractionResult(InteractionEffect.NoEffect, null); diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Items/ConchShell.cs b/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Items/ConchShell.cs index 3ce44552..5b3a9a3f 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Items/ConchShell.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Items/ConchShell.cs @@ -24,7 +24,7 @@ public Item Instantiate() { var conchShell = new Item(Name, Description, true) { - Interaction = (item, _) => + Interaction = item => { switch (item.Identifier.IdentifiableName) { diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs b/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs index ee4160ba..98ced8ea 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs @@ -26,18 +26,18 @@ public Room Instantiate() { var room = new Room(Name, string.Empty, new Exit(Direction.West), new Exit(Direction.North, true)); - InteractionCallback innerCaveInteraction = (i, _) => + InteractionCallback innerCaveInteraction = item => { - if (i != null && ConchShell.Name.EqualsExaminable(i)) + if (item != null && ConchShell.Name.EqualsExaminable(item)) { room[Direction.North].Unlock(); - return new InteractionResult(InteractionEffect.ItemUsedUp, i, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); + return new InteractionResult(InteractionEffect.ItemUsedUp, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); } - if (i != null && Knife.Name.EqualsExaminable(i)) - return new InteractionResult(InteractionEffect.NoEffect, i, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); + if (item != null && Knife.Name.EqualsExaminable(item)) + return new InteractionResult(InteractionEffect.NoEffect, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); }; room.Interaction = innerCaveInteraction; diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Flat.cs b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Flat.cs index fa460998..699ec075 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Flat.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Flat.cs @@ -35,40 +35,33 @@ public Region Instantiate() "Your in a large sitting room. Theres a huge map hanging on the eastern wall. On the southern wall there is a canvas. Theres a large coffee table in the center of the room. Beth is sat on a green sofa watching the TV. The kitchen is to the north.", () => roof.ContainsItem(Lead.Name)); - spareBedroom.Interaction = (i, target) => + spareBedroom.Interaction = item => { - var obj = target as Room; + if (Lead.Name.EqualsIdentifier(item.Identifier)) + { + spareBedroom.AddItem(new Item(item.Identifier, item.Description, true)); + return new InteractionResult(InteractionEffect.ItemUsedUp, item, "The lead fits snugly into the input socket on the amp."); + } - if (obj != null) + if (Guitar.Name.EqualsIdentifier(item.Identifier)) { - if (Lead.Name.EqualsIdentifier(i.Identifier)) + if (spareBedroom.ContainsItem(Lead.Name)) { - obj.AddItem(new Item(i.Identifier, i.Description, true)); - return new InteractionResult(InteractionEffect.ItemUsedUp, i, "The lead fits snugly into the input socket on the amp."); - } + easternHallway[Direction.East].Unlock(); - if (Guitar.Name.EqualsIdentifier(i.Identifier)) - { - if (obj.ContainsItem(Lead.Name)) + if (lounge.FindCharacter(Beth.Name, out var b)) { - easternHallway[Direction.East].Unlock(); - - if (lounge.FindCharacter(Beth.Name, out var b)) - { - lounge.RemoveCharacter(b); - return new InteractionResult(InteractionEffect.NoEffect, i, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar."); - } - - return new InteractionResult(InteractionEffect.NoEffect, i, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); + lounge.RemoveCharacter(b); + return new InteractionResult(InteractionEffect.NoEffect, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar."); } - return new InteractionResult(InteractionEffect.NoEffect, i, "You have no lead so you can't use the guitar with the amp..."); + return new InteractionResult(InteractionEffect.NoEffect, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); } - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item, "You have no lead so you can't use the guitar with the amp..."); } - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); }; var regionMaker = new RegionMaker(Name, Description) diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/EmptyCoffeeMug.cs b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/EmptyCoffeeMug.cs index aa5f58d1..e221c4ab 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/EmptyCoffeeMug.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/EmptyCoffeeMug.cs @@ -24,16 +24,15 @@ public Item Instantiate() { return new Item(Name, Description, true) { - Interaction = (i, target) => + Interaction = item => { - if (Kettle.Name.EqualsIdentifier(i.Identifier)) + if (Kettle.Name.EqualsIdentifier(item.Identifier)) { - var item = target as Item; item?.Morph(new MugOfCoffee().Instantiate()); - return new InteractionResult(InteractionEffect.ItemMorphed, i, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); + return new InteractionResult(InteractionEffect.ItemMorphed, item, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); } - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); } }; } diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/Kettle.cs b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/Kettle.cs index eac851e6..524aa498 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/Kettle.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Items/Kettle.cs @@ -24,20 +24,18 @@ public Item Instantiate() { return new Item(Name, Description) { - Interaction = (i, target) => + Interaction = item => { - var obj = target as Item; - - if (obj != null) + if (item != null) { - if (EmptyCoffeeMug.Name.EqualsIdentifier(i.Identifier)) + if (EmptyCoffeeMug.Name.EqualsIdentifier(item.Identifier)) { - i.Morph(new MugOfCoffee().Instantiate()); - return new InteractionResult(InteractionEffect.ItemMorphed, i, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); + item.Morph(new MugOfCoffee().Instantiate()); + return new InteractionResult(InteractionEffect.ItemMorphed, item, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); } } - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); } }; } diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs index 5eda957d..6b50f231 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs @@ -28,17 +28,12 @@ public Room Instantiate() room.AddItem(new HamsterCage().Instantiate()); room.AddItem(new Kettle().Instantiate()); - room.Interaction = (i, target) => + room.Interaction = (item) => { - var obj = target as Room; + if (Guitar.Name.EqualsIdentifier(item.Identifier)) + return new InteractionResult(InteractionEffect.NoEffect, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); - if (obj != null) - { - if (Guitar.Name.EqualsIdentifier(i.Identifier)) - return new InteractionResult(InteractionEffect.NoEffect, i, "Playing guitar in the kitchen is pretty stupid don't you think?"); - } - - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); }; return room; diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Lounge.cs b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Lounge.cs index 1b2431ff..f1fbb5ca 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Lounge.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Lounge.cs @@ -32,35 +32,31 @@ public Room Instantiate() room.AddItem(new LoungeTV().Instantiate()); room.AddItem(new Lead().Instantiate()); - room.Interaction = (i, target) => + room.Interaction = item => { - var obj = target as Room; - - if (obj != null) + if (item != null) { - if (MugOfCoffee.Name.EqualsIdentifier(i.Identifier)) + if (MugOfCoffee.Name.EqualsIdentifier(item.Identifier)) { - if (obj.ContainsCharacter(Beth.Name)) - return new InteractionResult(InteractionEffect.ItemUsedUp, i, "Beth takes the cup of coffee and smiles. Brownie points to you!"); + if (room.ContainsCharacter(Beth.Name)) + return new InteractionResult(InteractionEffect.ItemUsedUp, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); - i.Morph(new EmptyCoffeeMug().Instantiate()); - return new InteractionResult(InteractionEffect.ItemMorphed, i, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious."); + item.Morph(new EmptyCoffeeMug().Instantiate()); + return new InteractionResult(InteractionEffect.ItemMorphed, item, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious."); } - if (EmptyCoffeeMug.Name.EqualsIdentifier(i.Identifier)) + if (EmptyCoffeeMug.Name.EqualsIdentifier(item.Identifier)) { - obj.AddItem(i); - return new InteractionResult(InteractionEffect.ItemUsedUp, i, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed."); + room.AddItem(item); + return new InteractionResult(InteractionEffect.ItemUsedUp, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed."); } - if (Guitar.Name.EqualsIdentifier(i.Identifier)) - return new InteractionResult(InteractionEffect.NoEffect, i, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in..."); - - return new InteractionResult(InteractionEffect.NoEffect, i); + if (Guitar.Name.EqualsIdentifier(item.Identifier)) + return new InteractionResult(InteractionEffect.NoEffect, item, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in..."); } - return new InteractionResult(InteractionEffect.NoEffect, i); + return new InteractionResult(InteractionEffect.NoEffect, item); }; return room; diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Items/Stump.cs b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Items/Stump.cs index 14109731..99d6a8c4 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Items/Stump.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Items/Stump.cs @@ -24,7 +24,7 @@ public Item Instantiate() { var stump = new Item(Name, Description); - stump.Interaction = (item, _) => + stump.Interaction = item => { if (Shield.Name.EqualsExaminable(item)) { diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs index 4aa71a1c..dafea4c6 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs @@ -26,7 +26,7 @@ public Room Instantiate() var room = new Room(Name, Description, new Exit(Direction.South), new Exit(Direction.North), new Exit(Direction.East, true)); var door = new TailDoor().Instantiate(); - door.Interaction = (item, _) => + door.Interaction = item => { if (TailKey.Name.EqualsExaminable(item)) { diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/Stream.cs b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/Stream.cs index eefb6592..0edc281a 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/Stream.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Rooms/Stream.cs @@ -31,7 +31,7 @@ public Room Instantiate() var bush = new Bush().Instantiate(); var rupee = new Rupee().Instantiate(); - bush.Interaction = (item, _) => + bush.Interaction = item => { if (Sword.Name.EqualsExaminable(item)) { diff --git a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Zelda.cs b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Zelda.cs index c19c12db..ae480fc7 100644 --- a/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Zelda.cs +++ b/BP.AdventureFramework.Examples/Assets/Regions/Zelda/Zelda.cs @@ -65,7 +65,7 @@ public Region Instantiate() new Paragraph("OK Link your annoying me now, I'm just going to ignore you.", 0) ); - saria.Interaction = (item, _) => + saria.Interaction = item => { saria.FindItem(TailKey.Name, out var key); diff --git a/BP.AdventureFramework.Tests/Assets/Characters/PlayableCharacter_Tests.cs b/BP.AdventureFramework.Tests/Assets/Characters/PlayableCharacter_Tests.cs index 3171ce20..6b0016e6 100644 --- a/BP.AdventureFramework.Tests/Assets/Characters/PlayableCharacter_Tests.cs +++ b/BP.AdventureFramework.Tests/Assets/Characters/PlayableCharacter_Tests.cs @@ -68,7 +68,7 @@ public void GivenUseItem_WhenFatalEffect_ThenIsAliveIsFalse() var item = new Item("Test", string.Empty); var pc = new PlayableCharacter(string.Empty, string.Empty) { - Interaction = (i, _) => + Interaction = i => { if (i == null) return new InteractionResult(InteractionEffect.NoEffect, null); @@ -80,7 +80,7 @@ public void GivenUseItem_WhenFatalEffect_ThenIsAliveIsFalse() } }; - var result = pc.UseItem(pc, item); + pc.UseItem(pc, item); Assert.IsFalse(pc.IsAlive); } diff --git a/BP.AdventureFramework.Tests/Assets/Item_Tests.cs b/BP.AdventureFramework.Tests/Assets/Item_Tests.cs index c48a6671..3005d054 100644 --- a/BP.AdventureFramework.Tests/Assets/Item_Tests.cs +++ b/BP.AdventureFramework.Tests/Assets/Item_Tests.cs @@ -8,12 +8,12 @@ namespace BP.AdventureFramework.Tests.Assets public class Item_Tests { [TestMethod] - public void Given2Items_WhenUse_ThenNoEffect() + public void Given2Items_WhenInteract_ThenNoEffect() { var item = new Item(string.Empty, string.Empty); var item2 = new Item(string.Empty, string.Empty); - var result = item.Use(item2); + var result = item.Interact(item2); Assert.AreEqual(InteractionEffect.NoEffect, result.Effect); } diff --git a/BP.AdventureFramework.Tests/Rendering/Frames/GridTextFrame_Tests.cs b/BP.AdventureFramework.Tests/Rendering/Frames/GridTextFrame_Tests.cs index 8045be7e..191d4de8 100644 --- a/BP.AdventureFramework.Tests/Rendering/Frames/GridTextFrame_Tests.cs +++ b/BP.AdventureFramework.Tests/Rendering/Frames/GridTextFrame_Tests.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using BP.AdventureFramework.Assets; +using BP.AdventureFramework.Assets.Interaction; using BP.AdventureFramework.Rendering.FrameBuilders; using BP.AdventureFramework.Rendering.FrameBuilders.Color; using BP.AdventureFramework.Rendering.Frames; diff --git a/BP.AdventureFramework/Assets/Characters/Character.cs b/BP.AdventureFramework/Assets/Characters/Character.cs index 1f04a579..99390304 100644 --- a/BP.AdventureFramework/Assets/Characters/Character.cs +++ b/BP.AdventureFramework/Assets/Characters/Character.cs @@ -20,7 +20,7 @@ public abstract class Character : ExaminableObject, IInteractWithItem /// /// Get or set the interaction. /// - public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i); + public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i); /// /// Get the items this Character holds. @@ -38,7 +38,7 @@ public abstract class Character : ExaminableObject, IInteractWithItem /// The result of the interaction. protected virtual InteractionResult InteractWithItem(Item item) { - return Interaction.Invoke(item, this); + return Interaction.Invoke(item); } /// diff --git a/BP.AdventureFramework/Assets/Interaction/InteractionCallback.cs b/BP.AdventureFramework/Assets/Interaction/InteractionCallback.cs index bf446100..cd979d8d 100644 --- a/BP.AdventureFramework/Assets/Interaction/InteractionCallback.cs +++ b/BP.AdventureFramework/Assets/Interaction/InteractionCallback.cs @@ -4,7 +4,6 @@ /// Represents the callback for interacting with objects. /// /// The item to interact with. - /// The target interaction element. /// The result of the interaction. - public delegate InteractionResult InteractionCallback(Item item, IInteractWithItem target); + public delegate InteractionResult InteractionCallback(Item item); } \ No newline at end of file diff --git a/BP.AdventureFramework/Assets/Item.cs b/BP.AdventureFramework/Assets/Item.cs index f8a65f9a..3e8072d3 100644 --- a/BP.AdventureFramework/Assets/Item.cs +++ b/BP.AdventureFramework/Assets/Item.cs @@ -17,7 +17,7 @@ public sealed class Item : ExaminableObject, IInteractWithItem /// /// Get or set the interaction. /// - public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i); + public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i); #endregion @@ -62,16 +62,6 @@ public void Morph(Item item) IsTakeable = item.IsTakeable; } - /// - /// Use this item on a target. - /// - /// The target to use the item on. - /// The result of the interaction. - public InteractionResult Use(IInteractWithItem target) - { - return target.Interact(this); - } - #endregion #region IInteractWithItem Members @@ -83,7 +73,7 @@ public InteractionResult Use(IInteractWithItem target) /// The result of the interaction. public InteractionResult Interact(Item item) { - return Interaction.Invoke(item, this); + return Interaction.Invoke(item); } #endregion diff --git a/BP.AdventureFramework/Assets/Locations/Room.cs b/BP.AdventureFramework/Assets/Locations/Room.cs index 42da7109..66ca7aae 100644 --- a/BP.AdventureFramework/Assets/Locations/Room.cs +++ b/BP.AdventureFramework/Assets/Locations/Room.cs @@ -43,7 +43,7 @@ public sealed class Room : ExaminableObject, IInteractWithItem /// /// Get or set the interaction. /// - public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i); + public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i); /// /// Get an exit. @@ -203,7 +203,7 @@ public bool CanMove(Direction direction) /// The result of the interaction. private InteractionResult InteractWithItem(Item item) { - return Interaction.Invoke(item, this); + return Interaction.Invoke(item); } /// diff --git a/BP.AdventureFramework/Logic/Game.cs b/BP.AdventureFramework/Logic/Game.cs index 1406b9d7..94e5453c 100644 --- a/BP.AdventureFramework/Logic/Game.cs +++ b/BP.AdventureFramework/Logic/Game.cs @@ -20,7 +20,7 @@ namespace BP.AdventureFramework.Logic /// /// Represents the structure of the game /// - public sealed class Game : IDisposable + public sealed class Game { #region Constants @@ -563,22 +563,21 @@ public static void Execute(GameCreationCallback creator) while (run) { - using (var game = creator.Invoke()) + var game = creator.Invoke(); + + SetupConsole(game); + AttachToConsole(game); + game.Execute(); + + switch (game.ExitMode) { - SetupConsole(game); - AttachToConsole(game); - game.Execute(); - - switch (game.ExitMode) - { - case ExitMode.ExitApplication: - run = false; - break; - case ExitMode.ReturnToTitleScreen: - break; - default: - throw new NotImplementedException(); - } + case ExitMode.ExitApplication: + run = false; + break; + case ExitMode.ReturnToTitleScreen: + break; + default: + throw new NotImplementedException(); } } } @@ -614,19 +613,5 @@ private static void SetupConsole(Game game) } #endregion - - #region Implementation of IDisposable - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Output?.Dispose(); - Input?.Dispose(); - Error?.Dispose(); - } - - #endregion } } \ No newline at end of file diff --git a/docs/docfx/docs/exit.md b/docs/docfx/docs/exit.md new file mode 100644 index 00000000..1e19ae96 --- /dev/null +++ b/docs/docfx/docs/exit.md @@ -0,0 +1,46 @@ +# Exit + +## Overview + +An Exit is essentially a connector bewtween to adjoining rooms. + +## Use + +An Exit can be simply instantiated with a direction. + +```csharp +var exit = new Exit(Direction.North); +``` + +An Exit can be hidden from the player by setting its **IsPlayerVisible** property to false, this can be set in the constructor: + +```csharp +var exit = new Exit(Direction.North, false); +``` + +Or set explicitly: + +```csharp +exit.IsPlayerVisible = false; +``` + +Optionally, a description of the Exit can be specified: + +```csharp +var exit = new Exit(Direction.North, true, new Description("A door covered in ivy.")); +``` + +This will be returned if the player examines the Exit. + +Like all Examinable objects, an Exit can be assigned custom commands: + +```csharp +exit.Commands = +[ + new CustomCommand(new CommandHelp("Shove", "Shove the door."), true, (game, args) => + { + exit.Unlock(); + return new Reaction(ReactionResult.OK, "The door swung open."); + }) +]; +``` \ No newline at end of file diff --git a/docs/docfx/docs/items.md b/docs/docfx/docs/items.md new file mode 100644 index 00000000..03c8f7d9 --- /dev/null +++ b/docs/docfx/docs/items.md @@ -0,0 +1,51 @@ +# Item + +## Overview + +Items can be used to add interactivity with a game. Items can be something that a player can take with them, or they may be static in a Room. + +## Use + +An Item can be simply instantiated with a name and description. + +```csharp +var exit = new Item("Sword", "A heroes sword."); +``` + +By default an Item is not takeable and is tied to a Room. If it is takeable this can be specified in the constructor: + +```csharp +var item = new Item("Sword", "A heroes sword.", true); +``` + +Like all Examinable objects, an Item can be assigned custom commands: + +```csharp +bomb.Commands = +[ + new CustomCommand(new CommandHelp("Cut wire", "Cut the red wire."), true, (game, args) => + { + game.Player.Kill(); + return new Reaction(ReactionResult.Fatal, "Boom!"); + }) +]; +``` + +## Interaction + +Interactions can be set up between different assets in the game. The **InteractionResult** contains the result of the interaction, and allows the game to react to the interaction. + +```csharp +var dartsBoard = new Item("Darts board", "A darts board."); + +var dart = new Item("Dart", "A dart") +{ + Interaction = item => + { + if (item == dartsBoard) + return new InteractionResult(InteractionEffect.SelfContained, item, "The dart stuck in the darts board."); + + return new InteractionResult(InteractionEffect.NoEffect, item); + } +}; +``` \ No newline at end of file diff --git a/docs/docfx/docs/overworld.md b/docs/docfx/docs/overworld.md new file mode 100644 index 00000000..5aaa3ff0 --- /dev/null +++ b/docs/docfx/docs/overworld.md @@ -0,0 +1,59 @@ +# Overworld + +## Overview + +An Overworld is the top level location in a game. A game can only contain a single Overworld. An Overworld can contain multiple Regions. + +``` +Overworld +├── Region +│ ├── Room +│ ├── Room +│ ├── Room +├── Region +│ ├── Room +│ ├── Room +``` + +## Use + +An Overworld can be simply instantiated with a name and description. + +```csharp +var overworld = new Overworld("Name", "Description."); +``` + +Regions can be added to the Overworld with the **AddRegion** method: + +```csharp +overworld.AddRegion(region); +``` + +Regions can be removed from an Overworld with the **RemoveRegion** method: + +```csharp +overworld.RemoveRegion(region); +``` + +The Overworld can be traversed with the **Move** method: + +```csharp +overworld.Move(region); +``` + +## OverworldMaker + +The OverworldMaker simplifies the creation of the Overworld, when used in conjunction with RegionMakers. + +```csharp +var overworldMaker = new OverworldMaker("Name", "Description.", regionMakers); +``` + +However, the main benefit of using an OverworldMaker is that it allows multiple instances of an Overworld to be created from a single definition of an Overworld. + +```csharp +var overworld = overworldMaker.Make();; +``` + + + diff --git a/docs/docfx/docs/region.md b/docs/docfx/docs/region.md new file mode 100644 index 00000000..89efd1a9 --- /dev/null +++ b/docs/docfx/docs/region.md @@ -0,0 +1,100 @@ +# Region + +## Overview + +A Region is the intermediate level location in a game. An Overworld can contain multiple Regions. A Region can contain multiple Rooms. + +``` +Overworld +├── Region +│ ├── Room +│ ├── Room +│ ├── Room +├── Region +│ ├── Room +│ ├── Room +``` + +A Region represents a 3D space. +* The **x** location always refers to the horizontal axis, with lower values being west and higher values being east. +* The **y** location always refers to the vertical axis, with lower values being north and higher values being south. +* The **z** location always refers to the depth axis, with lower values being down and higher values being up. + +## Use + +A Region can be simply instantiated with a name and description. + +```csharp +var region = new Region("Name", "Description."); +``` + +Rooms can be added to the Region with the **AddRoom** method. The x, y and z location within the Region must be specified: + +```csharp +region.AddRoom(room, 0, 0, 0); +``` + +Rooms can be removed from a Region with the **RemoveRoom** method: + +```csharp +region.RemoveRoom(room); +``` + +The Region can be traversed with the **Move** method: + +```csharp +region.Move(Direction.North); +``` + +The Region can be traversed with the **Move** method: + +```csharp +region.Move(Direction.North); +``` + +The start position, that is the position that the Player will start in when entering a Region, can be specified with **SetStartPosition**. + +```csharp +region.SetStartPosition(0, 0, 0); +``` + +The **UnlockDoorPair** method can be used to unlock an **Exit** in the current Room, which will also unlock the corresponding Exit in the adjoining **Room**. +```csharp +region.UnlockDoorPair(Direction.East); +``` + +Like all Examinable objects, Regions can be assigned custom commands: + +```csharp +region.Commands = +[ + new CustomCommand(new CommandHelp("Warp", "Warp to the start."), true, (game, args) => + { + region.JumpToRoom(0, 0, 0); + return new Reaction(ReactionResult.OK, "You warped to the start."); + }) +]; +``` + +## RegionMaker + +The RegionMaker simplifies the creation of a Region. Rooms are added to the Region with a specified **x**, **y** and **z** position within the Region. + +```csharp +var regionMaker = new RegionMaker("Region", "Description.") +{ + [0, 0, 0] = new Room("Room 1", "Description of room 1."), + [1, 0, 0] = new Room("Room 2", "Description of room 2."), +}; +``` + +The main benefit of using a RegionMaker is that it allows multiple instances of a Region to be created from a single definition of a Region. + +```csharp +var region = regionMaker.Make(); +``` + + + + + diff --git a/docs/docfx/docs/room.md b/docs/docfx/docs/room.md new file mode 100644 index 00000000..2dbcddab --- /dev/null +++ b/docs/docfx/docs/room.md @@ -0,0 +1,76 @@ +# Room + +## Overview + +A Room is the lowest level location in a game. A Region can contain multiple Rooms. + +``` +Overworld +├── Region +│ ├── Room +│ ├── Room +│ ├── Room +├── Region +│ ├── Room +│ ├── Room +``` + +A Room can contain up to six Exits, one for each of the directions **north**, **east**, **south**, **west**, **up** and **down**. + +## Use + +A Region can be simply instantiated with a name and description. + +```csharp +var room = new Room("Name", "Description."); +``` + +Exits can be added to the Room with the **AddExit** method: + +```csharp +room.AddExit(new Exit(Direction.East)); +``` + +Exits can be removed from a Room with the **RemoveExit** method: + +```csharp +region.RemoveExit(exit); +``` + +Items can be added to the Room with the **AddItem** method: + +```csharp +room.AddItem(new Item("Name", "Description.")); +``` + +Items can be removed from a Room with the **RemoveItem** method: + +```csharp +region.RemoveItem(item); +``` + +Characters can be added to the Room with the **AddCharacter** method: + +```csharp +room.AddCharacter(new Character("Name", "Description.")); +``` + +Characters can be removed from a Room with the **RemoveCharacter** method: + +```csharp +region.RemoveCharacter(character); +``` + +Rooms can contains custom commands that allow the user to directly interact with the Room: + +```csharp +room.Commands = +[ + new CustomCommand(new CommandHelp("Pull lever", "Pull the lever."), true, (game, args) => + { + room.FindExit(Direction.East, true, out var exit); + exit.Unlock(); + return new Reaction(ReactionResult.OK, "The exit was unlocked."); + }) +]; +```