From 7c9c5fb26a43a490d7a9574749dab9b6b0757c4a Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 21 Sep 2018 17:17:49 +0100 Subject: [PATCH] function loading for USSR --- .../Physics/BasicPhysics.cs | 15 ++++ .../Physics/PhysicsControler.cs | 42 ---------- .../Physics/PhysicsController.cs | 78 +++++++++++++++++++ .../universal-science-solver/UI.cs | 17 ++-- .../universal-science-solver.csproj | 3 +- 5 files changed, 106 insertions(+), 49 deletions(-) create mode 100644 C#/Universal Science Solver and Resolver/universal-science-solver/Physics/BasicPhysics.cs delete mode 100644 C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsControler.cs create mode 100644 C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsController.cs diff --git a/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/BasicPhysics.cs b/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/BasicPhysics.cs new file mode 100644 index 0000000..03569fe --- /dev/null +++ b/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/BasicPhysics.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace universal_science_solver.Physics { + class BasicPhysics { + public static void SpeedDistanceTime() { + Console.WriteLine("Calculate distance, speed or time"); + + + } + } +} diff --git a/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsControler.cs b/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsControler.cs deleted file mode 100644 index 1b9dbcc..0000000 --- a/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsControler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace universal_science_solver.Physics { - class PhysicsControler { - - public enum Topic : byte { - USELECTED, - BASICS, - MECHANICS, - WAVES - } - - public static IList ModeList = new List(); - - public static void Initializer() { - ModeList.Add(new Mode("Speed distance time", Topic.BASICS, "Calculate distance, speed or time")); - } - - public static IList ListModes() { - foreach (Mode mode in ModeList) { - Console.WriteLine(mode.Title); - } - return ModeList; - } - } - - class Mode { - public string Title; - public PhysicsControler.Topic Topic; - public string Desc; - - public Mode(string title, PhysicsControler.Topic topic, string desc) { - this.Title = title; - this.Topic = topic; - this.Desc = desc; - } - } -} diff --git a/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsController.cs b/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsController.cs new file mode 100644 index 0000000..5cc3b4b --- /dev/null +++ b/C#/Universal Science Solver and Resolver/universal-science-solver/Physics/PhysicsController.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace universal_science_solver.Physics { + class PhysicsController { + public enum Topic : byte { + USELECTED, + BASICS, + MECHANICS, + WAVES + } + + public static IList ModeList = new List(); + public static Dictionary TopicDictionary = new Dictionary(); + + public static void Initializer() { + TopicDictionary.Add(Topic.USELECTED, "No topic selected"); + TopicDictionary.Add(Topic.BASICS, "Physics basics"); + TopicDictionary.Add(Topic.MECHANICS, "Mechanics"); + TopicDictionary.Add(Topic.WAVES, "Waves"); + + ModeList.Add(new Mode("Speed distance time", Topic.BASICS, "Calculate distance, speed or time", BasicPhysics.SpeedDistanceTime)); + } + + public static void TakeControl() { + Console.WriteLine(); + Console.WriteLine("Available physics modes:"); + listModes(); + selectMode(); + } + + private static void selectMode() { + Console.Write("> "); + var key = Console.ReadKey(); + Console.WriteLine(); + + int index = 0; + try { + index = int.Parse(key.KeyChar.ToString()) - 1; + Mode selected = ModeList[index]; + + Console.WriteLine("Mode [" + selected.Title + "] selected"); + selected.FunctionReference(); + Console.ReadKey(); + + } catch (Exception e) { + Console.WriteLine("You must select a number"); + selectMode(); + } + } + + private static IList listModes() { + for (int i = 0; i < ModeList.Count(); i++) { + Console.Write("(" + (i + 1) + ") "); + Console.Write(ModeList[i].Title); + Console.Write(" in the topic [" + TopicDictionary[ModeList[i].Topic] + "]"); + } + Console.WriteLine(); + return ModeList; + } + } + + class Mode { + public string Title; + public PhysicsController.Topic Topic; + public string Desc; + public Action FunctionReference; + + public Mode(string title, PhysicsController.Topic topic, string desc, Action functionReference) { + this.Title = title; + this.Topic = topic; + this.Desc = desc; + this.FunctionReference = functionReference; + } + } +} diff --git a/C#/Universal Science Solver and Resolver/universal-science-solver/UI.cs b/C#/Universal Science Solver and Resolver/universal-science-solver/UI.cs index 3dc641e..eec29ab 100644 --- a/C#/Universal Science Solver and Resolver/universal-science-solver/UI.cs +++ b/C#/Universal Science Solver and Resolver/universal-science-solver/UI.cs @@ -7,7 +7,7 @@ namespace universal_science_solver { public Modes Mode = Modes.UNSELECTED; private bool isRunning = true; - public enum Modes : byte { + public enum Modes : sbyte { UNSELECTED, PHYSICS, CHEMISTRY, @@ -15,20 +15,25 @@ namespace universal_science_solver { } public UI() { + Console.Clear(); Console.WriteLine("Loading..."); Thread.Sleep(400); - PhysicsControler.Initializer(); - boot(); - eventLoop(); + PhysicsController.Initializer(); + while (isRunning) { + boot(); + eventLoop(); + } } private void boot() { + Mode = Modes.UNSELECTED; Console.Clear(); Console.WriteLine("The Universal Science Solver and Resolver"); Console.WriteLine("Copyright 2018 Benjamin Kyd, Licensed under the MIT license"); Console.WriteLine(); Console.WriteLine("Enter q at any point to return to the menu, Ctrl+C to exit the program at any time"); Console.WriteLine(); + Console.WriteLine("Physics (p), chemistry (c), mathematics (m)"); } private void eventLoop() { @@ -39,13 +44,13 @@ namespace universal_science_solver { } if (Mode == Modes.PHYSICS) { - + PhysicsController.TakeControl(); + return; } } } private void selectMode() { - Console.WriteLine("Physics (p), chemistry (c), mathematics (m)"); Console.Write("> "); var key = Console.ReadKey(); Console.WriteLine(); diff --git a/C#/Universal Science Solver and Resolver/universal-science-solver/universal-science-solver.csproj b/C#/Universal Science Solver and Resolver/universal-science-solver/universal-science-solver.csproj index 0d670b1..f380969 100644 --- a/C#/Universal Science Solver and Resolver/universal-science-solver/universal-science-solver.csproj +++ b/C#/Universal Science Solver and Resolver/universal-science-solver/universal-science-solver.csproj @@ -45,7 +45,8 @@ - + +