Exemplo n.º 1
0
    public void ChooseRoom()
    {
        int             choice;
        Func <int, int> IndexToChoice = (int aChoice) => aChoice + 1;
        Func <int, int> ChoiceToIndex = (int anIndex) => anIndex - 1;

        System.Console.WriteLine("Choose a new room:");
        string[] rooms = _CurrentRoom.Neighbours().ToArray();
        for (var index = 0; index < rooms.Length; index++)
        {
            System.Console.WriteLine($"# {IndexToChoice(index)} : {rooms[index]}");
        }
        choice = GetValidChoice(1, rooms.Length);
        NamedGraphNode <string> ChosenRoom;

        if (_CurrentRoom.GetNeighbour(rooms[ChoiceToIndex(choice)], out ChosenRoom))
        {
            _CurrentRoom = ChosenRoom;
            System.Console.WriteLine($"Entered room {ChosenRoom.Name}");
        }
        else
        {
            System.Console.WriteLine($"Could not enter room {rooms[ChoiceToIndex(choice)]} due to an internal barrier!");
        }
    }