mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-08 03:12:26 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
47
84_Super_Star_Trek/csharp/Systems/LibraryComputer.cs
Normal file
47
84_Super_Star_Trek/csharp/Systems/LibraryComputer.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using SuperStarTrek.Commands;
|
||||
using SuperStarTrek.Space;
|
||||
using SuperStarTrek.Systems.ComputerFunctions;
|
||||
|
||||
namespace SuperStarTrek.Systems
|
||||
{
|
||||
internal class LibraryComputer : Subsystem
|
||||
{
|
||||
private readonly Output _output;
|
||||
private readonly Input _input;
|
||||
private readonly ComputerFunction[] _functions;
|
||||
|
||||
internal LibraryComputer(Output output, Input input, params ComputerFunction[] functions)
|
||||
: base("Library-Computer", Command.COM, output)
|
||||
{
|
||||
_output = output;
|
||||
_input = input;
|
||||
_functions = functions;
|
||||
}
|
||||
|
||||
protected override bool CanExecuteCommand() => IsOperational("Computer disabled");
|
||||
|
||||
protected override CommandResult ExecuteCommandCore(Quadrant quadrant)
|
||||
{
|
||||
var index = GetFunctionIndex();
|
||||
_output.NextLine();
|
||||
|
||||
_functions[index].Execute(quadrant);
|
||||
|
||||
return CommandResult.Ok;
|
||||
}
|
||||
|
||||
private int GetFunctionIndex()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var index = (int)_input.GetNumber("Computer active and waiting command");
|
||||
if (index >= 0 && index <= 5) { return index; }
|
||||
|
||||
for (int i = 0; i < _functions.Length; i++)
|
||||
{
|
||||
_output.WriteLine($" {i} = {_functions[i].Description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user