Пример #1
0
        static CardinalDirection Movement(AvailableCommand Command)
        {
            string QuitOption;

            switch (Command)
            {
            //boundry case defined in offset from directionsFacing
            //modulus ensures value is always between 0-3
            case AvailableCommand.MoveLeft:
                return((CardinalDirection)((s_directionFacing - 1 + 4) % 4));

            case AvailableCommand.MoveRight:
                return((CardinalDirection)((s_directionFacing + 1 + 4) % 4));

            case AvailableCommand.MoveBackward:
                return((CardinalDirection)((s_directionFacing + 2 + 4) % 4));

            case AvailableCommand.MoveForward:
                return((CardinalDirection)s_directionFacing);

            case AvailableCommand.Quit:
                Console.WriteLine("Are you sure you want to quit? Yes/No: ");
                QuitOption = Console.ReadLine();
                QuitOption = QuitOption.ToLower();
                if (QuitOption == "yes")
                {
                    Environment.Exit(0);
                }
                if (QuitOption == "no")
                {
                    break;
                }
                if (QuitOption != "yes" || QuitOption != "no")
                {
                    QuitOption = Console.ReadLine();
                    QuitOption = QuitOption.Trim();
                    QuitOption = QuitOption.ToLower();
                    Console.WriteLine("Invalid input. Please enter 'yes' or 'no'.");
                }
                break;
            }
            return((CardinalDirection)s_directionFacing);
        }
Пример #2
0
        static AvailableCommand CommandHandler()
        {
            string QuitOption;

            while (true)
            {
                Console.WriteLine("".PadLeft(45, '-'));
                Console.WriteLine("Where will you go?");
                Console.WriteLine("The available movement commands are: 'move forward', 'move backward', 'move right', 'move left'");
                Console.WriteLine("The available looking commands are: 'look left', 'look right', 'turn around'");
                Console.WriteLine("You may enter 'quit' to exit the game.");
                Console.WriteLine("".PadLeft(45, '-'));
                string Command = CommandValid();

                switch (Command)
                {
                case "Quit":
                    Console.WriteLine("Are you sure you want to quit? Yes/No: ");
                    QuitOption = Console.ReadLine();
                    QuitOption = QuitOption.ToLower();
                    if (QuitOption == "yes")
                    {
                        Environment.Exit(0);
                    }
                    if (QuitOption == "no")
                    {
                        break;
                    }
                    if (QuitOption != "yes" || QuitOption != "no")
                    {
                        QuitOption = Console.ReadLine();
                        QuitOption = QuitOption.Trim();
                        QuitOption = QuitOption.ToLower();
                        Console.WriteLine("Invalid input. Please enter 'yes' or 'no'.");
                    }
                    return(AvailableCommand.Quit);

                case "move forward":
                    return(AvailableCommand.MoveForward);

                case "move backward":
                    return(AvailableCommand.MoveBackward);

                case "move right":
                    return(AvailableCommand.MoveRight);

                case "move left":
                    return(AvailableCommand.MoveLeft);

                case "look right":
                    s_directionFacing = (s_directionFacing + 1 + 4) % 4;
                    DisplayDirection();
                    break;

                case "look left":
                    s_directionFacing = (s_directionFacing - 1 + 4) % 4;
                    DisplayDirection();
                    break;

                case "turn around":
                    s_directionFacing = (s_directionFacing + 1 + 4) % 4;
                    break;

                default:
                {
                    Console.WriteLine("Invalid input. Please enter a valid command.");
                    continue;
                }
                }
            }
        }