Skip to content

Commit

Permalink
Merge pull request #82 from benpollarduk/adding-game-setup
Browse files Browse the repository at this point in the history
Added setup callback
  • Loading branch information
benpollarduk authored Oct 27, 2024
2 parents ae4dd31 + ccca45f commit 3334358
Show file tree
Hide file tree
Showing 41 changed files with 691 additions and 345 deletions.
6 changes: 3 additions & 3 deletions NetAF.Examples/Assets/Regions/Hub/Rooms/Clearing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public Room Instantiate()
new Response("No thanks, keep things as they are.", new Jump(4))
]
},
new Paragraph("Arrk! Color it is.", g => g.FrameBuilders = FrameBuilderCollections.Default, new ToName("ModeQuestion")),
new Paragraph("Eeek, simple be fine too! Shame it's been deleted. Maybe it will be implmented again one day! Eeek!", new ToName("ModeQuestion")),
new Paragraph("Squarrk! Legacy, looks old. Shame it's been deleted. Maybe it will be implmented again one day! Arrk!", new ToName("ModeQuestion")),
new Paragraph("Arrk! Color it is.", g => g.ChangeFrameBuilders(FrameBuilderCollections.Default), new ToName("ModeQuestion")),
new Paragraph("Eeek, simple be fine too! Shame it's been deleted. Maybe it will be implemented again one day! Eeek!", new ToName("ModeQuestion")),
new Paragraph("Squarrk! Legacy, looks old. Shame it's been deleted. Maybe it will be implemented again one day! Arrk!", new ToName("ModeQuestion")),
new Paragraph("Fine, suit yourself! Squarrk!", new ToName("ModeQuestion"))
);

Expand Down
25 changes: 9 additions & 16 deletions NetAF.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace NetAF.Examples
{
internal class Program
internal static class Program
{
private static EndCheckResult DetermineIfGameHasCompleted(Game game)
{
Expand Down Expand Up @@ -66,19 +66,19 @@ private static void Main(string[] args)
{
try
{
OverworldCreationCallback overworldCreator = () =>
static Overworld overworldCreator()
{
var regions = new List<Region>
{
new Everglades().Instantiate(),
new Flat().Instantiate(),
new Zelda().Instantiate()
};

var overworld = new Overworld("Demo", "A demo of NetAF.");

var hub = new Hub().Instantiate();
PopulateHub(hub, overworld, regions.ToArray());
PopulateHub(hub, overworld, [.. regions]);
overworld.AddRegion(hub);

foreach (var region in regions)
Expand All @@ -95,9 +95,9 @@ private static void Main(string[] args)

if (a?.Length >= 3)
{
int.TryParse(a[0], out x);
int.TryParse(a[1], out y);
int.TryParse(a[2], out z);
_ = int.TryParse(a[0], out x);
_ = int.TryParse(a[1], out y);
_ = int.TryParse(a[2], out z);
}

var result = g.Overworld.CurrentRegion.JumpToRoom(x, y, z);
Expand All @@ -110,17 +110,10 @@ private static void Main(string[] args)
];

return overworld;
};
}

var about = "This is a short demo of NetAF made up from test chunks of games that were build to test different features during development.";

var creator = Game.Create("NetAF Demo",
about,
about,
overworldCreator,
() => new Player().Instantiate(),
DetermineIfGameHasCompleted,
DetermineIfGameOver);
var creator = Game.Create(new GameInfo("NetAF Demo", about, "NetAF"), about, AssetGenerator.Custom(overworldCreator, new Player().Instantiate), new GameEndConditions(DetermineIfGameHasCompleted, DetermineIfGameOver), GameConfiguration.Default);

Game.Execute(creator);
}
Expand Down
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(string.Empty, string.Empty, string.Empty, () => overworld, () => player, g => EndCheckResult.NotEnded, g => EndCheckResult.NotEnded);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, GameConfiguration.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(string.Empty, string.Empty, string.Empty, () => overworld, () => player, g => EndCheckResult.NotEnded, g => EndCheckResult.NotEnded);
var gameCreator = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, GameConfiguration.Default);

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

Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Conversation/End_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Conversation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Conversation
{
Expand All @@ -20,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), null, GameConfiguration.Default).Invoke();
var command = new End();

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

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

var result = command.Invoke(game);
Expand All @@ -33,7 +34,7 @@ public void GivenNoConverser_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGameAndConverser_WhenInvoke_ThenInternal()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var converser = new NonPlayableCharacter(string.Empty, string.Empty) { Conversation = new NetAF.Conversations.Conversation(new Paragraph(string.Empty)) };
game.StartConversation(converser);
var command = new Next();
Expand Down
7 changes: 4 additions & 3 deletions NetAF.Tests/Commands/Conversation/Respond_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NetAF.Commands.Conversation;
using NetAF.Conversations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

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

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

