Ejemplo n.º 1
0
        public void Draw()
        {
            Console.CursorLeft = colStart;
            Console.CursorTop  = rowStart;

            foreach (var address in MemoryAddresses)
            {
                var    indexColor          = address.AddressIndex >= (MemoryAddresses.Length / 2) - 1 ? ConsoleColor.DarkYellow : ConsoleColor.Blue;
                string variableTypeName    = string.Empty;
                string variableValue       = string.Empty;
                bool   lastVariableChanged = false;

                if (address.Variable != null)
                {
                    variableTypeName = $"({address.Variable.Type.Name}) {address.Variable.Name}";
                    variableValue    = address.Variable.Type == DataTypes.String
                        ? $"\"{address.Variable.Value}\""
                        : address.Variable.Value;
                    variableValue      += $"{(address.Variable.Type is RefType ? " (ref)" : string.Empty)}";
                    lastVariableChanged = address.Variable.LastChanged;
                }

                Console.ForegroundColor = lineColor;
                ConsoleAid.Print(typeAndNameVarialbeLineLength);
                ConsoleAid.PrintLine(valueLineLength, '-');
                Console.CursorLeft = colStart;

                if (lastVariableChanged)
                {
                    Console.BackgroundColor = ConsoleColor.Cyan;
                }

                Console.ForegroundColor = ConsoleColor.Green;
                ConsoleAid.PrintText(typeAndNameVarialbeLineLength, variableTypeName);

                Console.ForegroundColor = lineColor;
                Console.Write("|");
                Console.ForegroundColor = indexColor;
                ConsoleAid.PrintText(addressIndexLineLength, address.AddressIndex.ToString());

                Console.ForegroundColor = lineColor;
                Console.Write("|");
                Console.ForegroundColor = ConsoleColor.Green;
                ConsoleAid.PrintText(valueLineLength - addressIndexLineLength - 3, variableValue);
                Console.ForegroundColor = lineColor;
                Console.WriteLine("|");
                Console.CursorLeft = colStart;

                Console.BackgroundColor = ConsoleColor.White;
            }

            ConsoleAid.Print(typeAndNameVarialbeLineLength);
            ConsoleAid.PrintLine(valueLineLength, '-');
        }
