From bd62d4dedcef5938ad887130d2ec3843c2e44736 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 1 Sep 2019 16:46:31 +0300 Subject: Began the oscilloscope project --- Oscilloscope/Oscilloscope.sln | 25 +++++ Oscilloscope/Oscilloscope/App.config | 6 + Oscilloscope/Oscilloscope/Command.cs | 31 ++++++ Oscilloscope/Oscilloscope/Oscilloscope.csproj | 55 ++++++++++ Oscilloscope/Oscilloscope/Program.cs | 32 ++++++ .../Oscilloscope/Properties/AssemblyInfo.cs | 36 ++++++ Oscilloscope/Oscilloscope/Screen.cs | 121 +++++++++++++++++++++ 7 files changed, 306 insertions(+) create mode 100644 Oscilloscope/Oscilloscope.sln create mode 100644 Oscilloscope/Oscilloscope/App.config create mode 100644 Oscilloscope/Oscilloscope/Command.cs create mode 100644 Oscilloscope/Oscilloscope/Oscilloscope.csproj create mode 100644 Oscilloscope/Oscilloscope/Program.cs create mode 100644 Oscilloscope/Oscilloscope/Properties/AssemblyInfo.cs create mode 100644 Oscilloscope/Oscilloscope/Screen.cs diff --git a/Oscilloscope/Oscilloscope.sln b/Oscilloscope/Oscilloscope.sln new file mode 100644 index 0000000..2482a4c --- /dev/null +++ b/Oscilloscope/Oscilloscope.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29102.190 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Oscilloscope", "Oscilloscope\Oscilloscope.csproj", "{36E3F0B2-B785-4AF3-B59F-483FDA57672A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4F0BFF39-C20B-4BA7-8F27-2218F165F21D} + EndGlobalSection +EndGlobal diff --git a/Oscilloscope/Oscilloscope/App.config b/Oscilloscope/Oscilloscope/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Oscilloscope/Oscilloscope/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Oscilloscope/Oscilloscope/Command.cs b/Oscilloscope/Oscilloscope/Command.cs new file mode 100644 index 0000000..c14454d --- /dev/null +++ b/Oscilloscope/Oscilloscope/Command.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Oscilloscope { + class Command { + private static string[] input = new string[2]; + + public static void Do() { + Take(); + Execute(); + } + + private static void Take() { + input = Console.ReadLine().Split(' ').ToArray(); + } + + private static void Execute() { + switch (input[0]) { + case "screen": + Screen.SetValues(input.Skip(1).ToArray()); + break; + case "fps": + Program.Fps = double.Parse(input[1]); + break; + } + } + } +} diff --git a/Oscilloscope/Oscilloscope/Oscilloscope.csproj b/Oscilloscope/Oscilloscope/Oscilloscope.csproj new file mode 100644 index 0000000..de6a2a2 --- /dev/null +++ b/Oscilloscope/Oscilloscope/Oscilloscope.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {36E3F0B2-B785-4AF3-B59F-483FDA57672A} + Exe + Oscilloscope + Oscilloscope + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Oscilloscope/Oscilloscope/Program.cs b/Oscilloscope/Oscilloscope/Program.cs new file mode 100644 index 0000000..ea91a62 --- /dev/null +++ b/Oscilloscope/Oscilloscope/Program.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Oscilloscope +{ + class Program + { + public static double Fps = 100; + + static void Main(string[] args) + { + Screen.SetDefaults(); + + while (true) { + Screen.DEMO(); + Screen.Print(); + + + if (Console.KeyAvailable) { + Command.Do(); + } + + Thread.Sleep((int)(1000 / Fps)); + Console.Clear(); + } + } + } +} diff --git a/Oscilloscope/Oscilloscope/Properties/AssemblyInfo.cs b/Oscilloscope/Oscilloscope/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0bfa319 --- /dev/null +++ b/Oscilloscope/Oscilloscope/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Oscilloscope")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Oscilloscope")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("36e3f0b2-b785-4af3-b59f-483fda57672a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Oscilloscope/Oscilloscope/Screen.cs b/Oscilloscope/Oscilloscope/Screen.cs new file mode 100644 index 0000000..1b04f4d --- /dev/null +++ b/Oscilloscope/Oscilloscope/Screen.cs @@ -0,0 +1,121 @@ +using System; +using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Oscilloscope +{ + class Screen + { + public static int Height { get; private set; } + public static int Width { get; private set; } + + public static char VerWall { get; private set; } + public static char HorWall { get; private set; } + + public static char Ray { get; private set; } + public static int RayXPos { get; set; } + public static int RayYPos { get; set; } + + public static void SetDefaults() { + Height = 10; + Width = 20; + + VerWall = '|'; + HorWall = '-'; + + Ray = '*'; + RayXPos = Width / 2; + RayYPos = Height / 2; + + map = new StringBuilder[Height + 2]; + for (int i = 0; i < map.Length; i++) { + map[i] = new StringBuilder(new string(' ', Width + 2)); + } + } + + public static void SetValues(string[] command) { + try { + //TODO: add other commands + switch (command[0]) { + case "size": + Height = int.Parse(command[1]); Width = int.Parse(command[2]); + break; + case "char": + if (command[1] == "ray") Ray = command[2][0]; + //TODO: add other chars + break; + } + } catch (Exception) { + Console.WriteLine("ERR"); + Thread.Sleep(1000); + } + } + + private static StringBuilder[] map; + + public static void Print() { + map[0] = new StringBuilder(new string(HorWall, Width + 2)); + map[map.Length - 1] = new StringBuilder(new string(HorWall, Width + 2)); + + for (int row = 1; row < Height; row++) { + + var currRow = map[row]; + for (int col = 0; col < Width; col++) { + + if (row == RayYPos && col == RayXPos) { + currRow[col] = Ray; + + for (int j = 1; j < Height + 1; j++) { + if (j != row) map[j][col] = ' '; + } + } + } + + currRow[0] = VerWall; currRow[Width - 1] = VerWall; + map[row] = currRow; + } + + PrintMap(); + } + + private static void PrintMap() { + for (int i = 0; i < map.Length; i++) { + Console.WriteLine(map[i]); + } + } + + private static int t; + private static int val; + public static void DEMO() { + switch (val) { + case 0: RayYPos = 5; break; + case 1: RayYPos = 4; break; + case 2: RayYPos = 3; break; + case 3: RayYPos = 2; break; + case 4: RayYPos = 1; break; + case 5: RayYPos = 0; break; + case 6: RayYPos = 1; break; + case 7: RayYPos = 2; break; + case 8: RayYPos = 3; break; + case 9: RayYPos = 4; break; + case 10: RayYPos = 5; break; + case 11: RayYPos = 6; break; + case 12: RayYPos = 7; break; + case 13: RayYPos = 8; break; + case 14: RayYPos = 9; break; + case 15: RayYPos = 8; break; + case 16: RayYPos = 7; break; + case 17: RayYPos = 6; val = -1; break; + } + val++; + + if (t == Width) t = 0; + else t++; + + RayXPos = t; + } + } +} -- cgit v1.2.3