Exemple #1
0
        public void Interpretor(string[] Commands, Turtle fakeLogo)
        {
            int           i         = 0;
            List <int>    Init      = new List <int>();
            List <string> InitNames = new List <string>();
            int           intAdded  = 0;

            if (Commands.Length == 0)
            {
                output.Text += "No Commands Added" + '\r' + '\n';
            }
            for (; i < Commands.Length; i++)
            {
                string[] Facts     = Commands[i].Split(' ');
                int[]    Arguments = new int[4];

                for (int t = 1; t < Facts.Length; t++)
                {
                    Int32.TryParse(Facts[t], out Arguments[t - 1]);
                }

                switch (Facts[0])
                {
                case "":
                    break;

                case "{":
                    //Branch++;
                    break;

                case "}":
                    //Branch--;
                    break;

                case "go":
                    fakeLogo.Go(Arguments[0]);
                    break;

                case "rotate":
                    fakeLogo.Rotate(Arguments[0]);
                    break;

                case "circle":
                    fakeLogo.Circle(Arguments[0], Arguments[1], Arguments[2]);
                    break;

                case "pixelto":
                    fakeLogo.SPixel(Arguments[0], Arguments[1], Color.FromName(Facts[3]));
                    break;

                case "clear":
                    fakeLogo.ClearMap();
                    break;

                case "repeat":
                    string[] TrueCode = CodeCounter(Commands, i);
                    for (int t = 0; t < Arguments[0]; t++)
                    {
                        Interpretor(TrueCode, fakeLogo);
                    }
                    i += TrueCode.Length + 2;
                    break;

                case "int":
                    int bug;
                    if (Int32.TryParse(Facts[1], out bug))
                    {
                        output.Text += Facts[1] + " Isn't A Correct Name\r\n";
                    }
                    else
                    {
                        InitNames[intAdded] = Facts[1];
                        Init[intAdded]      = Arguments[2];
                    }
                    break;

                case "print":
                    if (InitNames.IndexOf(Facts[1]) != -1)
                    {
                        output.Text += Init[InitNames.IndexOf(Facts[1])] + "\r\n";
                    }
                    else
                    {
                        output.Text += Facts[1] + "\r\n";
                    }
                    break;

                case "if":
                    string[] TrueifCode = CodeCounter(Commands, i);
                    i += TrueifCode.Length + 2;
                    if (Commands[TrueifCode.Length + i].Contains("else") && !InterpretorIF(fakeLogo, InitNames, Init, Facts))
                    {
                        break;
                    }
                    Interpretor(TrueifCode, fakeLogo);
                    break;

                case "else":
                    string[] TrueElseCode = CodeCounter(Commands, i);
                    Interpretor(TrueElseCode, fakeLogo);
                    i += TrueElseCode.Length + 2;
                    break;


                default:
                    output.Text += "It's So Lonely Here" + '\r' + '\n';
                    break;
                }
            }
        }