Exemplo n.º 1
0
 // Assume: the constructor of RoomNumber ensures that the room number is valid.
 public void Connect(TravelDirection direction, RoomNumber toRoomNumber)
 {
     if (!toRoomNumber.Equals(RoomNumber))
     {
         connections[direction] = toRoomNumber;
     }
 }
Exemplo n.º 2
0
        // call this to load the starting room
        // call this to load each subsequent room
        // Using a naive algorithm since this is the first try:
        // Whenever it is time to load another room for any reason, check the server
        // version, download if necessary, etc.  There may be a better way to do this, down the road.
        // First things first, though!
        private WorldCell Load(RoomNumber roomNumber, TravelDirection fromDirection, RoomNumber parentRoomNumber)
        {
            int             centerX           = this.BuildX(fromDirection);
            int             centerY           = this.BuildY(fromDirection);
            Color           backgroundColor   = diskReader.GetColor(roomNumber);
            TravelDirection directionToParent = TravelDirection.Opposite(fromDirection);

            return(new WorldCell(centerX, centerY, roomNumber, backgroundColor, directionToParent, parentRoomNumber));
        }
Exemplo n.º 3
0
 public void Travel(TravelDirection direction)
 {
     // throw exception if can't move in that direction (assume the UI disables direction buttons that currently have no connection)
     // figure out which room number is in the indicated direction
     // check this.cells for indicated roomNumber (if found, assign it to CurrentCell)
     // Load(indicated roomNumber, indicated direction) if not found in cells
     // ...and assign result of load to CurrentCell
     // In either case, CurrentCell will be the travelled-to cell.
     // This might be the only place that should/can call Load(RoomNumber, TravelDirection).
 }
Exemplo n.º 4
0
 // Assume the builder or whatever to pass in proper values.
 // Assume this cell wouldn't be constructed in memory until after the client ensures that the relevant content file is installed.
 // If this is the starting cell, there won't be any parent direction or parent room number, which is expected.
 public WorldCell(int centerX, int centerY, RoomNumber roomNumber,
                  Color backgroundColor, TravelDirection directionToParent, RoomNumber parentRoomNumber)
 {
     this.CenterX         = centerX;
     this.CenterY         = centerY;
     this.RoomNumber      = roomNumber;
     this.BackgroundColor = backgroundColor;
     connections          = new Dictionary <TravelDirection, RoomNumber>();
     Connect(directionToParent, parentRoomNumber);
 }
Exemplo n.º 5
0
        private int BuildY(TravelDirection fromDirection)
        {
            int yOffset = Director.Offset(fromDirection) * WorldCell.StandardHeight;

            return(CurrentCell.CenterY + yOffset);
        }
Exemplo n.º 6
0
        private int BuildX(TravelDirection fromDirection)
        {
            int xOffset = Director.Offset(fromDirection) * WorldCell.StandardWidth;

            return(CurrentCell.CenterX + xOffset);
        }