Ejemplo n.º 1
0
        private void ProcessLine(string line)
        {
            if(line.StartsWith('$'))
            {
                var match = Regex.Match(line, @"(?<=\$jmp\s)\d+", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    //Console.Write($"Jump to {match.Value}");
                    _linePointer = int.Parse(match.Value) - 1;
                    return;
                }

                if(line.StartsWith("$choice"))
                {
                    var matches = Regex.Matches(line, @"(?<=\$choice|\|)[^\|]+:\s*[1-9]+", RegexOptions.IgnoreCase);
                    if (matches.Count > 0)
                    {
                        ParseChoice(matches);
                        return;
                    }
                }
            }
            DelayedWriter.WriteLineDelay(line);
            Console.ReadKey(true);
            Console.Write("\n");
            _linePointer++;
        }
Ejemplo n.º 2
0
 private void ParseChoice(MatchCollection matches)
 {
     var count = matches.Count;
     var choices = new Choice[count];
     for (int i = 0; i < count; i++)
     {
         choices[i] = new Choice(matches[i].Value);
         DelayedWriter.WriteLineDelay($"{i} - {choices[i].text}\n");
     }
     _linePointer = choices[GetChoice(count)].targetLine - 1;
 }
Ejemplo n.º 3
0
 private int GetChoice(int count)
 {
     //DelayedWriter.WriteLineDelay("Enter choice.\n");
     int choice;
     while(true)
     {
         if(int.TryParse(Console.ReadLine(), out choice))
         {
             if(choice < count)
             {
                 break;
             }
         }
         DelayedWriter.WriteLineDelay("Enter a valid choice\n");
     }
     return choice;
 }