-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenue.cs
91 lines (77 loc) · 2.77 KB
/
Menue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Numerics;
using System.Runtime.InteropServices.Marshalling;
using Resourses.Tools;
namespace Resourses.Logic;
public class Menue
{
//Menue parameters
public delegate void OptionMethod();
private char[] optionsKeys;
private string menueName;
private string[] optionsNames;
private OptionMethod[] OptionMethods;
private int menueLength;
public Menue(string theMenueName, char[] theOptionKeys, string[] theOptionsNames, OptionMethod[] theOptionMethods)
{
//capting general parameters
this.menueName = theMenueName;
this.optionsKeys = theOptionKeys;
this.OptionMethods = theOptionMethods;
this.menueLength = theOptionKeys.Length;
//saving properly the option names with the format:
//[x]-"OptionName"
string[] importedOptionNames = theOptionsNames;
for (int i = 0; i < this.menueLength; i++)
{
importedOptionNames[i] = "[" + optionsKeys[i] + "]-" + theOptionsNames[i];
}
this.optionsNames = importedOptionNames;
}
//just a nonsense testing mehtod I like to add...
public static void Testing() => Console.WriteLine("- Menue loaded correctly");
//methods to get private information from the class instanse...
public string GetMenueName() => this.menueName;
public string[] GetOptionNames() => this.optionsNames;
//method for executing options
public void Option(char theInput)
{
//checking if the input is a valid iption
int optionPosition = OptionExist(theInput);
if (optionPosition != -1)
{
//executes the selected method option
this.OptionMethods[optionPosition]?.Invoke();
}
}
/*
them try some kind of methods for adding and deleting
options... like a dinamic list... or directly make
parameters as lis? mmmmm... nah... I'll do it later
*/
private int OptionExist(char theInput){
//preset value for non valid option
int optionPosition = -1;
for(int i = 0; i < this.optionsKeys.Length; i++)
{
if (optionsKeys[i] == theInput)
{
//saves the valid option
optionPosition = i;
}
}
return optionPosition;
}
//method for simple console printing... temporal for testing
public void Print()
{
Console.WriteLine("----" + this.menueName + "----");
Console.WriteLine(" ");
for (int i = 0; i < this.menueLength; i++){
Console.WriteLine(this.optionsNames[i]);
}
Console.WriteLine(" ");
Console.WriteLine("[i]-Pres a key for selecting an option");
Console.WriteLine(" ");
}
}