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!");
        }
    }
Exemplo n.º 2
0
 public bool GetNeighbour(string name, out NamedGraphNode <T> neighbour)
 {
     if (HasNeighbour(name))
     {
         neighbour = _Neighbours[name];
         return(true);
     }
     else
     {
         neighbour = null;
         return(false);
     }
 }
Exemplo n.º 3
0
    public void SetupRooms()
    {
        NamedGraphNode <string>
        NorthRoom              = new NamedGraphNode <string>("North Room"),
            NorthEastRoom      = new NamedGraphNode <string>("North East Room"),
            NorthSouthCorridor = new NamedGraphNode <string>("North South Corridor"),
            SouthernKitchen    = new NamedGraphNode <string>("Southern Kitchen"),
            SouthWestWing      = new NamedGraphNode <string>("South West Wing");

        NorthRoom
        .AddNeighbour(NorthEastRoom)
        .AddNeighbour(NorthSouthCorridor);
        SouthernKitchen
        .AddNeighbour(NorthSouthCorridor)
        .AddNeighbour(SouthWestWing);
        _CurrentRoom = NorthSouthCorridor;
    }
Exemplo n.º 4
0
 public NamedGraphNode <T> AddNeighbour(NamedGraphNode <T> other)
 {
     _Neighbours.Add(other.Name, other);
     other._Neighbours.Add(Name, this);
     return(this);
 }