//state 4
        public static void clientCodeState()
        {
            var game = new MilitaryContext(new Private());

            while (true)
            {
                Console.WriteLine("Choose an operation:");
                Console.WriteLine("1. Show chevron\n2. Promote\n3. Demote\n4. Exit");
                string choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    game.ShowChevron();
                    break;

                case "2":
                    if (game.Order < 6)
                    {
                        game.TransitionTo(game.Order + 1);
                    }
                    else
                    {
                        Console.WriteLine("Cannot promote a general!");
                    }
                    break;

                case "3":
                    if (game.Order > 1)
                    {
                        game.TransitionTo(game.Order - 1);
                    }
                    else
                    {
                        Console.WriteLine("Cannot demote a private!");
                    }
                    break;

                case "4":
                    Console.WriteLine("Exiting!");
                    return;

                default:
                    Console.WriteLine("Invalid operation code!");
                    break;
                }
            }
        }
Beispiel #2
0
 public void SetContext(MilitaryContext MilitaryContext) => _context = MilitaryContext;