Skip to content

Commit

Permalink
Merge pull request #93 from benpollarduk/refactor-game-modes
Browse files Browse the repository at this point in the history
Added game modes
  • Loading branch information
benpollarduk authored Nov 14, 2024
2 parents 754f6bd + d10ae0b commit e224475
Show file tree
Hide file tree
Showing 98 changed files with 1,499 additions and 668 deletions.
8 changes: 3 additions & 5 deletions NetAF.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ private static void PopulateHub(Region hub, Overworld overworld, Region[] otherR
if (!move)
return new Reaction(ReactionResult.Error, $"Could not move to {otherRegion.Identifier.Name}.");

g.DisplayTransition(string.Empty, $"You peer inside the sphere and feel faint. When the sensation passes you open you eyes and have been transported to the {otherRegion.Identifier.Name}.");

return new Reaction(ReactionResult.Internal, string.Empty);
return new Reaction(ReactionResult.OK, $"You peer inside the sphere and feel faint. When the sensation passes you open you eyes and have been transported to the {otherRegion.Identifier.Name}.");
})
];

Expand Down Expand Up @@ -120,8 +118,8 @@ static Overworld overworldCreator()
}
catch (Exception e)
{
System.Console.WriteLine($"Exception caught running demo: {e.Message}");
System.Console.ReadKey();
Console.WriteLine($"Exception caught running demo: {e.Message}");
Console.ReadKey();
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions NetAF.Tests/Adapters/SystemConsoleAdapter_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using NetAF.Assets.Characters;
using NetAF.Assets.Locations;
using NetAF.Logic;
using NetAF.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Adapters;
using NetAF.Rendering.FrameBuilders.Console;

namespace NetAF.Tests.Logic
{
[TestClass]
public class SystemConsoleAdapter_Tests
{
[TestMethod]
public void GivenNoConsoleAccess_WhenRenderFrame_ThenIOExceptionThrown()
{
Assert.ThrowsException<IOException>(() =>
{
RegionMaker regionMaker = new(string.Empty, string.Empty);
Room room = new("Room", string.Empty);
regionMaker[0, 0, 0] = room;
OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker);
var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default);
var aboutFrame = new ConsoleAboutFrameBuilder(new NetAF.Rendering.FrameBuilders.GridStringBuilder()).Build("abc", game.Invoke(), 50, 50);
var adapter = new SystemConsoleAdapter();

adapter.RenderFrame(aboutFrame);
});
}
}
}
4 changes: 2 additions & 2 deletions NetAF.Tests/Assets/ExaminationRequest_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void GivenCreate_WhenGameSpecified_ThenExaminerSetFromPlayer()
var overworld = new Overworld(string.Empty, string.Empty);
region.AddRoom(room, 0, 0, 0);
overworld.AddRegion(region);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default);

var result = new ExaminationRequest(player, gameCreator());

Expand All @@ -34,7 +34,7 @@ public void GivenCreate_WhenGameSpecified_ThenRoomSetFromPlayer()
var overworld = new Overworld(string.Empty, string.Empty);
region.AddRoom(room, 0, 0, 0);
overworld.AddRegion(region);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default);

var result = new ExaminationRequest(player, gameCreator());

Expand Down
17 changes: 12 additions & 5 deletions NetAF.Tests/Commands/Conversation/Next_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using NetAF.Conversations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;
using NetAF.Logic.Modes;
using NetAF.Assets.Locations;
using NetAF.Utilities;

namespace NetAF.Tests.Commands.Conversation
{
Expand All @@ -23,7 +26,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenNoConverser_WhenInvoke_ThenError()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new Next();

var result = command.Invoke(game);
Expand All @@ -32,16 +35,20 @@ public void GivenNoConverser_WhenInvoke_ThenError()
}

[TestMethod]
public void GivenValidGameAndConverser_WhenInvoke_ThenInternal()
public void GivenValidGameAndConverser_WhenInvoke_ThenSilent()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
RegionMaker regionMaker = new(string.Empty, string.Empty);
Room room = new(string.Empty, string.Empty);
regionMaker[0, 0, 0] = room;
OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker);
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var converser = new NonPlayableCharacter(string.Empty, string.Empty, conversation: new(new Paragraph(string.Empty)));
game.StartConversation(converser);
game.ChangeMode(new ConversationMode(converser));
var command = new Next();

var result = command.Invoke(game);

Assert.AreEqual(ReactionResult.Internal, result.Result);
Assert.AreEqual(ReactionResult.Silent, result.Result);
}
}
}
20 changes: 14 additions & 6 deletions NetAF.Tests/Commands/Conversation/Respond_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using NetAF.Conversations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;
using NetAF.Logic.Modes;
using NetAF.Assets.Locations;
using NetAF.Utilities;

namespace NetAF.Tests.Commands.Conversation
{
Expand All @@ -23,7 +26,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenNullResponse_WhenInvoke_ThenError()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new Respond(null);

var result = command.Invoke(game);
Expand All @@ -34,7 +37,7 @@ public void GivenNullResponse_WhenInvoke_ThenError()
[TestMethod]
public void GivenNoConverser_WhenInvoke_ThenError()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var response = new Response("");
var command = new Respond(response);

Expand All @@ -44,19 +47,24 @@ public void GivenNoConverser_WhenInvoke_ThenError()
}

