Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
etmendz committed Sep 10, 2023
1 parent 339ed82 commit 7971ce5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 12 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The GameLibrary provides a simple framework for creating games that can follow a
}
End();

The basic flow and basic construct combined defines the game's runtime. The general philosophy playfully plays with the idea that playing games can begin with "Ready? Set? Go!". The game can then Start to monitor game Actions, Continue state and GameOver state, to finally End.
The basic flow and basic construct combined establishes a structure for the game's runtime. The general philosophy playfully plays with the idea that playing games can begin with "Ready? Set? Go!". The game can then Start to monitor game Actions, Continue state and GameOver state, to finally End.

The design allows the game developer to focus on implementing the game play and the game UI.
The design allows the game developer to focus on implementing the game play and the game UI, which can then be consumed by a

Thus, for example, in a game console app's program main entry point, the developer can simply code:

Expand All @@ -37,20 +37,35 @@ Defines a game play designed to align with the basic construct's Start(), Action

The game play Action() is defined by the *in* and *out* generic types passed to IGamePlay.

The game play is essentially the actual game.

When implemented sans any UI-specific aspects, the game play can be re-used in different UI/UX platforms.

## IGameUI<TGamePlay, in TActionIn, out TActionOut>
Defines a game UI designed to align with the basic construct's Start(), Action(), Continue(), GameOver() and End() methods.

IGameUI accepts a type that implements IGamePlay, and provides additional methods to Render() and Refresh().

An implementation must define a parameterless constructor that can initialize an IGamePlay instance.

Implementations can be UI/UX platform specific.

## IGameFlow
Defines a game flow designed to align with the basic flow's Play(), Ready(), Set() and Go() methods.

Play() implements the basic flow.

Go() implements the basic construct.

Implementations can be UI/UX platform specific.

## GameRandomizer
Defines a game randomizer to generate random numbers.

Methods are provided to get the next random number, the next random number below a limit, and the next random number within a minimum/maximum range.

## GamePlayReadyMode
Specifies the game play ready mode or how the game flows.
Specifies the game play ready mode or how the game flows to consume the Ready(), Set() and Go() methods.

### IfReady
Start only one game UI instance per launch.
Expand All @@ -77,10 +92,12 @@ An example is 2048, where the player performs moves to reach a goal:
2. If the player runs out of moves, then the game is over:
- Then the game prompts the player to start a new game.

### GameConsole<TGameUI, TGamePlay, TActionIn, TActionOut>
## GameConsole<TGameUI, TGamePlay, TActionIn, TActionOut>
GameConsole implements IGameFlow for game console apps.

GameConsole accepts a type that implements IGameUI, which requires a type that implements IGamePlay.

Play() implements the basic flow, using the GamePlayReadyMode to switch:
Play() implements the basic flow using the GamePlayReadyMode to switch:

