Exemple #1
0
        public MoveResults MoveResults(Direction direction)
        {
            MoveResults       result = new MoveResults();
            PrintInstructions pi     = result.PrintInstructions;

            result.Success   = false;
            result.DoorState = DoorState(direction);

            switch (result.DoorState)
            {
            case Types.DoorState.Locked:
            case Types.DoorState.Sealed:
                break;

            case Types.DoorState.Open:
                result.Success = true;
                break;
            }

            pi.NewLine("The ")
            .Add($"{direction}", GetDoorColor(CurrentRoomPosition, direction));

            if (result.Success)
            {
                pi.Add($" door was {result.DoorState}");
            }
            else
            {
                pi.Add($" door is {result.DoorState}");
            }

            return(result);
        }
Exemple #2
0
        public PrintInstructions PrintInstructions(string banner, string spaces = "  ")
        {
            PrintInstructions result = new PrintInstructions();
            int          row, col, rowOffset, colOffset;
            RoomPosition position;
            char         c;


            for (row = 0; row < 3; row++)
            {
                result.NewLine(spaces);

                for (col = 0; col < 7; col++)
                {
                    c        = RoomsTemplate[row][col];
                    position = RoomPosition.One;
                    // rowOffset = 0;
                    // colOffset = 0;
                    result.Add(DeligateMap[c](c, row, col, position));
                }

                for (col = 7; col < 13; col++)
                {
                    c        = RoomsTemplate[row][col];
                    position = RoomPosition.Two;
                    // rowOffset = 0;
                    colOffset = 6;
                    result.Add(DeligateMap[c](c, row, col - colOffset, position));
                }
            }

            for (row = 3; row < 5; row++)
            {
                result.NewLine(spaces);

                for (col = 0; col < 7; col++)
                {
                    c         = RoomsTemplate[row][col];
                    position  = RoomPosition.Three;
                    rowOffset = 2;
                    // colOffset = 0;
                    result.Add(DeligateMap[c](c, row - rowOffset, col, position));
                }

                for (col = 7; col < 13; col++)
                {
                    c         = RoomsTemplate[row][col];
                    position  = RoomPosition.Four;
                    rowOffset = 2;
                    colOffset = 6;
                    result.Add(DeligateMap[c](c, row - rowOffset, col - colOffset, position));
                }
            }

            return(result);
        }
Exemple #3
0
        internal void Put(string option)
        {
            string noun = option.Substring(0, option.IndexOf(" "));
            string verb = option.Substring(option.IndexOf(" ") + 1).Trim();

            Noun nounEnum;
            Verb verbEnum;

            PrintInstructions pi = new PrintInstructions();

            if (Enum.TryParse(_textInfo.ToTitleCase(noun), out nounEnum))
            {
                if (Enum.TryParse(_textInfo.ToTitleCase(verb), out verbEnum))
                {
                    switch (nounEnum)
                    {
                    case Noun.Calculator:
                        switch (verbEnum)
                        {
                        case Verb.Away:
                            pi.Add("You turn the calculator off and put it in your pocket", ConsoleColor.DarkGreen);
                            SetCalculator(false);
                            SetPrintInstructions(pi);
                            return;
                        }
                        break;
                    }
                }
                pi.Add("You can't put the ");
                pi.Add(noun, ConsoleColor.DarkRed);
                pi.Add($" '{verb}' ", ConsoleColor.DarkRed);

                SetPrintInstructions(pi);
                return;
            }
            pi.Add("There is no ");
            pi.Add($"'{noun}' ", ConsoleColor.DarkRed);
            pi.Add("to put ");
            pi.Add(verb, ConsoleColor.DarkRed);
            SetPrintInstructions(pi);
        }
Exemple #4
0
        internal void Unlock(string option)
        {
            PrintInstructions pi = new PrintInstructions();

            string[] options = option.Trim().Split(" ");
            string   direction;
            string   noun;

            if (options[0] == "")
            {
                pi.Add("What did you want to unlock?", ConsoleColor.Blue);
                SetPrintInstructions(pi);
                return;
            }

            if (options.Length < 2)
            {
                direction = options[0];
                noun      = "";
            }
            else
            {
                direction = options[0];
                noun      = options[1];
            }

            Noun      nounEnum;
            Direction directionEnum;

            // Check for direction
            if (Enum.TryParse(_textInfo.ToTitleCase(direction), out directionEnum))
            {
                // Check the noun
                if (Enum.TryParse(_textInfo.ToTitleCase(noun), out nounEnum))
                {
                    switch (nounEnum)
                    {
                    case Noun.Door:
                        // They have given us a valid direction and "Door"
                        if (_rooms.Lock.DoorIsLocked(_rooms.CurrentRoomPosition, directionEnum))
                        {
                            UnlockDoor();
                            return;
                            // Ok This door is locked
                        }
                        else
                        {
                            pi.Add($"The {directionEnum} is not locked", ConsoleColor.Blue);
                            SetPrintInstructions(pi);
                            return;
                        }

                    default:
                        // We dont have anything else to unlock at this direction
                        pi.Add($"There is no {directionEnum} {nounEnum} to Unlock");
                        SetPrintInstructions(pi);
                        return;
                    }
                }
                // We were given a valid direction but an invalid noun
                pi.Add($"There is no {directionEnum} {noun} to Unlock");
                SetPrintInstructions(pi);
                return;
            }
            else if (Enum.TryParse(_textInfo.ToTitleCase(direction), out nounEnum)) // Check for a noun in the direction place
            {
                switch (nounEnum)
                {
                case Noun.Door:
                    // Which door???
                    pi.Add($"Which {nounEnum} did you want to unlock?", ConsoleColor.Blue);
                    pi.NewLine($"Did you mean 'unlock [north|east|south|west] door'?", ConsoleColor.Blue);
                    SetPrintInstructions(pi);
                    return;

                case Noun.Calculator:
                    // The calculator is unlocked...
                    if (PlayerHasItem(noun.ToLower()))
                    {
                        pi.Add("The calculator is unlocked", ConsoleColor.DarkGreen);
                        SetPrintInstructions(pi);
                        return;
                    }
                    else
                    {
                        pi.Add("You don't have a calculator to unlock", ConsoleColor.DarkRed);
                        SetPrintInstructions(pi);
                        return;
                    }

                default:
                    pi.Add($"There is no '{noun}' to unlock", ConsoleColor.DarkRed);
                    SetPrintInstructions(pi);
                    return;
                }
            }
            else
            {
                // We were given an unknown noun and direction
                pi.Add($"There is no '{option}' to unlock", ConsoleColor.DarkRed);
                SetPrintInstructions(pi);
                return;
            }
        }