openthebox/src/OpenTheBox/Rendering/BasicRenderer.cs
Samuel Bouchet 04894a4906 Initial project setup: Open The Box CLI game
- .NET 10 console app with Spectre.Console and Loreline integration
- Black Box Sim architecture (simulation separated from presentation)
- Progressive CLI rendering (9 phases from basic to full layout)
- 25+ box definitions with weighted loot tables
- 100+ item definitions (meta, cosmetics, materials, adventure tokens)
- 9 Loreline adventures (Space, Medieval, Pirate, etc.)
- Bilingual content (EN/FR)
- Save/load system
- Game Design Document
2026-03-10 18:24:01 +01:00

124 lines
3.5 KiB
C#

using OpenTheBox.Core;
namespace OpenTheBox.Rendering;
/// <summary>
/// Phase 0 renderer. Pure Console.WriteLine and Console.ReadLine.
/// No colors, no frames, no fancy stuff. This is the "stone age" of the UI,
/// deliberately ugly and minimal.
/// </summary>
public sealed class BasicRenderer : IRenderer
{
public void ShowMessage(string message)
{
Console.WriteLine(message);
}
public void ShowError(string message)
{
Console.WriteLine($"ERROR: {message}");
}
public void ShowBoxOpening(string boxName, string rarity)
{
Console.WriteLine($"Opening {boxName}...");
Console.WriteLine("...");
Console.WriteLine("......");
Console.WriteLine($"Box opened! (Rarity: {rarity})");
}
public void ShowLootReveal(List<(string name, string rarity, string category)> items)
{
Console.WriteLine("You received:");
for (int i = 0; i < items.Count; i++)
{
var (name, rarity, category) = items[i];
Console.WriteLine($" - {name} [{rarity}] ({category})");
}
}
public int ShowSelection(string prompt, List<string> options)
{
Console.WriteLine(prompt);
for (int i = 0; i < options.Count; i++)
{
Console.WriteLine($" {i + 1}. {options[i]}");
}
while (true)
{
Console.Write("> ");
string? input = Console.ReadLine();
if (int.TryParse(input, out int choice) && choice >= 1 && choice <= options.Count)
{
return choice - 1;
}
Console.WriteLine($"Please enter a number between 1 and {options.Count}.");
}
}
public string ShowTextInput(string prompt)
{
Console.Write($"{prompt}: ");
return Console.ReadLine() ?? string.Empty;
}
public void ShowGameState(GameState state, RenderContext context)
{
// Phase 0: no panels unlocked yet, so nothing to show.
}
public void ShowAdventureDialogue(string? character, string text)
{
if (character is not null)
{
Console.WriteLine($"[{character}]");
}
Console.WriteLine(text);
Console.WriteLine();
}
public int ShowAdventureChoice(List<string> options)
{
Console.WriteLine("What do you do?");
for (int i = 0; i < options.Count; i++)
{
Console.WriteLine($" {i + 1}. {options[i]}");
}
while (true)
{
Console.Write("> ");
string? input = Console.ReadLine();
if (int.TryParse(input, out int choice) && choice >= 1 && choice <= options.Count)
{
return choice - 1;
}
Console.WriteLine($"Please enter a number between 1 and {options.Count}.");
}
}
public void ShowUIFeatureUnlocked(string featureName)
{
Console.WriteLine("========================================");
Console.WriteLine($" NEW FEATURE UNLOCKED: {featureName}");
Console.WriteLine("========================================");
}
public void ShowInteraction(string description)
{
Console.WriteLine($"* {description} *");
}
public void WaitForKeyPress(string? message = null)
{
Console.WriteLine(message ?? "Press any key to continue...");
Console.ReadKey(intercept: true);
Console.WriteLine();
}
public void Clear()
{
Console.Clear();
}
}