コード例 #1
0
 public void SendText()
 {
     try
     {
         if (Device.IsConnected)
         {
             Device.WriteString(TextCommand + "\r\n");
             if (!CommandList.Contains(TextCommand))
             {
                 CommandList.Add(TextCommand);
             }
         }
     }
     catch (Exception e)
     {
         Messager.AddError(e.ToString());
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            bool  doLoop = true;
            Field field  = new Field();

            var commands = new CommandList();

            commands.Add("Usage", "Print the usage", () =>
            {
                commands.PrintCommandList();
            });

            commands.Add("Start", "Start a new game", () =>
            {
                Console.WriteLine("New game started");
                field = new Field();
                field.PlaceBalls();
                PrintField(field);
            });

            commands.Add("Next", "Add a temp", () =>
            {
                var balls = field.PlaceBalls();
                field.RemoveForBalls(balls);
                PrintField(field);
            });

            commands.Add("Switch", "Switch two balls", () =>
            {
                var destination = SwitchBalls(field);
                field.RemoveLines(destination);
                var balls = field.PlaceBalls();
                field.RemoveForBalls(balls);
                PrintField(field);
            });

            commands.Add("End", "Finish the game", () =>
            {
                doLoop = false;
            });

            commands.PrintCommandList();

            while (doLoop)
            {
                string line = Console.ReadLine()?.Trim();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                if (commands.Contains(line))
                {
                    commands.Run(line);
                }
                else
                {
                    Console.WriteLine($"Invalid '{line}' command");
                }
            }
        }