[TestMethod]
public void GivenValidGame_WhenInvoke_ThenInternal()
public void GivenValidGame_WhenInvoke_ThenSilent()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
RegionMaker regionMaker = new(string.Empty, string.Empty);
Room room = new(string.Empty, string.Empty);
regionMaker[0, 0, 0] = room;
OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker);
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var response = new Response("");
var paragraph = new Paragraph(string.Empty) { Responses = [response] };
var conversation = new NetAF.Conversations.Conversation(paragraph);
var converser = new NonPlayableCharacter(string.Empty, string.Empty, conversation: conversation);
game.StartConversation(converser);
converser.Conversation.Next(game);
game.ChangeMode(new ConversationMode(converser));
var command = new Respond(response);

var result = command.Invoke(game);

Assert.AreEqual(ReactionResult.Internal, result.Result);
Assert.AreEqual(ReactionResult.Silent, result.Result);
}
}
}
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new CommandsOff();

var result = command.Invoke(game);
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new CommandsOn();

var result = command.Invoke(game);
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Frame/KeyOff_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new KeyOff();

var result = command.Invoke(game);
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Frame/KeyOn_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new KeyOn();

var result = command.Invoke(game);
Expand Down
6 changes: 3 additions & 3 deletions NetAF.Tests/Commands/Global/About_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public void GivenNullGame_WhenInvoke_ThenError()
}

[TestMethod]
public void GivenValidGame_WhenInvoke_ThenInternal()
public void GivenValidGame_WhenInvoke_ThenSilent()
{
var overworld = new Overworld(Identifier.Empty, Description.Empty);
var region = new Region(Identifier.Empty, Description.Empty);
region.AddRoom(new Room(Identifier.Empty, Description.Empty, [new Exit(Direction.North)]), 0, 0, 0);
region.AddRoom(new Room(Identifier.Empty, Description.Empty, [new Exit(Direction.South)]), 0, 1, 0);
overworld.AddRegion(region);
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new About();

var result = command.Invoke(game);

Assert.AreEqual(ReactionResult.Internal, result.Result);
Assert.AreEqual(ReactionResult.Silent, result.Result);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Conversation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;
using NetAF.Commands.Global;
using NetAF.Assets.Locations;
using NetAF.Utilities;
using NetAF.Assets.Characters;

namespace NetAF.Tests.Commands.Conversation
namespace NetAF.Tests.Commands.Global
{
[TestClass]
public class End_Tests
Expand All @@ -21,7 +24,11 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, ConsoleGameConfiguration.Default).Invoke();
RegionMaker regionMaker = new(string.Empty, string.Empty);
Room room = new(string.Empty, string.Empty);
regionMaker[0, 0, 0] = room;
OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker);
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), null, TestGameConfiguration.Default).Invoke();
var command = new End();

var result = command.Invoke(game);
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Global/Exit_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, TestGameConfiguration.Default).Invoke();
var command = new Exit();

var result = command.Invoke(game);
Expand Down
8 changes: 5 additions & 3 deletions NetAF.Tests/Commands/Global/Help_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NetAF.Commands.Global;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;
using NetAF.Logic.Modes;

namespace NetAF.Tests.Commands.Global
{
Expand All @@ -22,7 +23,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
}

[TestMethod]
public void GivenValidGame_WhenInvoke_ThenInternal()
public void GivenValidGame_WhenInvoke_ThenSilent()
{
var room = new Room(Identifier.Empty, Description.Empty);
var character = new PlayableCharacter(Identifier.Empty, Description.Empty);
Expand All @@ -32,12 +33,13 @@ public void GivenValidGame_WhenInvoke_ThenInternal()
region.AddRoom(room, 0, 0, 0);
var overworld = new Overworld(string.Empty, string.Empty);
overworld.AddRegion(region);
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, character), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, character), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
game.ChangeMode(new AboutMode());
var command = new Help();

var result = command.Invoke(game);

Assert.AreEqual(ReactionResult.Internal, result.Result);
Assert.AreEqual(ReactionResult.Silent, result.Result);
}
}
}
6 changes: 3 additions & 3 deletions NetAF.Tests/Commands/Global/Map_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public void GivenNullGame_WhenInvoke_ThenError()
}

[TestMethod]
public void GivenValidGame_WhenInvoke_ThenInternal()
public void GivenValidGame_WhenInvoke_ThenSilent()
{
var overworld = new Overworld(Identifier.Empty, Description.Empty);
var region = new Region(Identifier.Empty, Description.Empty);
region.AddRoom(new Room(Identifier.Empty, Description.Empty, [new NetAF.Assets.Locations.Exit(Direction.North)]), 0, 0, 0);
region.AddRoom(new Room(Identifier.Empty, Description.Empty, [new NetAF.Assets.Locations.Exit(Direction.South)]), 0, 1, 0);
overworld.AddRegion(region);
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke();
var command = new Map();

var result = command.Invoke(game);

Assert.AreEqual(ReactionResult.Internal, result.Result);
Assert.AreEqual(ReactionResult.Silent, result.Result);
}
}
}
2 changes: 1 addition & 1 deletion NetAF.Tests/Commands/Global/New_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, ConsoleGameConfiguration.Default).Invoke();
var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, TestGameConfiguration.Default).Invoke();
var command = new New();

var result = command.Invoke(game);
Expand Down
Loading

0 comments on commit e224475

Please sign in to comment.