From 26decdcd2b3c9397c9c36df13f936118189b1550 Mon Sep 17 00:00:00 2001 From: Darren Cardenas <53984972+darrencardenas@users.noreply.github.com> Date: Sat, 10 Apr 2021 19:52:00 -0400 Subject: [PATCH 01/15] Ported Reverse to Java. --- 73 Reverse/java/Reverse.java | 242 +++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 73 Reverse/java/Reverse.java diff --git a/73 Reverse/java/Reverse.java b/73 Reverse/java/Reverse.java new file mode 100644 index 00000000..22c1d073 --- /dev/null +++ b/73 Reverse/java/Reverse.java @@ -0,0 +1,242 @@ +import java.util.Scanner; +import java.lang.Math; + +/** + * Game of Reverse + *

+ * Based on the BASIC game of Reverse here + * https://github.com/coding-horror/basic-computer-games/blob/main/73%20Reverse/reverse.bas + *

+ * Note: The idea was to create a version of the 1970's BASIC game in Java, without introducing + * new features - no additional text, error checking, etc has been added. + * + * Converted from BASIC to Java by Darren Cardenas. + */ + +public class Reverse { + + private final int NUMBER_COUNT = 9; + + private final Scanner scan; // For user input + + private enum Step { + INITIALIZE, PERFORM_REVERSE, TRY_AGAIN, END_GAME + } + + public Reverse() { + + scan = new Scanner(System.in); + + } // End of constructor Reverse + + public void play() { + + showIntro(); + startGame(); + + } // End of method play + + private static void showIntro() { + + System.out.println(" ".repeat(31) + "REVERSE"); + System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); + System.out.println("\n\n"); + System.out.println("REVERSE -- A GAME OF SKILL"); + System.out.println(""); + + } // End of method showIntro + + private void startGame() { + + int index = 0; + int numMoves = 0; + int numReverse = 0; + int tempVal = 0; + int[] numList = new int[NUMBER_COUNT + 1]; + + Step nextStep = Step.INITIALIZE; + + String userResponse = ""; + + System.out.print("DO YOU WANT THE RULES? "); + userResponse = scan.nextLine(); + + if (!userResponse.toUpperCase().equals("NO")) { + + this.printRules(); + } + + // Begin outer while loop + while (true) { + + // Begin outer switch + switch (nextStep) { + + case INITIALIZE: + + // Make a random list of numbers + numList[1] = (int)((NUMBER_COUNT - 1) * Math.random() + 2); + + for (index = 2; index <= NUMBER_COUNT; index++) { + + // Keep generating lists if there are duplicates + while (true) { + + numList[index] = (int)(NUMBER_COUNT * Math.random() + 1); + + // Search for duplicates + if (!this.findDuplicates(numList, index)) { + break; + } + } + } + + System.out.println(""); + System.out.println("HERE WE GO ... THE LIST IS:"); + + numMoves = 0; + + this.printBoard(numList); + + nextStep = Step.PERFORM_REVERSE; + break; + + case PERFORM_REVERSE: + + System.out.print("HOW MANY SHALL I REVERSE? "); + numReverse = Integer.parseInt(scan.nextLine()); + + if (numReverse == 0) { + + nextStep = Step.TRY_AGAIN; + + } else if (numReverse > NUMBER_COUNT) { + + System.out.println("OOPS! TOO MANY! I CAN REVERSE AT MOST " + NUMBER_COUNT); + nextStep = Step.PERFORM_REVERSE; + + } else { + + numMoves++; + + for (index = 1; index <= (int)(numReverse / 2.0); index++) { + + tempVal = numList[index]; + numList[index] = numList[numReverse - index + 1]; + numList[numReverse - index + 1] = tempVal; + } + + this.printBoard(numList); + + nextStep = Step.TRY_AGAIN; + + // Check for a win + for (index = 1; index <= NUMBER_COUNT; index++) { + + if (numList[index] != index) { + nextStep = Step.PERFORM_REVERSE; + } + } + + if (nextStep == Step.TRY_AGAIN) { + System.out.println("YOU WON IT IN " + numMoves + " MOVES!!!"); + System.out.println(""); + } + } + break; + + case TRY_AGAIN: + + System.out.println(""); + System.out.print("TRY AGAIN (YES OR NO)? "); + userResponse = scan.nextLine(); + + if (userResponse.toUpperCase().equals("YES")) { + nextStep = Step.INITIALIZE; + } else { + nextStep = Step.END_GAME; + } + break; + + case END_GAME: + + System.out.println(""); + System.out.println("O.K. HOPE YOU HAD FUN!!"); + return; + + default: + + System.out.println("INVALID STEP"); + break; + + } // End outer switch + + } // End outer while loop + + } // End of method startGame + + public boolean findDuplicates(int[] board, int length) { + + int index = 0; + + for (index = 1; index <= length - 1; index++) { + + // Identify duplicates + if (board[length] == board[index]) { + + return true; // Found a duplicate + } + } + + return false; // No duplicates found + + } // End of method findDuplicates + + public void printBoard(int[] board) { + + int index = 0; + + System.out.println(""); + + for (index = 1; index <= NUMBER_COUNT; index++) { + + System.out.format("%2d", board[index]); + } + + System.out.println("\n"); + + } // End of method printBoard + + public void printRules() { + + System.out.println(""); + System.out.println("THIS IS THE GAME OF 'REVERSE'. TO WIN, ALL YOU HAVE"); + System.out.println("TO DO IS ARRANGE A LIST OF NUMBERS (1 THROUGH " + NUMBER_COUNT + ")"); + System.out.println("IN NUMERICAL ORDER FROM LEFT TO RIGHT. TO MOVE, YOU"); + System.out.println("TELL ME HOW MANY NUMBERS (COUNTING FROM THE LEFT) TO"); + System.out.println("REVERSE. FOR EXAMPLE, IF THE CURRENT LIST IS:"); + System.out.println(""); + System.out.println("2 3 4 5 1 6 7 8 9"); + System.out.println(""); + System.out.println("AND YOU REVERSE 4, THE RESULT WILL BE:"); + System.out.println(""); + System.out.println("5 4 3 2 1 6 7 8 9"); + System.out.println(""); + System.out.println("NOW IF YOU REVERSE 5, YOU WIN!"); + System.out.println(""); + System.out.println("1 2 3 4 5 6 7 8 9"); + System.out.println(""); + System.out.println("NO DOUBT YOU WILL LIKE THIS GAME, BUT"); + System.out.println("IF YOU WANT TO QUIT, REVERSE 0 (ZERO)."); + System.out.println(""); + + } // End of method printRules + + public static void main(String[] args) { + + Reverse game = new Reverse(); + game.play(); + + } // End of method main + +} // End of class Reverse From 2de853ade3db4550648af8a70d82922419f400e8 Mon Sep 17 00:00:00 2001 From: Dave LeCompte Date: Tue, 13 Apr 2021 21:08:06 -0700 Subject: [PATCH 02/15] Fix missing global variable --- 04 Awari/python/awari.py | 1 + 1 file changed, 1 insertion(+) diff --git a/04 Awari/python/awari.py b/04 Awari/python/awari.py index de97ee97..c04cce26 100644 --- a/04 Awari/python/awari.py +++ b/04 Awari/python/awari.py @@ -90,6 +90,7 @@ One could go many directions with this game: game_number = 0 move_count = 0 losing_book = [] +n = 0 MAX_HISTORY = 9 LOSING_BOOK_SIZE = 50 From a97a049ae909651481343e0bb21eaf3573de5450 Mon Sep 17 00:00:00 2001 From: Darren Cardenas <53984972+darrencardenas@users.noreply.github.com> Date: Wed, 14 Apr 2021 19:01:58 -0400 Subject: [PATCH 03/15] Ported Calendar to Java. --- 21 Calendar/java/Calendar.java | 175 +++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 21 Calendar/java/Calendar.java diff --git a/21 Calendar/java/Calendar.java b/21 Calendar/java/Calendar.java new file mode 100644 index 00000000..4202a4dc --- /dev/null +++ b/21 Calendar/java/Calendar.java @@ -0,0 +1,175 @@ +/** + * Game of Calendar + *

+ * Based on the BASIC game of Calendar here + * https://github.com/coding-horror/basic-computer-games/blob/main/21%20Calendar/calendar.bas + *

+ * Note: The idea was to create a version of the 1970's BASIC game in Java, without introducing + * new features - no additional text, error checking, etc has been added. + * + * Converted from BASIC to Java by Darren Cardenas. + */ + +public class Calendar { + + private static final int NUM_WEEK_ROWS = 6; + private static final int NUM_DAYS_PER_WEEK = 7; + private static final int NUM_MONTHS_PER_YEAR = 12; + private static final int[] daysPerMonth = { 0, 31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31 }; + + public void play() { + + showIntro(); + startGame(); + + } // End of method play + + private static void showIntro() { + + System.out.println(" ".repeat(31) + "CALENDAR"); + System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); + System.out.println("\n\n"); + + } // End of method showIntro + + private void startGame() { + + int dayOfMonth = 0; + int dayOfWeek = 0; + int dayOfYear = 0; + int daysTotal = 0; + int index = 0; + int month = 0; + int row = 0; + + String lineContent = ""; + + for (index = 1; index <= 6; index++) { + System.out.println(""); + } + + daysTotal = -1; + dayOfYear = 0; + + System.out.println(""); + + // Begin loop through all months + for (month = 1; month <= NUM_MONTHS_PER_YEAR; month++) { + + System.out.println(""); + + dayOfYear = dayOfYear + daysPerMonth[month - 1]; + + lineContent = String.format("** %-3d" + "*".repeat(18), dayOfYear); + + switch (month) { + case 1: + lineContent += " JANUARY "; + break; + case 2: + lineContent += " FEBRUARY"; + break; + case 3: + lineContent += " MARCH "; + break; + case 4: + lineContent += " APRIL "; + break; + case 5: + lineContent += " MAY "; + break; + case 6: + lineContent += " JUNE "; + break; + case 7: + lineContent += " JULY "; + break; + case 8: + lineContent += " AUGUST "; + break; + case 9: + lineContent += "SEPTEMBER"; + break; + case 10: + lineContent += " OCTOBER "; + break; + case 11: + lineContent += " NOVEMBER"; + break; + case 12: + lineContent += " DECEMBER"; + break; + default: + break; + } + + lineContent += "*".repeat(18) + " " + (365 - dayOfYear) + "**"; + + System.out.println(lineContent); + System.out.println(""); + + System.out.print(" S M T W"); + System.out.println(" T F S"); + System.out.println(""); + + System.out.println("*".repeat(59)); + + // Begin loop through each week row + for (row = 1; row <= NUM_WEEK_ROWS; row++) { + + System.out.println(""); + + lineContent = " "; + + // Begin loop through days of the week + for (dayOfWeek = 1; dayOfWeek <= NUM_DAYS_PER_WEEK; dayOfWeek++) { + + daysTotal++; + + dayOfMonth = daysTotal - dayOfYear; + + if (dayOfMonth > daysPerMonth[month]) { + row = 6; + break; + } + + if (dayOfMonth > 0) { + lineContent += dayOfMonth; + } + + while (lineContent.length() < (4 + 8 * dayOfWeek)) { + lineContent += " "; + } + + } // End loop through days of the week + + if (dayOfMonth == daysPerMonth[month]) { + row = 6; + daysTotal += dayOfWeek; + System.out.println(lineContent); + break; + } + + System.out.println(lineContent); + + } // End loop through each week row + + daysTotal -= dayOfWeek; + + } // End loop through all months + + for (index = 1; index <= 6; index++) { + System.out.println(""); + } + + } // End of method startGame + + public static void main(String[] args) { + + Calendar game = new Calendar(); + game.play(); + + } // End of method main + +} // End of class Calendar From 6d7e57430e203c4931264efcbfddbf79b7e28836 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:21:01 +1000 Subject: [PATCH 04/15] Standardise accessibility keywords and remove dead code. --- 84 Super Star Trek/csharp/Game.cs | 20 +++---- 84 Super Star Trek/csharp/Input.cs | 24 ++++---- .../csharp/Objects/Enterprise.cs | 56 +++++++++---------- 84 Super Star Trek/csharp/Objects/Klingon.cs | 8 +-- 84 Super Star Trek/csharp/Objects/Starbase.cs | 2 +- 84 Super Star Trek/csharp/Output.cs | 10 ++-- 84 Super Star Trek/csharp/Program.cs | 7 ++- 84 Super Star Trek/csharp/Random.cs | 10 ++-- .../csharp/Resources/Strings.cs | 50 ++++++++--------- .../csharp/Space/Coordinates.cs | 10 ++-- 84 Super Star Trek/csharp/Space/Galaxy.cs | 14 ++--- 84 Super Star Trek/csharp/Space/Quadrant.cs | 20 +++---- .../csharp/Space/QuadrantInfo.cs | 14 ++--- .../DirectionDistanceCalculator.cs | 5 +- .../ComputerFunctions/GalacticReport.cs | 2 +- .../StarbaseDataCalculator.cs | 2 +- .../Systems/ComputerFunctions/StatusReport.cs | 2 +- .../TorpedoDataCalculator.cs | 2 +- .../csharp/Systems/DamageControl.cs | 4 +- .../csharp/Systems/LibraryComputer.cs | 2 +- .../csharp/Systems/LongRangeSensors.cs | 7 +-- .../csharp/Systems/PhaserControl.cs | 2 +- .../csharp/Systems/PhotonTubes.cs | 4 +- .../csharp/Systems/ShieldControl.cs | 4 +- .../csharp/Systems/ShortRangeSensors.cs | 4 +- .../csharp/Systems/Subsystem.cs | 15 +++-- .../csharp/Systems/WarpEngines.cs | 2 +- .../csharp/Utils/DirectionAndDistance.cs | 8 +-- 28 files changed, 149 insertions(+), 161 deletions(-) diff --git a/84 Super Star Trek/csharp/Game.cs b/84 Super Star Trek/csharp/Game.cs index f2e1c819..96261498 100644 --- a/84 Super Star Trek/csharp/Game.cs +++ b/84 Super Star Trek/csharp/Game.cs @@ -4,7 +4,6 @@ using SuperStarTrek.Resources; using SuperStarTrek.Space; using SuperStarTrek.Systems; using SuperStarTrek.Systems.ComputerFunctions; -using static System.StringComparison; namespace SuperStarTrek { @@ -22,17 +21,17 @@ namespace SuperStarTrek private int _initialKlingonCount; private Enterprise _enterprise; - public Game() + internal Game(Output output, Input input, Random random) { - _output = new Output(); - _input = new Input(_output); - _random = new Random(); + _output = output; + _input = input; + _random = random; } - public float Stardate => _currentStardate; - public float StardatesRemaining => _finalStarDate - _currentStardate; + internal float Stardate => _currentStardate; + internal float StardatesRemaining => _finalStarDate - _currentStardate; - public void DoIntroduction() + internal void DoIntroduction() { _output.Write(Strings.Title); @@ -44,11 +43,10 @@ namespace SuperStarTrek } } - public void Play() + internal void Play() { Initialise(); var gameOver = false; - var newQuadrantText = Strings.StartText; while (!gameOver) { @@ -120,7 +118,7 @@ namespace SuperStarTrek private Quadrant BuildCurrentQuadrant() => new Quadrant(_galaxy[_currentQuadrant], _enterprise, _random, _galaxy, _input, _output); - public bool Replay() => _galaxy.StarbaseCount > 0 && _input.GetString(Strings.ReplayPrompt, "Aye"); + internal bool Replay() => _galaxy.StarbaseCount > 0 && _input.GetString(Strings.ReplayPrompt, "Aye"); private bool CheckIfStranded() { diff --git a/84 Super Star Trek/csharp/Input.cs b/84 Super Star Trek/csharp/Input.cs index 3011738b..2b37b2ba 100644 --- a/84 Super Star Trek/csharp/Input.cs +++ b/84 Super Star Trek/csharp/Input.cs @@ -10,24 +10,24 @@ namespace SuperStarTrek { private readonly Output _output; - public Input(Output output) + internal Input(Output output) { _output = output; } - public void WaitForAnyKeyButEnter(string prompt) + internal void WaitForAnyKeyButEnter(string prompt) { _output.Write($"Hit any key but Enter {prompt} "); while (Console.ReadKey(intercept: true).Key == ConsoleKey.Enter); } - public string GetString(string prompt) + internal string GetString(string prompt) { _output.Prompt(prompt); return Console.ReadLine(); } - public float GetNumber(string prompt) + internal float GetNumber(string prompt) { _output.Prompt(prompt); @@ -44,24 +44,24 @@ namespace SuperStarTrek } } - public (float X, float Y) GetCoordinates(string prompt) + internal (float X, float Y) GetCoordinates(string prompt) { _output.Prompt($"{prompt} (X,Y)"); var responses = ReadNumbers(2); return (responses[0], responses[1]); } - public bool TryGetNumber(string prompt, float minValue, float maxValue, out float value) + internal bool TryGetNumber(string prompt, float minValue, float maxValue, out float value) { value = GetNumber($"{prompt} ({minValue}-{maxValue})"); return value >= minValue && value <= maxValue; } - internal bool GetString(string replayPrompt, string trueValue) - => GetString(replayPrompt).Equals(trueValue, InvariantCultureIgnoreCase); + internal bool GetString(string replayPrompt, string trueValue) => + GetString(replayPrompt).Equals(trueValue, InvariantCultureIgnoreCase); - public Command GetCommand() + internal Command GetCommand() { while(true) { @@ -82,7 +82,7 @@ namespace SuperStarTrek } } - public bool TryGetCourse(string prompt, string officer, out Course course) + internal bool TryGetCourse(string prompt, string officer, out Course course) { if (!TryGetNumber(prompt, 1, 9, out var direction)) { @@ -95,7 +95,7 @@ namespace SuperStarTrek return true; } - public bool GetYesNo(string prompt, YesNoMode mode) + internal bool GetYesNo(string prompt, YesNoMode mode) { _output.Prompt($"{prompt} (Y/N)"); var response = Console.ReadLine().ToUpperInvariant(); @@ -150,7 +150,7 @@ namespace SuperStarTrek return numbers; } - public enum YesNoMode + internal enum YesNoMode { TrueOnY, FalseOnN diff --git a/84 Super Star Trek/csharp/Objects/Enterprise.cs b/84 Super Star Trek/csharp/Objects/Enterprise.cs index 4adf81df..2f587631 100644 --- a/84 Super Star Trek/csharp/Objects/Enterprise.cs +++ b/84 Super Star Trek/csharp/Objects/Enterprise.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using SuperStarTrek.Commands; using SuperStarTrek.Resources; using SuperStarTrek.Space; @@ -31,22 +30,33 @@ namespace SuperStarTrek.Objects _input = input; } - public Quadrant Quadrant => _quadrant; - public Coordinates QuadrantCoordinates => _quadrant.Coordinates; - public Coordinates SectorCoordinates { get; private set; } + internal Quadrant Quadrant => _quadrant; - public string Condition => GetCondition(); - public LibraryComputer Computer => (LibraryComputer)_commandExecutors[Command.COM]; - public ShieldControl ShieldControl => (ShieldControl)_commandExecutors[Command.SHE]; - public float Energy => TotalEnergy - ShieldControl.ShieldEnergy; - public float TotalEnergy { get; private set; } - public int DamagedSystemCount => _systems.Count(s => s.IsDamaged); - public IEnumerable Systems => _systems; - public PhotonTubes PhotonTubes => (PhotonTubes)_commandExecutors[Command.TOR]; - public bool IsDocked => _quadrant.EnterpriseIsNextToStarbase; - public bool IsStranded => TotalEnergy < 10 || Energy < 10 && ShieldControl.IsDamaged; + internal Coordinates QuadrantCoordinates => _quadrant.Coordinates; - public Enterprise Add(Subsystem system) + internal Coordinates SectorCoordinates { get; private set; } + + internal string Condition => GetCondition(); + + internal LibraryComputer Computer => (LibraryComputer)_commandExecutors[Command.COM]; + + internal ShieldControl ShieldControl => (ShieldControl)_commandExecutors[Command.SHE]; + + internal float Energy => TotalEnergy - ShieldControl.ShieldEnergy; + + internal float TotalEnergy { get; private set; } + + internal int DamagedSystemCount => _systems.Count(s => s.IsDamaged); + + internal IEnumerable Systems => _systems; + + internal PhotonTubes PhotonTubes => (PhotonTubes)_commandExecutors[Command.TOR]; + + internal bool IsDocked => _quadrant.EnterpriseIsNextToStarbase; + + internal bool IsStranded => TotalEnergy < 10 || Energy < 10 && ShieldControl.IsDamaged; + + internal Enterprise Add(Subsystem system) { _systems.Add(system); _commandExecutors[system.Command] = system; @@ -54,7 +64,7 @@ namespace SuperStarTrek.Objects return this; } - public void StartIn(Quadrant quadrant) + internal void StartIn(Quadrant quadrant) { _quadrant = quadrant; quadrant.Display(Strings.StartText); @@ -68,24 +78,14 @@ namespace SuperStarTrek.Objects _ => "Green" }; - public CommandResult Execute(Command command) + internal CommandResult Execute(Command command) { if (command == Command.XXX) { return CommandResult.GameOver; } return _commandExecutors[command].ExecuteCommand(_quadrant); } - public void Refuel() => TotalEnergy = _maxEnergy; - - internal bool Recognises(string command) - { - throw new NotImplementedException(); - } - - internal string GetCommandList() - { - throw new NotImplementedException(); - } + internal void Refuel() => TotalEnergy = _maxEnergy; public override string ToString() => "<*>"; diff --git a/84 Super Star Trek/csharp/Objects/Klingon.cs b/84 Super Star Trek/csharp/Objects/Klingon.cs index 4e277b07..78c307e5 100644 --- a/84 Super Star Trek/csharp/Objects/Klingon.cs +++ b/84 Super Star Trek/csharp/Objects/Klingon.cs @@ -7,19 +7,19 @@ namespace SuperStarTrek.Objects { private readonly Random _random; - public Klingon(Coordinates sector, Random random) + internal Klingon(Coordinates sector, Random random) { Sector = sector; _random = random; Energy = _random.GetFloat(100, 300); } - public float Energy { get; private set; } - public Coordinates Sector { get; private set; } + internal float Energy { get; private set; } + internal Coordinates Sector { get; private set; } public override string ToString() => "+K+"; - public CommandResult FireOn(Enterprise enterprise) + internal CommandResult FireOn(Enterprise enterprise) { var attackStrength = _random.GetFloat(); var distanceToEnterprise = Sector.GetDistanceTo(enterprise.SectorCoordinates); diff --git a/84 Super Star Trek/csharp/Objects/Starbase.cs b/84 Super Star Trek/csharp/Objects/Starbase.cs index 4befa73a..1ef4a85e 100644 --- a/84 Super Star Trek/csharp/Objects/Starbase.cs +++ b/84 Super Star Trek/csharp/Objects/Starbase.cs @@ -9,7 +9,7 @@ namespace SuperStarTrek.Objects private readonly Output _output; private readonly float _repairDelay; - public Starbase(Coordinates sector, Random random, Input input, Output output) + internal Starbase(Coordinates sector, Random random, Input input, Output output) { Sector = sector; _repairDelay = random.GetFloat() * 0.5f; diff --git a/84 Super Star Trek/csharp/Output.cs b/84 Super Star Trek/csharp/Output.cs index ed960eea..6a377bce 100644 --- a/84 Super Star Trek/csharp/Output.cs +++ b/84 Super Star Trek/csharp/Output.cs @@ -4,33 +4,33 @@ namespace SuperStarTrek { internal class Output { - public Output Write(string text) + internal Output Write(string text) { Console.Write(text); return this; } - public Output Write(string format, params object[] args) + internal Output Write(string format, params object[] args) { Console.Write(format, args); return this; } - public Output WriteLine(string text = "") + internal Output WriteLine(string text = "") { Console.WriteLine(text); return this; } - public Output NextLine() + internal Output NextLine() { Console.WriteLine(); return this; } - public Output Prompt(string text = "") + internal Output Prompt(string text = "") { Console.Write($"{text}? "); return this; diff --git a/84 Super Star Trek/csharp/Program.cs b/84 Super Star Trek/csharp/Program.cs index 7f8395a6..7080df29 100644 --- a/84 Super Star Trek/csharp/Program.cs +++ b/84 Super Star Trek/csharp/Program.cs @@ -29,8 +29,11 @@ namespace SuperStarTrek { static void Main() { - var foo = Utils.DirectionAndDistance.From(1,1).To(4,5); - var game = new Game(); + var output = new Output(); + var input = new Input(output); + var random = new Random(); + + var game = new Game(output, input, random); game.DoIntroduction(); diff --git a/84 Super Star Trek/csharp/Random.cs b/84 Super Star Trek/csharp/Random.cs index 5ed47805..ae51d95b 100644 --- a/84 Super Star Trek/csharp/Random.cs +++ b/84 Super Star Trek/csharp/Random.cs @@ -6,20 +6,20 @@ namespace SuperStarTrek { private static readonly System.Random _random = new(); - public Coordinates GetCoordinate() => new Coordinates(Get1To8Inclusive() - 1, Get1To8Inclusive() - 1); + internal Coordinates GetCoordinate() => new Coordinates(Get1To8Inclusive() - 1, Get1To8Inclusive() - 1); // Duplicates the algorithm used in the original code to get an integer value from 1 to 8, inclusive: // 475 DEF FNR(R)=INT(RND(R)*7.98+1.01) // Returns a value from 1 to 8, inclusive. // Note there's a slight bias away from the extreme values, 1 and 8. - public int Get1To8Inclusive() => (int)(GetFloat() * 7.98 + 1.01); + internal int Get1To8Inclusive() => (int)(GetFloat() * 7.98 + 1.01); - public int GetInt(int inclusiveMinValue, int exclusiveMaxValue) => + internal int GetInt(int inclusiveMinValue, int exclusiveMaxValue) => _random.Next(inclusiveMinValue, exclusiveMaxValue); - public float GetFloat() => (float)_random.NextDouble(); + internal float GetFloat() => (float)_random.NextDouble(); - public float GetFloat(float inclusiveMinValue, float exclusiveMaxValue) + internal float GetFloat(float inclusiveMinValue, float exclusiveMaxValue) => GetFloat() * (exclusiveMaxValue - inclusiveMinValue) + inclusiveMinValue; } } diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index ddb768ca..fea41521 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -6,31 +6,31 @@ namespace SuperStarTrek.Resources { internal static class Strings { - public static string CombatArea => GetResource(); - public static string ComputerFunctions => GetResource(); - public static string Congratulations => GetResource(); - public static string CourtMartial => GetResource(); - public static string Destroyed => GetResource(); - public static string EndOfMission => GetResource(); - public static string Enterprise => GetResource(); - public static string Instructions => GetResource(); - public static string LowShields => GetResource(); - public static string NoEnemyShips => GetResource(); - public static string NoStarbase => GetResource(); - public static string NowEntering => GetResource(); - public static string Orders => GetResource(); - public static string PermissionDenied => GetResource(); - public static string Protected => GetResource(); - public static string RegionNames => GetResource(); - public static string RelievedOfCommand => GetResource(); - public static string RepairEstimate => GetResource(); - public static string RepairPrompt => GetResource(); - public static string ReplayPrompt => GetResource(); - public static string ShieldsDropped => GetResource(); - public static string ShortRangeSensorsOut => GetResource(); - public static string StartText => GetResource(); - public static string Stranded => GetResource(); - public static string Title => GetResource(); + internal static string CombatArea => GetResource(); + internal static string ComputerFunctions => GetResource(); + internal static string Congratulations => GetResource(); + internal static string CourtMartial => GetResource(); + internal static string Destroyed => GetResource(); + internal static string EndOfMission => GetResource(); + internal static string Enterprise => GetResource(); + internal static string Instructions => GetResource(); + internal static string LowShields => GetResource(); + internal static string NoEnemyShips => GetResource(); + internal static string NoStarbase => GetResource(); + internal static string NowEntering => GetResource(); + internal static string Orders => GetResource(); + internal static string PermissionDenied => GetResource(); + internal static string Protected => GetResource(); + internal static string RegionNames => GetResource(); + internal static string RelievedOfCommand => GetResource(); + internal static string RepairEstimate => GetResource(); + internal static string RepairPrompt => GetResource(); + internal static string ReplayPrompt => GetResource(); + internal static string ShieldsDropped => GetResource(); + internal static string ShortRangeSensorsOut => GetResource(); + internal static string StartText => GetResource(); + internal static string Stranded => GetResource(); + internal static string Title => GetResource(); private static string GetResource([CallerMemberName] string name = "") { diff --git a/84 Super Star Trek/csharp/Space/Coordinates.cs b/84 Super Star Trek/csharp/Space/Coordinates.cs index 1619d387..4c4f7b69 100644 --- a/84 Super Star Trek/csharp/Space/Coordinates.cs +++ b/84 Super Star Trek/csharp/Space/Coordinates.cs @@ -7,7 +7,7 @@ namespace SuperStarTrek.Space // Note that the origin is top-left, x increase downwards, and y increases to the right. internal record Coordinates { - public Coordinates(int x, int y) + internal Coordinates(int x, int y) { X = Validated(x, nameof(x)); Y = Validated(y, nameof(y)); @@ -16,10 +16,10 @@ namespace SuperStarTrek.Space SubRegionIndex = Y % 4; } - public int X { get; } - public int Y { get; } - public int RegionIndex { get; } - public int SubRegionIndex { get; } + internal int X { get; } + internal int Y { get; } + internal int RegionIndex { get; } + internal int SubRegionIndex { get; } private int Validated(int value, string argumentName) { diff --git a/84 Super Star Trek/csharp/Space/Galaxy.cs b/84 Super Star Trek/csharp/Space/Galaxy.cs index 63838567..8fce8fb9 100644 --- a/84 Super Star Trek/csharp/Space/Galaxy.cs +++ b/84 Super Star Trek/csharp/Space/Galaxy.cs @@ -1,7 +1,5 @@ -using System.Collections; using System.Collections.Generic; using System.Linq; -using SuperStarTrek.Objects; using SuperStarTrek.Resources; using static System.StringSplitOptions; @@ -21,7 +19,7 @@ namespace SuperStarTrek.Space _subRegionIdentifiers = new[] { "I", "II", "III", "IV" }; } - public Galaxy(Random random) + internal Galaxy(Random random) { _random = random; @@ -46,16 +44,16 @@ namespace SuperStarTrek.Space } } - public QuadrantInfo this[Coordinates coordinate] => _quadrants[coordinate.X][coordinate.Y]; + internal QuadrantInfo this[Coordinates coordinate] => _quadrants[coordinate.X][coordinate.Y]; - public int KlingonCount => _quadrants.SelectMany(q => q).Sum(q => q.KlingonCount); - public int StarbaseCount => _quadrants.SelectMany(q => q).Count(q => q.HasStarbase); - public IEnumerable> Quadrants => _quadrants; + internal int KlingonCount => _quadrants.SelectMany(q => q).Sum(q => q.KlingonCount); + internal int StarbaseCount => _quadrants.SelectMany(q => q).Count(q => q.HasStarbase); + internal IEnumerable> Quadrants => _quadrants; private static string GetQuadrantName(Coordinates coordinates) => $"{_regionNames[coordinates.RegionIndex]} {_subRegionIdentifiers[coordinates.SubRegionIndex]}"; - public IEnumerable> GetNeighborhood(Quadrant quadrant) => + internal IEnumerable> GetNeighborhood(Quadrant quadrant) => Enumerable.Range(-1, 3) .Select(dx => dx + quadrant.Coordinates.X) .Select(x => GetNeighborhoodRow(quadrant, x)); diff --git a/84 Super Star Trek/csharp/Space/Quadrant.cs b/84 Super Star Trek/csharp/Space/Quadrant.cs index b333cb7e..0ed2a567 100644 --- a/84 Super Star Trek/csharp/Space/Quadrant.cs +++ b/84 Super Star Trek/csharp/Space/Quadrant.cs @@ -16,7 +16,7 @@ namespace SuperStarTrek.Space private readonly Output _output; private bool _displayed = false; - public Quadrant( + internal Quadrant( QuadrantInfo info, Enterprise enterprise, Random random, @@ -39,13 +39,13 @@ namespace SuperStarTrek.Space PositionObject(_ => new Star(), _info.StarCount); } - public Coordinates Coordinates => _info.Coordinates; - public bool HasKlingons => _info.KlingonCount > 0; - public int KlingonCount => _info.KlingonCount; - public bool HasStarbase => _info.HasStarbase; - public Starbase Starbase { get; } + internal Coordinates Coordinates => _info.Coordinates; + internal bool HasKlingons => _info.KlingonCount > 0; + internal int KlingonCount => _info.KlingonCount; + internal bool HasStarbase => _info.HasStarbase; + internal Starbase Starbase { get; } internal Galaxy Galaxy { get; } - public bool EnterpriseIsNextToStarbase => + internal bool EnterpriseIsNextToStarbase => _info.HasStarbase && Math.Abs(_enterprise.SectorCoordinates.X - Starbase.Sector.X) <= 1 && Math.Abs(_enterprise.SectorCoordinates.Y - Starbase.Sector.Y) <= 1; @@ -166,10 +166,10 @@ namespace SuperStarTrek.Space } } - public IEnumerable GetDisplayLines() => Enumerable.Range(0, 8).Select(x => GetDisplayLine(x)); + internal IEnumerable GetDisplayLines() => Enumerable.Range(0, 8).Select(x => GetDisplayLine(x)); - private string GetDisplayLine(int x) - => string.Join( + private string GetDisplayLine(int x) => + string.Join( " ", Enumerable .Range(0, 8) diff --git a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs index 70447250..e37a1a9c 100644 --- a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs +++ b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs @@ -1,5 +1,3 @@ -using SuperStarTrek.Objects; - namespace SuperStarTrek.Space { internal class QuadrantInfo @@ -15,13 +13,13 @@ namespace SuperStarTrek.Space HasStarbase = hasStarbase; } - public Coordinates Coordinates { get; } - public string Name { get; } - public int KlingonCount { get; private set; } - public bool HasStarbase { get; private set; } - public int StarCount { get; } + internal Coordinates Coordinates { get; } + internal string Name { get; } + internal int KlingonCount { get; private set; } + internal bool HasStarbase { get; private set; } + internal int StarCount { get; } - public static QuadrantInfo Create(Coordinates coordinates, string name) + internal static QuadrantInfo Create(Coordinates coordinates, string name) { var random = new Random(); var klingonCount = random.GetFloat() switch diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs index ff6239ed..f59865a0 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; using SuperStarTrek.Objects; using SuperStarTrek.Space; @@ -11,7 +8,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions private readonly Enterprise _enterprise; private readonly Input _input; - public DirectionDistanceCalculator(Enterprise enterprise, Output output, Input input) + internal DirectionDistanceCalculator(Enterprise enterprise, Output output, Input input) : base("Starbase nav data", output) { _enterprise = enterprise; diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/GalacticReport.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/GalacticReport.cs index 8b26cc2e..8be29baf 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/GalacticReport.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/GalacticReport.cs @@ -6,7 +6,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions { internal abstract class GalacticReport : ComputerFunction { - public GalacticReport(string description, Output output, Galaxy galaxy) + internal GalacticReport(string description, Output output, Galaxy galaxy) : base(description, output) { Galaxy = galaxy; diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/StarbaseDataCalculator.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/StarbaseDataCalculator.cs index 0d2c5b50..7a87f970 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/StarbaseDataCalculator.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/StarbaseDataCalculator.cs @@ -8,7 +8,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions { private readonly Enterprise _enterprise; - public StarbaseDataCalculator(Enterprise enterprise, Output output) + internal StarbaseDataCalculator(Enterprise enterprise, Output output) : base("Starbase nav data", output) { _enterprise = enterprise; diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/StatusReport.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/StatusReport.cs index f80ba7bb..26a299a8 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/StatusReport.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/StatusReport.cs @@ -10,7 +10,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions private readonly Galaxy _galaxy; private readonly Enterprise _enterprise; - public StatusReport(Game game, Galaxy galaxy, Enterprise enterprise, Output output) + internal StatusReport(Game game, Galaxy galaxy, Enterprise enterprise, Output output) : base("Status report", output) { _game = game; diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/TorpedoDataCalculator.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/TorpedoDataCalculator.cs index 09c71859..ec837fc4 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/TorpedoDataCalculator.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/TorpedoDataCalculator.cs @@ -8,7 +8,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions { private readonly Enterprise _enterprise; - public TorpedoDataCalculator(Enterprise enterprise, Output output) + internal TorpedoDataCalculator(Enterprise enterprise, Output output) : base("Photon torpedo data", output) { _enterprise = enterprise; diff --git a/84 Super Star Trek/csharp/Systems/DamageControl.cs b/84 Super Star Trek/csharp/Systems/DamageControl.cs index 6ce41bbe..8fbf21d3 100644 --- a/84 Super Star Trek/csharp/Systems/DamageControl.cs +++ b/84 Super Star Trek/csharp/Systems/DamageControl.cs @@ -9,7 +9,7 @@ namespace SuperStarTrek.Systems private readonly Enterprise _enterprise; private readonly Output _output; - public DamageControl(Enterprise enterprise, Output output) + internal DamageControl(Enterprise enterprise, Output output) : base("Damage Control", Command.DAM, output) { _enterprise = enterprise; @@ -40,7 +40,7 @@ namespace SuperStarTrek.Systems return CommandResult.Ok; } - public void WriteDamageReport() + internal void WriteDamageReport() { _output.NextLine().WriteLine("Device State of Repair"); foreach (var system in _enterprise.Systems) diff --git a/84 Super Star Trek/csharp/Systems/LibraryComputer.cs b/84 Super Star Trek/csharp/Systems/LibraryComputer.cs index b2e47d2a..df5c6868 100644 --- a/84 Super Star Trek/csharp/Systems/LibraryComputer.cs +++ b/84 Super Star Trek/csharp/Systems/LibraryComputer.cs @@ -10,7 +10,7 @@ namespace SuperStarTrek.Systems private readonly Input _input; private readonly ComputerFunction[] _functions; - public LibraryComputer(Output output, Input input, params ComputerFunction[] functions) + internal LibraryComputer(Output output, Input input, params ComputerFunction[] functions) : base("Library-Computer", Command.COM, output) { _output = output; diff --git a/84 Super Star Trek/csharp/Systems/LongRangeSensors.cs b/84 Super Star Trek/csharp/Systems/LongRangeSensors.cs index 84ed7a87..a873eeba 100644 --- a/84 Super Star Trek/csharp/Systems/LongRangeSensors.cs +++ b/84 Super Star Trek/csharp/Systems/LongRangeSensors.cs @@ -1,10 +1,5 @@ - -using System; -using System.Collections.Generic; using System.Linq; using SuperStarTrek.Commands; -using SuperStarTrek.Objects; -using SuperStarTrek.Resources; using SuperStarTrek.Space; namespace SuperStarTrek.Systems @@ -14,7 +9,7 @@ namespace SuperStarTrek.Systems private readonly Galaxy _galaxy; private readonly Output _output; - public LongRangeSensors(Galaxy galaxy, Output output) + internal LongRangeSensors(Galaxy galaxy, Output output) : base("Long Range Sensors", Command.LRS, output) { _galaxy = galaxy; diff --git a/84 Super Star Trek/csharp/Systems/PhaserControl.cs b/84 Super Star Trek/csharp/Systems/PhaserControl.cs index 18566294..9207ad94 100644 --- a/84 Super Star Trek/csharp/Systems/PhaserControl.cs +++ b/84 Super Star Trek/csharp/Systems/PhaserControl.cs @@ -13,7 +13,7 @@ namespace SuperStarTrek.Systems private readonly Input _input; private readonly Random _random; - public PhaserControl(Enterprise enterprise, Output output, Input input, Random random) + internal PhaserControl(Enterprise enterprise, Output output, Input input, Random random) : base("Phaser Control", Command.PHA, output) { _enterprise = enterprise; diff --git a/84 Super Star Trek/csharp/Systems/PhotonTubes.cs b/84 Super Star Trek/csharp/Systems/PhotonTubes.cs index a807d16c..37613037 100644 --- a/84 Super Star Trek/csharp/Systems/PhotonTubes.cs +++ b/84 Super Star Trek/csharp/Systems/PhotonTubes.cs @@ -11,7 +11,7 @@ namespace SuperStarTrek.Systems private readonly Output _output; private readonly Input _input; - public PhotonTubes(int tubeCount, Enterprise enterprise, Output output, Input input) + internal PhotonTubes(int tubeCount, Enterprise enterprise, Output output, Input input) : base("Photon Tubes", Command.TOR, output) { TorpedoCount = _tubeCount = tubeCount; @@ -20,7 +20,7 @@ namespace SuperStarTrek.Systems _input = input; } - public int TorpedoCount { get; private set; } + internal int TorpedoCount { get; private set; } protected override bool CanExecuteCommand() => HasTorpedoes() && IsOperational("{name} are not operational"); diff --git a/84 Super Star Trek/csharp/Systems/ShieldControl.cs b/84 Super Star Trek/csharp/Systems/ShieldControl.cs index a7518359..df42c125 100644 --- a/84 Super Star Trek/csharp/Systems/ShieldControl.cs +++ b/84 Super Star Trek/csharp/Systems/ShieldControl.cs @@ -10,7 +10,7 @@ namespace SuperStarTrek.Systems private readonly Output _output; private readonly Input _input; - public ShieldControl(Enterprise enterprise, Output output, Input input) + internal ShieldControl(Enterprise enterprise, Output output, Input input) : base("Shield Control", Command.SHE, output) { _enterprise = enterprise; @@ -18,7 +18,7 @@ namespace SuperStarTrek.Systems _input = input; } - public float ShieldEnergy { get; set; } + internal float ShieldEnergy { get; set; } protected override bool CanExecuteCommand() => IsOperational("{name} inoperable"); diff --git a/84 Super Star Trek/csharp/Systems/ShortRangeSensors.cs b/84 Super Star Trek/csharp/Systems/ShortRangeSensors.cs index ad3929d1..c37028cb 100644 --- a/84 Super Star Trek/csharp/Systems/ShortRangeSensors.cs +++ b/84 Super Star Trek/csharp/Systems/ShortRangeSensors.cs @@ -16,7 +16,7 @@ namespace SuperStarTrek.Systems private readonly Game _game; private readonly Output _output; - public ShortRangeSensors(Enterprise enterprise, Galaxy galaxy, Game game, Output output) + internal ShortRangeSensors(Enterprise enterprise, Galaxy galaxy, Game game, Output output) : base("Short Range Sensors", Command.SRS, output) { _enterprise = enterprise; @@ -47,7 +47,7 @@ namespace SuperStarTrek.Systems return CommandResult.Ok; } - public IEnumerable GetStatusLines() + internal IEnumerable GetStatusLines() { yield return $"Stardate {_game.Stardate}"; yield return $"Condition {_enterprise.Condition}"; diff --git a/84 Super Star Trek/csharp/Systems/Subsystem.cs b/84 Super Star Trek/csharp/Systems/Subsystem.cs index 9e5f3570..2e11e3e7 100644 --- a/84 Super Star Trek/csharp/Systems/Subsystem.cs +++ b/84 Super Star Trek/csharp/Systems/Subsystem.cs @@ -1,4 +1,3 @@ -using System; using SuperStarTrek.Commands; using SuperStarTrek.Space; @@ -16,10 +15,10 @@ namespace SuperStarTrek.Systems _output = output; } - public string Name { get; } - public float Condition { get; private set; } - public bool IsDamaged => Condition < 0; - public Command Command { get; } + internal string Name { get; } + internal float Condition { get; private set; } + internal bool IsDamaged => Condition < 0; + internal Command Command { get; } protected virtual bool CanExecuteCommand() => true; @@ -34,12 +33,12 @@ namespace SuperStarTrek.Systems return true; } - public CommandResult ExecuteCommand(Quadrant quadrant) + internal CommandResult ExecuteCommand(Quadrant quadrant) => CanExecuteCommand() ? ExecuteCommandCore(quadrant) : CommandResult.Ok; protected abstract CommandResult ExecuteCommandCore(Quadrant quadrant); - public virtual void Repair() + internal virtual void Repair() { if (IsDamaged) { @@ -47,7 +46,7 @@ namespace SuperStarTrek.Systems } } - public virtual bool Repair(float repairWorkDone) + internal virtual bool Repair(float repairWorkDone) { if (IsDamaged) { diff --git a/84 Super Star Trek/csharp/Systems/WarpEngines.cs b/84 Super Star Trek/csharp/Systems/WarpEngines.cs index 0dcf396c..4203f4e8 100644 --- a/84 Super Star Trek/csharp/Systems/WarpEngines.cs +++ b/84 Super Star Trek/csharp/Systems/WarpEngines.cs @@ -11,7 +11,7 @@ namespace SuperStarTrek.Systems private readonly Output _output; private readonly Input _input; - public WarpEngines(Enterprise enterprise, Output output, Input input) + internal WarpEngines(Enterprise enterprise, Output output, Input input) : base("Warp Engines", Command.NAV, output) { _enterprise = enterprise; diff --git a/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs b/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs index 3fa9f4b8..65cb6a30 100644 --- a/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs +++ b/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs @@ -14,13 +14,13 @@ namespace SuperStarTrek.Utils _fromY = fromY; } - public static DirectionAndDistance From(Coordinates coordinates) => From(coordinates.X, coordinates.Y); + internal static DirectionAndDistance From(Coordinates coordinates) => From(coordinates.X, coordinates.Y); - public static DirectionAndDistance From(float x, float y) => new DirectionAndDistance(x, y); + internal static DirectionAndDistance From(float x, float y) => new DirectionAndDistance(x, y); - public (float Direction, float Distance) To(Coordinates coordinates) => To(coordinates.X, coordinates.Y); + internal (float Direction, float Distance) To(Coordinates coordinates) => To(coordinates.X, coordinates.Y); - public (float Direction, float Distance) To(float x, float y) + internal (float Direction, float Distance) To(float x, float y) { var deltaX = x - _fromX; var deltaY = y - _fromY; From 2aee62dd476b813eeeb986b5d869b66f4e31536c Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:31:53 +1000 Subject: [PATCH 05/15] Fix compiler messages --- 84 Super Star Trek/csharp/Random.cs | 2 +- 84 Super Star Trek/csharp/Resources/Strings.cs | 4 +--- 84 Super Star Trek/csharp/Space/Coordinates.cs | 2 +- 84 Super Star Trek/csharp/Space/Course.cs | 2 +- 84 Super Star Trek/csharp/Space/Galaxy.cs | 3 --- 84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs | 4 ++-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/84 Super Star Trek/csharp/Random.cs b/84 Super Star Trek/csharp/Random.cs index ae51d95b..cd0ef230 100644 --- a/84 Super Star Trek/csharp/Random.cs +++ b/84 Super Star Trek/csharp/Random.cs @@ -4,7 +4,7 @@ namespace SuperStarTrek { internal class Random { - private static readonly System.Random _random = new(); + private readonly System.Random _random = new(); internal Coordinates GetCoordinate() => new Coordinates(Get1To8Inclusive() - 1, Get1To8Inclusive() - 1); diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index fea41521..72fd7d5a 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -35,9 +35,7 @@ namespace SuperStarTrek.Resources private static string GetResource([CallerMemberName] string name = "") { var streamName = $"SuperStarTrek.Resources.{name}.txt"; - using var stream = Assembly - .GetExecutingAssembly() - .GetManifestResourceStream(streamName); + using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(streamName); using var reader = new StreamReader(stream); return reader.ReadToEnd(); diff --git a/84 Super Star Trek/csharp/Space/Coordinates.cs b/84 Super Star Trek/csharp/Space/Coordinates.cs index 4c4f7b69..4bcc8085 100644 --- a/84 Super Star Trek/csharp/Space/Coordinates.cs +++ b/84 Super Star Trek/csharp/Space/Coordinates.cs @@ -21,7 +21,7 @@ namespace SuperStarTrek.Space internal int RegionIndex { get; } internal int SubRegionIndex { get; } - private int Validated(int value, string argumentName) + private static int Validated(int value, string argumentName) { if (value >= 0 && value <= 7) { return value; } diff --git a/84 Super Star Trek/csharp/Space/Course.cs b/84 Super Star Trek/csharp/Space/Course.cs index a46385c3..7067ec81 100644 --- a/84 Super Star Trek/csharp/Space/Course.cs +++ b/84 Super Star Trek/csharp/Space/Course.cs @@ -74,7 +74,7 @@ namespace SuperStarTrek.Space return (xComplete && yComplete, new Coordinates(quadrantX, quadrantY), new Coordinates(sectorX, sectorY)); } - private (bool, int, int) GetNewCoordinate(int quadrant, int sector, float sectorsTravelled) + private static (bool, int, int) GetNewCoordinate(int quadrant, int sector, float sectorsTravelled) { var galacticCoordinate = quadrant * 8 + sector + sectorsTravelled; var newQuadrant = (int)(galacticCoordinate / 8); diff --git a/84 Super Star Trek/csharp/Space/Galaxy.cs b/84 Super Star Trek/csharp/Space/Galaxy.cs index 8fce8fb9..66f7c418 100644 --- a/84 Super Star Trek/csharp/Space/Galaxy.cs +++ b/84 Super Star Trek/csharp/Space/Galaxy.cs @@ -11,7 +11,6 @@ namespace SuperStarTrek.Space private static readonly string[] _regionNames; private static readonly string[] _subRegionIdentifiers; private readonly QuadrantInfo[][] _quadrants; - private readonly Random _random; static Galaxy() { @@ -21,8 +20,6 @@ namespace SuperStarTrek.Space internal Galaxy(Random random) { - _random = random; - _quadrants = Enumerable .Range(0, 8) .Select(x => Enumerable diff --git a/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs b/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs index 65cb6a30..e4b1a2fa 100644 --- a/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs +++ b/84 Super Star Trek/csharp/Utils/DirectionAndDistance.cs @@ -45,7 +45,7 @@ namespace SuperStarTrek.Utils // 8430 PRINT"DIRECTION =";C1+(((ABS(X)-ABS(A))+ABS(X))/ABS(X)):GOTO8460 // 8450 PRINT"DIRECTION =";C1+(ABS(X)/ABS(A)) // 8460 PRINT"DISTANCE =";SQR(X^2+A^2):IFH8=1THEN1990 - private float GetDirection(float deltaX, float deltaY) + private static float GetDirection(float deltaX, float deltaY) { var deltaXDominant = Math.Abs(deltaX) > Math.Abs(deltaY); var fractionalPart = deltaXDominant ? deltaY / deltaX : -deltaX / deltaY; @@ -59,7 +59,7 @@ namespace SuperStarTrek.Utils return direction < 1 ? direction + 8 : direction; } - private float GetDistance(float deltaX, float deltaY) => + private static float GetDistance(float deltaX, float deltaY) => (float)Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); } } \ No newline at end of file From 99a847813c56964e440b6dea4f54440c5c364216 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:39:21 +1000 Subject: [PATCH 06/15] Inject Random into QuadrantInfo --- 84 Super Star Trek/csharp/Space/Galaxy.cs | 2 +- 84 Super Star Trek/csharp/Space/QuadrantInfo.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/84 Super Star Trek/csharp/Space/Galaxy.cs b/84 Super Star Trek/csharp/Space/Galaxy.cs index 66f7c418..91961b38 100644 --- a/84 Super Star Trek/csharp/Space/Galaxy.cs +++ b/84 Super Star Trek/csharp/Space/Galaxy.cs @@ -25,7 +25,7 @@ namespace SuperStarTrek.Space .Select(x => Enumerable .Range(0, 8) .Select(y => new Coordinates(x, y)) - .Select(c => QuadrantInfo.Create(c, GetQuadrantName(c))) + .Select(c => QuadrantInfo.Create(c, GetQuadrantName(c), random)) .ToArray()) .ToArray(); diff --git a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs index e37a1a9c..31626a35 100644 --- a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs +++ b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs @@ -19,9 +19,8 @@ namespace SuperStarTrek.Space internal bool HasStarbase { get; private set; } internal int StarCount { get; } - internal static QuadrantInfo Create(Coordinates coordinates, string name) + internal static QuadrantInfo Create(Coordinates coordinates, string name, Random random) { - var random = new Random(); var klingonCount = random.GetFloat() switch { > 0.98f => 3, From 0f795c07250f82c37c0f95e2583455c71a8605e3 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:44:43 +1000 Subject: [PATCH 07/15] Normalise member spacing --- 84 Super Star Trek/csharp/Game.cs | 1 + 84 Super Star Trek/csharp/Objects/Klingon.cs | 1 + 84 Super Star Trek/csharp/Objects/Starbase.cs | 1 + .../csharp/Resources/Strings.cs | 24 +++++++++++++++++++ .../csharp/Space/Coordinates.cs | 3 +++ 84 Super Star Trek/csharp/Space/Course.cs | 1 + 84 Super Star Trek/csharp/Space/Galaxy.cs | 2 ++ 84 Super Star Trek/csharp/Space/Quadrant.cs | 6 +++++ .../csharp/Space/QuadrantInfo.cs | 4 ++++ .../ComputerFunctions/ComputerFunction.cs | 1 + .../csharp/Systems/Subsystem.cs | 3 +++ 11 files changed, 47 insertions(+) diff --git a/84 Super Star Trek/csharp/Game.cs b/84 Super Star Trek/csharp/Game.cs index 96261498..92c16a83 100644 --- a/84 Super Star Trek/csharp/Game.cs +++ b/84 Super Star Trek/csharp/Game.cs @@ -29,6 +29,7 @@ namespace SuperStarTrek } internal float Stardate => _currentStardate; + internal float StardatesRemaining => _finalStarDate - _currentStardate; internal void DoIntroduction() diff --git a/84 Super Star Trek/csharp/Objects/Klingon.cs b/84 Super Star Trek/csharp/Objects/Klingon.cs index 78c307e5..1b55940a 100644 --- a/84 Super Star Trek/csharp/Objects/Klingon.cs +++ b/84 Super Star Trek/csharp/Objects/Klingon.cs @@ -15,6 +15,7 @@ namespace SuperStarTrek.Objects } internal float Energy { get; private set; } + internal Coordinates Sector { get; private set; } public override string ToString() => "+K+"; diff --git a/84 Super Star Trek/csharp/Objects/Starbase.cs b/84 Super Star Trek/csharp/Objects/Starbase.cs index 1ef4a85e..c9abb870 100644 --- a/84 Super Star Trek/csharp/Objects/Starbase.cs +++ b/84 Super Star Trek/csharp/Objects/Starbase.cs @@ -18,6 +18,7 @@ namespace SuperStarTrek.Objects } internal Coordinates Sector { get; } + public override string ToString() => ">!<"; internal bool TryRepair(Enterprise enterprise, out float repairTime) diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index 72fd7d5a..c3dcedf6 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -7,29 +7,53 @@ namespace SuperStarTrek.Resources internal static class Strings { internal static string CombatArea => GetResource(); + internal static string ComputerFunctions => GetResource(); + internal static string Congratulations => GetResource(); + internal static string CourtMartial => GetResource(); + internal static string Destroyed => GetResource(); + internal static string EndOfMission => GetResource(); + internal static string Enterprise => GetResource(); + internal static string Instructions => GetResource(); + internal static string LowShields => GetResource(); + internal static string NoEnemyShips => GetResource(); + internal static string NoStarbase => GetResource(); + internal static string NowEntering => GetResource(); + internal static string Orders => GetResource(); + internal static string PermissionDenied => GetResource(); + internal static string Protected => GetResource(); + internal static string RegionNames => GetResource(); + internal static string RelievedOfCommand => GetResource(); + internal static string RepairEstimate => GetResource(); + internal static string RepairPrompt => GetResource(); + internal static string ReplayPrompt => GetResource(); + internal static string ShieldsDropped => GetResource(); + internal static string ShortRangeSensorsOut => GetResource(); + internal static string StartText => GetResource(); + internal static string Stranded => GetResource(); + internal static string Title => GetResource(); private static string GetResource([CallerMemberName] string name = "") diff --git a/84 Super Star Trek/csharp/Space/Coordinates.cs b/84 Super Star Trek/csharp/Space/Coordinates.cs index 4bcc8085..7aec927f 100644 --- a/84 Super Star Trek/csharp/Space/Coordinates.cs +++ b/84 Super Star Trek/csharp/Space/Coordinates.cs @@ -17,8 +17,11 @@ namespace SuperStarTrek.Space } internal int X { get; } + internal int Y { get; } + internal int RegionIndex { get; } + internal int SubRegionIndex { get; } private static int Validated(int value, string argumentName) diff --git a/84 Super Star Trek/csharp/Space/Course.cs b/84 Super Star Trek/csharp/Space/Course.cs index 7067ec81..6418b15b 100644 --- a/84 Super Star Trek/csharp/Space/Course.cs +++ b/84 Super Star Trek/csharp/Space/Course.cs @@ -46,6 +46,7 @@ namespace SuperStarTrek.Space } internal float DeltaX { get; } + internal float DeltaY { get; } internal IEnumerable GetSectorsFrom(Coordinates start) diff --git a/84 Super Star Trek/csharp/Space/Galaxy.cs b/84 Super Star Trek/csharp/Space/Galaxy.cs index 91961b38..0b348b06 100644 --- a/84 Super Star Trek/csharp/Space/Galaxy.cs +++ b/84 Super Star Trek/csharp/Space/Galaxy.cs @@ -44,7 +44,9 @@ namespace SuperStarTrek.Space internal QuadrantInfo this[Coordinates coordinate] => _quadrants[coordinate.X][coordinate.Y]; internal int KlingonCount => _quadrants.SelectMany(q => q).Sum(q => q.KlingonCount); + internal int StarbaseCount => _quadrants.SelectMany(q => q).Count(q => q.HasStarbase); + internal IEnumerable> Quadrants => _quadrants; private static string GetQuadrantName(Coordinates coordinates) => diff --git a/84 Super Star Trek/csharp/Space/Quadrant.cs b/84 Super Star Trek/csharp/Space/Quadrant.cs index 0ed2a567..29f8e0ce 100644 --- a/84 Super Star Trek/csharp/Space/Quadrant.cs +++ b/84 Super Star Trek/csharp/Space/Quadrant.cs @@ -40,11 +40,17 @@ namespace SuperStarTrek.Space } internal Coordinates Coordinates => _info.Coordinates; + internal bool HasKlingons => _info.KlingonCount > 0; + internal int KlingonCount => _info.KlingonCount; + internal bool HasStarbase => _info.HasStarbase; + internal Starbase Starbase { get; } + internal Galaxy Galaxy { get; } + internal bool EnterpriseIsNextToStarbase => _info.HasStarbase && Math.Abs(_enterprise.SectorCoordinates.X - Starbase.Sector.X) <= 1 && diff --git a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs index 31626a35..6a403c2e 100644 --- a/84 Super Star Trek/csharp/Space/QuadrantInfo.cs +++ b/84 Super Star Trek/csharp/Space/QuadrantInfo.cs @@ -14,9 +14,13 @@ namespace SuperStarTrek.Space } internal Coordinates Coordinates { get; } + internal string Name { get; } + internal int KlingonCount { get; private set; } + internal bool HasStarbase { get; private set; } + internal int StarCount { get; } internal static QuadrantInfo Create(Coordinates coordinates, string name, Random random) diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/ComputerFunction.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/ComputerFunction.cs index 400c1f62..36d9127b 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/ComputerFunction.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/ComputerFunction.cs @@ -11,6 +11,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions } internal string Description { get; } + protected Output Output { get; } internal abstract void Execute(Quadrant quadrant); diff --git a/84 Super Star Trek/csharp/Systems/Subsystem.cs b/84 Super Star Trek/csharp/Systems/Subsystem.cs index 2e11e3e7..5c11e656 100644 --- a/84 Super Star Trek/csharp/Systems/Subsystem.cs +++ b/84 Super Star Trek/csharp/Systems/Subsystem.cs @@ -16,8 +16,11 @@ namespace SuperStarTrek.Systems } internal string Name { get; } + internal float Condition { get; private set; } + internal bool IsDamaged => Condition < 0; + internal Command Command { get; } protected virtual bool CanExecuteCommand() => true; From 315bdc04327ac7f31013de7d603bd18ff29ad4aa Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:48:27 +1000 Subject: [PATCH 08/15] Remove unsed string resource --- .../csharp/Resources/ComputerFunctions.txt | 9 --------- 84 Super Star Trek/csharp/Resources/Strings.cs | 2 -- 2 files changed, 11 deletions(-) delete mode 100644 84 Super Star Trek/csharp/Resources/ComputerFunctions.txt diff --git a/84 Super Star Trek/csharp/Resources/ComputerFunctions.txt b/84 Super Star Trek/csharp/Resources/ComputerFunctions.txt deleted file mode 100644 index 4827b0fe..00000000 --- a/84 Super Star Trek/csharp/Resources/ComputerFunctions.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Functions available from Library-Computer: - 0 = Cumulative galactic record - 1 = Status report - 2 = Photon torpedo data - 3 = Starbase nav data - 4 = Direction/distance calculator - 5 = Galaxy 'region name' map - diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index c3dcedf6..6fd472c1 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -8,8 +8,6 @@ namespace SuperStarTrek.Resources { internal static string CombatArea => GetResource(); - internal static string ComputerFunctions => GetResource(); - internal static string Congratulations => GetResource(); internal static string CourtMartial => GetResource(); From 3165a9226a79ef13ae24cc278d6babaccd1bebce Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 21:51:20 +1000 Subject: [PATCH 09/15] Fix computer function name --- .../Systems/ComputerFunctions/DirectionDistanceCalculator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs b/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs index f59865a0..a3679ada 100644 --- a/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs +++ b/84 Super Star Trek/csharp/Systems/ComputerFunctions/DirectionDistanceCalculator.cs @@ -9,7 +9,7 @@ namespace SuperStarTrek.Systems.ComputerFunctions private readonly Input _input; internal DirectionDistanceCalculator(Enterprise enterprise, Output output, Input input) - : base("Starbase nav data", output) + : base("Direction/distance calculator", output) { _enterprise = enterprise; _input = input; From 471af5bf4079fa9b1344fdbea592bb354c2e8ff4 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 22:02:36 +1000 Subject: [PATCH 10/15] Fix shield set text --- 84 Super Star Trek/csharp/Resources/ShieldsSet.txt | 2 ++ 84 Super Star Trek/csharp/Resources/Strings.cs | 2 ++ 84 Super Star Trek/csharp/Systems/ShieldControl.cs | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 84 Super Star Trek/csharp/Resources/ShieldsSet.txt diff --git a/84 Super Star Trek/csharp/Resources/ShieldsSet.txt b/84 Super Star Trek/csharp/Resources/ShieldsSet.txt new file mode 100644 index 00000000..e3d7efda --- /dev/null +++ b/84 Super Star Trek/csharp/Resources/ShieldsSet.txt @@ -0,0 +1,2 @@ +Deflector control room report: + 'Shields now at {0} units per your command.' diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index 6fd472c1..b6cd5486 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -46,6 +46,8 @@ namespace SuperStarTrek.Resources internal static string ShieldsDropped => GetResource(); + internal static string ShieldsSet => GetResource(); + internal static string ShortRangeSensorsOut => GetResource(); internal static string StartText => GetResource(); diff --git a/84 Super Star Trek/csharp/Systems/ShieldControl.cs b/84 Super Star Trek/csharp/Systems/ShieldControl.cs index df42c125..de4f44d9 100644 --- a/84 Super Star Trek/csharp/Systems/ShieldControl.cs +++ b/84 Super Star Trek/csharp/Systems/ShieldControl.cs @@ -1,5 +1,6 @@ using SuperStarTrek.Commands; using SuperStarTrek.Objects; +using SuperStarTrek.Resources; using SuperStarTrek.Space; namespace SuperStarTrek.Systems @@ -30,6 +31,7 @@ namespace SuperStarTrek.Systems if (Validate(requested)) { ShieldEnergy = requested; + _output.Write(Strings.ShieldsSet, requested); } else { From 1c1eead60a422935f4d13aac5e668a4f419d3e12 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 22:04:49 +1000 Subject: [PATCH 11/15] Fix "Now entering ..." text spacing --- 84 Super Star Trek/csharp/Resources/NowEntering.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/84 Super Star Trek/csharp/Resources/NowEntering.txt b/84 Super Star Trek/csharp/Resources/NowEntering.txt index 915b526f..6545f9c4 100644 --- a/84 Super Star Trek/csharp/Resources/NowEntering.txt +++ b/84 Super Star Trek/csharp/Resources/NowEntering.txt @@ -1,2 +1,3 @@ + Now entering {0} quadrant . . . From f3fce146e5e11aeefea400c63c31756a9d256de6 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 22:24:11 +1000 Subject: [PATCH 12/15] Fix display of quadrant after move --- 84 Super Star Trek/csharp/Game.cs | 2 -- 84 Super Star Trek/csharp/Space/Quadrant.cs | 12 ++++++------ 84 Super Star Trek/csharp/Systems/WarpEngines.cs | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/84 Super Star Trek/csharp/Game.cs b/84 Super Star Trek/csharp/Game.cs index 92c16a83..274e2948 100644 --- a/84 Super Star Trek/csharp/Game.cs +++ b/84 Super Star Trek/csharp/Game.cs @@ -51,8 +51,6 @@ namespace SuperStarTrek while (!gameOver) { - _enterprise.Quadrant.Display(Strings.NowEntering); - var command = _input.GetCommand(); var result = _enterprise.Execute(command); diff --git a/84 Super Star Trek/csharp/Space/Quadrant.cs b/84 Super Star Trek/csharp/Space/Quadrant.cs index 29f8e0ce..694f7fc8 100644 --- a/84 Super Star Trek/csharp/Space/Quadrant.cs +++ b/84 Super Star Trek/csharp/Space/Quadrant.cs @@ -14,7 +14,7 @@ namespace SuperStarTrek.Space private readonly Dictionary _sectors; private readonly Enterprise _enterprise; private readonly Output _output; - private bool _displayed = false; + private bool _entered = false; internal Quadrant( QuadrantInfo info, @@ -77,9 +77,11 @@ namespace SuperStarTrek.Space internal void Display(string textFormat) { - if (_displayed) { return; } - - _output.Write(textFormat, this); + if (!_entered) + { + _output.Write(textFormat, this); + _entered = true; + } if (_info.KlingonCount > 0) { @@ -88,8 +90,6 @@ namespace SuperStarTrek.Space } _enterprise.Execute(Command.SRS); - - _displayed = true; } internal bool HasObjectAt(Coordinates coordinates) => _sectors.ContainsKey(coordinates); diff --git a/84 Super Star Trek/csharp/Systems/WarpEngines.cs b/84 Super Star Trek/csharp/Systems/WarpEngines.cs index 4203f4e8..096d0e43 100644 --- a/84 Super Star Trek/csharp/Systems/WarpEngines.cs +++ b/84 Super Star Trek/csharp/Systems/WarpEngines.cs @@ -1,6 +1,7 @@ using System; using SuperStarTrek.Commands; using SuperStarTrek.Objects; +using SuperStarTrek.Resources; using SuperStarTrek.Space; namespace SuperStarTrek.Systems @@ -39,6 +40,8 @@ namespace SuperStarTrek.Systems _enterprise.PhotonTubes.ReplenishTorpedoes(); } + _enterprise.Quadrant.Display(Strings.NowEntering); + return CommandResult.Elapsed(timeElapsed); } From 8169f1e64a8ab100badeda0816ee99f04538332a Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 22:29:39 +1000 Subject: [PATCH 13/15] Fix "Shields dropped..." text spacing --- 84 Super Star Trek/csharp/Resources/ShieldsDropped.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/84 Super Star Trek/csharp/Resources/ShieldsDropped.txt b/84 Super Star Trek/csharp/Resources/ShieldsDropped.txt index acc87f59..9135e8b4 100644 --- a/84 Super Star Trek/csharp/Resources/ShieldsDropped.txt +++ b/84 Super Star Trek/csharp/Resources/ShieldsDropped.txt @@ -1 +1 @@ -Shields dropped for docking purposes +Shields dropped for docking purposes \ No newline at end of file From 94c0d2398318d1e57ce163f79edefa5050aa9229 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 23:00:36 +1000 Subject: [PATCH 14/15] Fix error when navigating out of bounds --- 84 Super Star Trek/csharp/Space/Course.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/84 Super Star Trek/csharp/Space/Course.cs b/84 Super Star Trek/csharp/Space/Course.cs index 6418b15b..b316e4b3 100644 --- a/84 Super Star Trek/csharp/Space/Course.cs +++ b/84 Super Star Trek/csharp/Space/Course.cs @@ -81,10 +81,10 @@ namespace SuperStarTrek.Space var newQuadrant = (int)(galacticCoordinate / 8); var newSector = (int)(galacticCoordinate - newQuadrant * 8); - if (newSector == -1) + if (newSector < 0) { newQuadrant -= 1; - newSector = 7; + newSector += 8; } return newQuadrant switch From 4a82dd2198a5fb81d89ec392fefbac3712aa8b35 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 15 Apr 2021 23:02:40 +1000 Subject: [PATCH 15/15] Fix display of Docked status --- 84 Super Star Trek/csharp/Objects/Enterprise.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/84 Super Star Trek/csharp/Objects/Enterprise.cs b/84 Super Star Trek/csharp/Objects/Enterprise.cs index 2f587631..ac9e8112 100644 --- a/84 Super Star Trek/csharp/Objects/Enterprise.cs +++ b/84 Super Star Trek/csharp/Objects/Enterprise.cs @@ -71,11 +71,12 @@ namespace SuperStarTrek.Objects } private string GetCondition() => - (_quadrant.HasKlingons, Energy / _maxEnergy) switch + IsDocked switch { - (true, _) => "*Red*", - (_, < 0.1f) => "Yellow", - _ => "Green" + true => "Docked", + false when _quadrant.HasKlingons => "*Red*", + false when Energy / _maxEnergy < 0.1f => "Yellow", + false => "Green" }; internal CommandResult Execute(Command command)