- IfReady
```
Expand Down Expand Up @@ -113,8 +130,8 @@ Go() implements the basic construct as follows:
}
gameUI.End();

### GameConsoleUX
Provides the basic capabilities for game interactions via keyboard.
## GameConsoleUX
Provides the basic capabilities for game console app interactions via keyboard.

Methods are provided to enable Y/N input, arrow key input, specific key input and valid keys input.

Expand Down
18 changes: 15 additions & 3 deletions src/GameLibrary/GameConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace GameLibrary;

/// <summary>
/// Defines a game console app.
/// Implements IGameFlow to define a console app game that can consume the provided IGameUI and IGamePlay implementations.
/// </summary>
/// <typeparam name="TGameUI">The game UI.</typeparam>
/// <typeparam name="TGamePlay">The game play.</typeparam>
Expand All @@ -18,7 +18,19 @@ namespace GameLibrary;
/// <param name="description">The game description.</param>
/// <param name="splashText">The game splash text.</param>
/// <param name="gamePlayReadyMode">The game play ready mode.</param>
public class GameConsole<TGameUI, TGamePlay, TActionIn, TActionOut>(string name, string copyright, string description, string? splashText = null, GamePlayReadyMode gamePlayReadyMode = GamePlayReadyMode.IfReady)
/// <remarks>
/// The program main entry point can use the following boilerplate template to call Play():
/// <code>
/// new GameConsole<GameUI, GamePlay, ConsoleKey, bool>(
/// "Game name",
/// "All rights reserved.",
/// "Game description.",
/// "Press [Esc] anytime to exit.",
/// GamePlayReadyMode.WhileReady
/// ).Play();
/// </code>
/// </remarks>
public class GameConsole<TGameUI, TGamePlay, TActionIn, TActionOut>(string name, string copyright, string description, string? splashText = null, GamePlayReadyMode gamePlayReadyMode = GamePlayReadyMode.IfReady) : IGameFlow
where TGameUI : IGameUI<TGamePlay, TActionIn, TActionOut>, new()
where TGamePlay : IGamePlay<TActionIn, TActionOut>
{
Expand Down Expand Up @@ -55,7 +67,7 @@ public class GameConsole<TGameUI, TGamePlay, TActionIn, TActionOut>(string name,
/// <summary>
/// Plays the game.
/// </summary>
/// <remarks>The default implementation basically calls (if|while) Ready(), Set(), Go()!</remarks>
/// <remarks>The default implementation uses GamePlayReadyMode to switch (if|while) Ready(), Set(), Go()!</remarks>
public virtual void Play()
{
Console.CursorVisible = false;
Expand Down
2 changes: 1 addition & 1 deletion src/GameLibrary/GameConsoleUX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace GameLibrary;

/// <summary>
/// Defines the game console UX capabilities for game flow and game play interactions.
/// Defines the game console UX capabilities for interactions via keyboard.
/// </summary>
/// <param name="escExit">Indicates if the [Esc] key exits the application. Default is true.</param>
public class GameConsoleUX(bool escExit = true)
Expand Down
2 changes: 1 addition & 1 deletion src/GameLibrary/GameLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Copyright>© Mendz, etmendz. All rights reserved.</Copyright>
Expand Down
33 changes: 33 additions & 0 deletions src/GameLibrary/IGameFlow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* GameLibrary (c) Mendz, etmendz. All rights reserved.
* SPDX-License-Identifier: MIT
*/
namespace GameLibrary;

/// <summary>
/// Defines the game flow.
/// </summary>
/// <remarks>Implementations can be UI/UX platform specific.</remarks>
public interface IGameFlow
{
/// <summary>
/// Plays the game.
/// </summary>
public void Play();

/// <summary>
/// Ready.
/// </summary>
/// <returns>True of ready, else false.</returns>
public bool Ready();

/// <summary>
/// Set.
/// </summary>
public void Set();

/// <summary>
/// Go!
/// </summary>
public void Go();
}
4 changes: 4 additions & 0 deletions src/GameLibrary/IGamePlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace GameLibrary;
/// </summary>
/// <typeparam name="TActionIn">The action input type.</typeparam>
/// <typeparam name="TActionOut">The action output or result type.</typeparam>
/// <remarks>
/// <para>The game play is essentially the actual game.</para>
/// <para>When implemented separate from any UI-specific aspects, the game play can be re-used in different UI/UX platforms.</para>
/// </remarks>
public interface IGamePlay<in TActionIn, out TActionOut>
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/GameLibrary/IGameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace GameLibrary;
/// <typeparam name="TGamePlay">The game play.</typeparam>
/// <typeparam name="TActionIn">The action input type.</typeparam>
/// <typeparam name="TActionOut">The action output or result type.</typeparam>
/// <remarks>Implementations can be UI/UX platform specific.</remarks>
public interface IGameUI<TGamePlay, in TActionIn, out TActionOut>
where TGamePlay : IGamePlay<TActionIn, TActionOut>
{
Expand Down

0 comments on commit 7971ce5

Please sign in to comment.