function loading for USSR

This commit is contained in:
Ben
2018-09-21 17:17:49 +01:00
parent a3a319859d
commit 7c9c5fb26a
5 changed files with 106 additions and 49 deletions

View File

@@ -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");
}
}
}

View File

@@ -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<Mode> ModeList = new List<Mode>();
public static void Initializer() {
ModeList.Add(new Mode("Speed distance time", Topic.BASICS, "Calculate distance, speed or time"));
}
public static IList<Mode> 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;
}
}
}

View File

@@ -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<Mode> ModeList = new List<Mode>();
public static Dictionary<Topic, string> TopicDictionary = new Dictionary<Topic, string>();
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<Mode> 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;
}
}
}

View File

@@ -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();

View File

@@ -45,7 +45,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Physics\PhysicsControler.cs" />
<Compile Include="Physics\BasicPhysics.cs" />
<Compile Include="Physics\PhysicsController.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI.cs" />