Ejemplo n.º 2
0
        public void DrawSourceCode()
        {
            Console.CursorTop       = rowStart;
            Console.BackgroundColor = ConsoleColor.Gray;

            foreach (var statement in SourceCode)
            {
                Console.CursorLeft = colStart;
                ConsoleAid.PrintLineText(50, statement);
            }

            Console.BackgroundColor = ConsoleColor.White;
        }
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WindowWidth     = Console.LargestWindowWidth;
            Console.WindowHeight    = Console.LargestWindowHeight;
            Console.Clear();

            int    choice       = 0;
            string choiceString = string.Empty;
            string name         = string.Empty;
            string value        = string.Empty;
            int    lengte       = 0;

            while ((choice = ConsoleAid.GetChoice("Maak een keuze", MainMenu.ToArray(), "Stop", Draw)) != 0)
            {
                Console.Clear();
                if (computer.LastVariableChanged != null)
                {
                    computer.LastVariableChanged.LastChanged = false;
                    computer.LastVariableChanged             = null;
                }

                try
                {
                    switch (choice)
                    {
                    case 1:     // ValueType
                        choiceString = ConsoleAid.GetChoicePossibility("Welk dataType wil je aanmaken",
                                                                       DataTypes.Types[DataTypes.valueTypes].Select(x => x.Name).ToArray(),
                                                                       "Terug Naar Main Menu", out choice, Draw);

                        switch (choice)
                        {
                        case 1:         // int
                            name  = ConsoleAid.ReadText("Hoe wil je je int variable noemen ?");
                            value = ConsoleAid.ReadInteger($"Geef een integere waarde voor {name}.", "Dit is geen integer waarde.").ToString();

                            computer.InitializeValueVariable(DataTypes.Int, name, value);
                            break;

                        case 2:         // string
                            name  = ConsoleAid.ReadText("Hoe wil je je string variable noemen?");
                            value = ConsoleAid.ReadText($"Geef een string waarde voor {name}.", true, true, true);

                            computer.InitializeValueVariable(DataTypes.String, name, value);
                            break;

                        case 3:         // bool
                            name  = ConsoleAid.ReadText("Hoe wil je je bool variable noemen?");
                            value = ConsoleAid.ReadInteger($"Geef een bool waarde voor {name}. kies tussen 0 of 1", "Dit is geen bool waarde", 0, 1).ToString();

                            computer.InitializeValueVariable(DataTypes.Bool, name, value);
                            break;
                        }
                        break;

                    case 2:     // RefType
                        choiceString = ConsoleAid.GetChoicePossibility("Welk dataType wil je aanmaken",
                                                                       computer.Types.Where(x => x.GetType() == typeof(RefType)).Select(x => x.Name).ToArray(),
                                                                       "Terug Naar Main Menu", out choice, Draw);

                        if (choice == 0)    //back to main menu
                        {
                            break;
                        }

                        if (DataTypes.Types[DataTypes.arrayTypes].Any(x => x.Name == choiceString))     // array type
                        {
                            name   = ConsoleAid.ReadText($"Hoe wil je je {choiceString} variable noemen?");
                            lengte = ConsoleAid.ReadInteger($"Geef een de lengte voor {name}, kies tussen 1 en 5.", "Dit is geen integer waarde.", 1, 5);

                            computer.InitializeArrayVariable(computer.Types.First(x => x.Name == choiceString), name, lengte);
                        }
                        else     // custom type
                        {
                            var type = (RefType)DataTypes.CustomTypes.FirstOrDefault(x => x.Name == choiceString);

                            name = ConsoleAid.ReadText($"Hoe wil je je {choiceString} variable noemen?");

                            computer.InitializeCustumTypeVariable(type, name);
                        }
                        break;

                    case 3:
                        name = ConsoleAid.ReadText("Hoe heet je nieuw custom data type?");
                        var properties      = new List <Property>();
                        var maxProperties   = 5;
                        var propertyCounter = 1;

                        do
                        {
                            Console.WriteLine($"Property {propertyCounter++}/{maxProperties}.");

                            choiceString = ConsoleAid.GetChoicePossibility("Van welk dataType is je property?",
                                                                           computer.Types.Where(x => x.GetType() == typeof(ValueType)).Select(x => x.Name).ToArray(),
                                                                           "Stop met properties aanmaken", out choice, Draw);

                            if (choice == 0)
                            {
                                break;
                            }

                            var propertyName = ConsoleAid.ReadText("Hoe heet je property?");

                            properties.Add(new Property
                            {
                                Name = propertyName,
                                Type = computer.Types.First(x => x.GetType() == typeof(ValueType) && x.Name == choiceString)
                            });

                            Console.Clear();
                        }while (propertyCounter <= maxProperties);

                        computer.CreateCustomType(name, properties);
                        break;

                    case 4:
                        if (!computer.Variables.Any())
                        {
                            throw new Exception("Nog geen variabelen aangemaakt");
                        }

                        var variableNames = computer.Variables.Select(x => x.Name).ToArray();
                        choiceString = ConsoleAid.GetChoicePossibility("Van welke variable wil je de waarde wijzigen",
                                                                       variableNames, "Stop", out choice, Draw);

                        if (choice == 0)
                        {
                            break;
                        }
                        choice--;
                        var variable = computer.Variables[choice];

                        if (variable.Type is ValueType)
                        {
                            switch (variable.Type.Name)
                            {
                            case "int":         // int
                                value = ConsoleAid.ReadInteger($"Geef een integere waarde voor {name}.", "Dit is geen integer waarde.").ToString();
                                break;

                            case "string":         // string
                                value = ConsoleAid.ReadText($"Geef een string waarde voor {name}.", true, true, true);
                                break;

                            case "bool":         // bool
                                value = ConsoleAid.ReadInteger($"Geef een bool waarde voor {name}. kies tussen 0 of 1", "Dit is geen bool waarde", 0, 1).ToString();
                                break;
                            }
                        }
                        else if (variable.Type is RefType)
                        {
                            Console.Clear();
                            Console.WriteLine($"Je hebt gekozen om '{variable.Name}' te wijzigen.");

                            variableNames = variable.Variables.Select(x => x.Name).ToArray();
                            choiceString  = ConsoleAid.GetChoicePossibility("Van welke variable wil je de waarde wijzigen",
                                                                            variableNames, "Stop", out choice, Draw);

                            if (choice == 0)
                            {
                                break;
                            }

                            choice--;
                            variable = variable.Variables[choice];

                            switch (variable.Type.Name)
                            {
                            case "int":         // int
                                value = ConsoleAid.ReadInteger($"Geef een integere waarde voor {name}.", "Dit is geen integer waarde.").ToString();
                                break;

                            case "string":         // string
                                value = ConsoleAid.ReadText($"Geef een string waarde voor {name}.", true, true, true);
                                break;

                            case "bool":         // bool
                                value = ConsoleAid.ReadInteger($"Geef een bool waarde voor {name}. kies tussen 0 of 1", "Dit is geen bool waarde", 0, 1).ToString();
                                break;
                            }
                        }

                        computer.SetValueOfVariable(variable, value);

                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.WriteLine("Druk op ENTER om verder te gaan.");
                    Console.ReadLine();
                }


                Console.Clear();
            }
        }