Expand All @@ -45,7 +46,7 @@ public void GivenNoConverser_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenInternal()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var response = new Response("");
var paragraph = new Paragraph(string.Empty) { Responses = [response] };
var conversation = new NetAF.Conversations.Conversation(paragraph);
Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Frame;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Frame
{
Expand All @@ -20,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new CommandsOff();

var result = command.Invoke(game);
Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Frame;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Frame
{
Expand All @@ -20,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new CommandsOn();

var result = command.Invoke(game);
Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Frame/KeyOff_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Frame;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Frame
{
Expand All @@ -20,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new KeyOff();

var result = command.Invoke(game);
Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Frame/KeyOn_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetAF.Assets.Interaction;
using NetAF.Commands.Frame;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Frame
{
Expand All @@ -20,7 +21,7 @@ public void GivenNullGame_WhenInvoke_ThenError()
[TestMethod]
public void GivenValidGame_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new KeyOn();

var result = command.Invoke(game);
Expand Down
9 changes: 5 additions & 4 deletions NetAF.Tests/Commands/Game/Drop_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NetAF.Assets.Locations;
using NetAF.Commands.Game;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Game
{
Expand All @@ -13,7 +14,7 @@ public class Drop_Tests
[TestMethod]
public void GivenNoCharacter_WhenInvoke_ThenError()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Drop(null);

var result = command.Invoke(game);
Expand All @@ -25,7 +26,7 @@ public void GivenNoCharacter_WhenInvoke_ThenError()
public void GivenNoItem_WhenInvoke_ThenError()
{
var character = new PlayableCharacter(Identifier.Empty, Description.Empty);
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, () => character, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, character), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Drop(null);

var result = command.Invoke(game);
Expand All @@ -43,7 +44,7 @@ public void GivenPlayerDoesNotHaveItem_WhenInvoke_ThenError()
overworld.AddRegion(region);
var character = new PlayableCharacter(Identifier.Empty, Description.Empty);
var item = new Item(new Identifier("A"), Description.Empty, true);
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, () => overworld, () => character, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, character), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Drop(item);

var result = command.Invoke(game);
Expand All @@ -62,7 +63,7 @@ public void GivenItemIsDroppable_WhenInvoke_ThenOK()
var character = new PlayableCharacter(Identifier.Empty, Description.Empty);
var item = new Item(new Identifier("A"), Description.Empty, true);
character.AcquireItem(item);
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, () => overworld, () => character, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, character), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Drop(item);

var result = command.Invoke(game);
Expand Down
3 changes: 2 additions & 1 deletion NetAF.Tests/Commands/Game/Examine_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NetAF.Assets.Locations;
using NetAF.Commands.Game;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Game
{
Expand All @@ -22,7 +23,7 @@ public void GivenNothingToExamine_WhenInvoke_ThenError()
[TestMethod]
public void GivenSomethingToExamine_WhenInvoke_ThenOK()
{
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(null, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var region = new Region(Identifier.Empty, Description.Empty);
var command = new Examine(region);

Expand Down
5 changes: 3 additions & 2 deletions NetAF.Tests/Commands/Game/Move_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NetAF.Assets.Locations;
using NetAF.Commands.Game;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAF.Logic;

namespace NetAF.Tests.Commands.Game
{
Expand All @@ -17,7 +18,7 @@ public void GivenCantMove_WhenInvoke_ThenError()
region.AddRoom(new Room(Identifier.Empty, Description.Empty, new Exit(Direction.South)), 0, 1, 0);
var overworld = new Overworld(string.Empty, string.Empty);
overworld.AddRegion(region);
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, () => overworld, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Move(Direction.East);

var result = command.Invoke(game);
Expand All @@ -33,7 +34,7 @@ public void GivenCanMove_WhenInvoke_ThenOK()
region.AddRoom(new Room(Identifier.Empty, Description.Empty, new Exit(Direction.South)), 0, 1, 0);
var overworld = new Overworld(string.Empty, string.Empty);
overworld.AddRegion(region);
var game = NetAF.Logic.Game.Create(string.Empty, string.Empty, string.Empty, () => overworld, null, null, null).Invoke();
var game = NetAF.Logic.Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, null), GameEndConditions.NoEnd, GameConfiguration.Default).Invoke();
var command = new Move(Direction.North);

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

0 comments on commit 3334358

Please sign in to comment.