Esempio n. 1
0
        public bool FlipRooms(Direction direction)
        {
            Dictionary <RoomPosition, BaseRoom> result = new Dictionary <RoomPosition, BaseRoom>();
            FlipDirection flipDirection = GetFlipDirection(direction);

            switch (flipDirection)
            {
            case FlipDirection.Horizontal:
                result.Add(RoomPosition.One, RoomPositions[RoomPosition.Four]);
                result.Add(RoomPosition.Two, RoomPositions[RoomPosition.Three]);
                result.Add(RoomPosition.Three, RoomPositions[RoomPosition.Two]);
                result.Add(RoomPosition.Four, RoomPositions[RoomPosition.One]);
                break;

            case FlipDirection.Vertical:
                result.Add(RoomPosition.One, RoomPositions[RoomPosition.Two]);
                result.Add(RoomPosition.Two, RoomPositions[RoomPosition.One]);
                result.Add(RoomPosition.Three, RoomPositions[RoomPosition.Four]);
                result.Add(RoomPosition.Four, RoomPositions[RoomPosition.Three]);
                break;

            default:
                return(false);
            }
            RoomPositions = result;
            return(true);
        }
Esempio n. 2
0
        public ConsoleColor GetDoorColor(RoomPosition roomPosition, Direction direction)
        {
            BaseRoom room          = RoomPositions[roomPosition];
            BaseRoom adjoiningRoom = GetAdjoiningRoom(roomPosition, direction);
            char     doorChar      = room.DoorCharacter(direction);

            if (DoorsAreMerged(roomPosition, direction))
            {
                // We need to get the merged color
                return(GetMergedColor(room, adjoiningRoom));
            }

            if (ColoredDoorChars.Contains(doorChar))
            {
                return(room.Color);
            }

            // If the adjoining door is a color door we get that
            if (adjoiningRoom != null)
            {
                char adjoiningDoorChar = adjoiningRoom.DoorCharacter(GetOppisiteDirection(direction));
                if (ColoredDoorChars.Contains(adjoiningDoorChar))
                {
                    return(adjoiningRoom.Color);
                }
            }

            return(Types.WALL_AND_DOOR_COLOR);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public bool RotateRooms(RoomPosition position, Direction direction)
        {
            Dictionary <RoomPosition, BaseRoom> result = new Dictionary <RoomPosition, BaseRoom>();
            Rotation rotation = GetRotation(position, direction);

            switch (rotation)
            {
            case Rotation.Clockwise:
                result.Add(RoomPosition.One, RoomPositions[RoomPosition.Three]);
                result.Add(RoomPosition.Two, RoomPositions[RoomPosition.One]);
                result.Add(RoomPosition.Three, RoomPositions[RoomPosition.Four]);
                result.Add(RoomPosition.Four, RoomPositions[RoomPosition.Two]);
                break;

            case Rotation.CounterClockwise:
                result.Add(RoomPosition.One, RoomPositions[RoomPosition.Two]);
                result.Add(RoomPosition.Two, RoomPositions[RoomPosition.Four]);
                result.Add(RoomPosition.Three, RoomPositions[RoomPosition.One]);
                result.Add(RoomPosition.Four, RoomPositions[RoomPosition.Three]);
                break;

            case Rotation.None:
                return(false); // Get out of here if we arent rotating.
            }
            RoomPositions = result;
            return(true);
        }
Esempio n. 5
0
        public DoorState DoorLockState(RoomPosition position, Direction direction)
        {
            if (Lock.DoorIsLocked(position, direction))
            {
                return(Types.DoorState.Locked);
            }

            return(Types.DoorState.Open);
        }
Esempio n. 6
0
        public RoomPosition GetAdjoiningRoomPosition(RoomPosition currentPosition, Direction direction)
        {
            RoomPosition result = currentPosition;

            switch (currentPosition)
            {
            case RoomPosition.One:
                switch (direction)
                {
                case Direction.South:
                    return(RoomPosition.Three);

                case Direction.East:
                    return(RoomPosition.Two);
                }
                break;

            case RoomPosition.Two:
                switch (direction)
                {
                case Direction.South:
                    return(RoomPosition.Four);

                case Direction.West:
                    return(RoomPosition.One);
                }
                break;

            case RoomPosition.Three:
                switch (direction)
                {
                case Direction.North:
                    return(RoomPosition.One);

                case Direction.East:
                    return(RoomPosition.Four);
                }
                break;

            case RoomPosition.Four:
                switch (direction)
                {
                case Direction.North:
                    return(RoomPosition.Two);

                case Direction.West:
                    return(RoomPosition.Three);
                }
                break;
            }

            return(result);
        }
Esempio n. 7
0
        public bool DoorsAreMerged(RoomPosition currentPosition, Direction direction)
        {
            BaseRoom adjoiningRoom = GetAdjoiningRoom(currentPosition, direction);

            if (adjoiningRoom == null)
            {
                return(false);
            }

            bool currentIsMergable   = ColoredDoorChars.Contains(RoomPositions[currentPosition].DoorCharacter(direction));
            bool adjoiningIsMergable = ColoredDoorChars.Contains(adjoiningRoom.DoorCharacter(GetOppisiteDirection(direction)));

            return(currentIsMergable && adjoiningIsMergable);
        }
Esempio n. 8
0
        public FlipDirection GetFlipDirection(Direction direction)
        {
            switch (direction)
            {
            case Direction.East:
            case Direction.West:
                return(FlipDirection.Horizontal);

            case Direction.North:
            case Direction.South:
                return(FlipDirection.Vertical);
            }
            return(FlipDirection.None);
        }
Esempio n. 9
0
        public Rotation GetRotation(RoomPosition position, Direction direction)
        {
            switch (position)
            {
            case RoomPosition.One:
                switch (direction)
                {
                case Direction.South:
                    return(Rotation.Clockwise);

                case Direction.East:
                    return(Rotation.CounterClockwise);
                }
                break;

            case RoomPosition.Two:
                switch (direction)
                {
                case Direction.South:
                    return(Rotation.CounterClockwise);

                case Direction.West:
                    return(Rotation.Clockwise);
                }
                break;

            case RoomPosition.Three:
                switch (direction)
                {
                case Direction.North:
                    return(Rotation.CounterClockwise);

                case Direction.East:
                    return(Rotation.Clockwise);
                }
                break;

            case RoomPosition.Four:
                switch (direction)
                {
                case Direction.North:
                    return(Rotation.Clockwise);

                case Direction.West:
                    return(Rotation.CounterClockwise);
                }
                break;
            }
            return(Rotation.None);
        }
Esempio n. 10
0
        public DoorState DoorState(Direction direction)
        {
            DoorState state = Types.DoorState.Sealed;

            switch (CurrentRoomPosition)
            {
            case RoomPosition.One:
                switch (direction)
                {
                case Direction.South:
                case Direction.East:
                    state = DoorLockState(CurrentRoomPosition, direction);
                    break;
                }
                break;

            case RoomPosition.Two:
                switch (direction)
                {
                case Direction.South:
                case Direction.West:
                    state = DoorLockState(CurrentRoomPosition, direction);
                    break;
                }
                break;

            case RoomPosition.Three:
                switch (direction)
                {
                case Direction.North:
                case Direction.East:
                    state = DoorLockState(CurrentRoomPosition, direction);
                    break;
                }
                break;

            case RoomPosition.Four:
                switch (direction)
                {
                case Direction.North:
                case Direction.West:
                    state = DoorLockState(CurrentRoomPosition, direction);
                    break;
                }
                break;
            }

            return(state);
        }
Esempio n. 11
0
        public Direction GetOppisiteDirection(Direction d)
        {
            switch (d)
            {
            case Direction.North:
                return(Direction.South);

            case Direction.East:
                return(Direction.West);

            case Direction.South:
                return(Direction.North);

            case Direction.West:
                return(Direction.East);
            }
            return(d);
        }
Esempio n. 12
0
        // public char GetDoorCharacter(BaseRoom room, Direction direction)
        // {
        //   return room.DoorCharacter(direction);
        // }

        public char GetDoorChar(RoomPosition roomPosition, Direction direction)
        {
            BaseRoom currentRoom   = RoomPositions[roomPosition];
            BaseRoom adjoiningRoom = GetAdjoiningRoom(roomPosition, direction);

            char curRoomChar = currentRoom.DoorCharacter(direction);

            if (adjoiningRoom == null)
            {
                return(curRoomChar);
            }

            char adjRoomChar = adjoiningRoom.DoorCharacter(GetOppisiteDirection(direction));

            if (ColoredDoorChars.Contains(adjRoomChar))
            {
                return(adjRoomChar);
            }

            return(curRoomChar);
        }
Esempio n. 13
0
        public BaseRoom GetAdjoiningRoom(RoomPosition currentPosition, Direction direction)
        {
            switch (currentPosition)
            {
            case RoomPosition.One:
                switch (direction)
                {
                case Direction.South:
                    return(RoomPositions[RoomPosition.Three]);

                case Direction.East:
                    return(RoomPositions[RoomPosition.Two]);

                default:
                    break;
                }
                break;

            case RoomPosition.Two:
                switch (direction)
                {
                case Direction.West:
                    return(RoomPositions[RoomPosition.One]);

                case Direction.South:
                    return(RoomPositions[RoomPosition.Four]);

                default:
                    break;
                }
                break;

            case RoomPosition.Three:
                switch (direction)
                {
                case Direction.North:
                    return(RoomPositions[RoomPosition.One]);

                case Direction.East:
                    return(RoomPositions[RoomPosition.Four]);

                default:
                    break;
                }
                break;

            case RoomPosition.Four:
                switch (direction)
                {
                case Direction.North:
                    return(RoomPositions[RoomPosition.Two]);

                case Direction.West:
                    return(RoomPositions[RoomPosition.Three]);

                default:
                    break;
                }
                break;

            default:
                break;
            }
            return(null);
        }
Esempio n. 14
0
        public MoveResults MovePlayer(Direction direction)
        {
            MoveResults result = MoveResults(direction);

            if (result.Success)
            {
                if (FullyMerged() || Lock.Locked)
                {
                    CurrentRoomPosition = GetAdjoiningRoomPosition(CurrentRoomPosition, direction);
                }
                else
                {
                    switch (Level)
                    {
                    case Types.Level.One:
                        switch (direction)
                        {
                        case Direction.East:
                        case Direction.West:
                            RotateRooms(CurrentRoomPosition, direction);
                            break;

                        case Direction.North:
                        case Direction.South:
                            FlipRooms(direction);
                            break;
                        }
                        break;

                    case Types.Level.Two:
                        switch (direction)
                        {
                        case Direction.North:
                        case Direction.South:
                            RotateRooms(CurrentRoomPosition, direction);
                            break;

                        case Direction.East:
                        case Direction.West:
                            FlipRooms(direction);
                            break;
                        }
                        break;
                    }

                    if (FullyMerged())
                    {
                        AddCards();
                    }
                }
            }

            if (result.Success)
            {
                BaseRoom room = RoomPositions[CurrentRoomPosition];
                result.PrintInstructions.NewLine("You enter the ", ConsoleColor.DarkGreen)
                .Add(RoomInfo[room.Id].Name, room.Color)
                .Add(" room.", ConsoleColor.DarkGreen);
            }

            PrintInstructions mergedMessage = MergedDescription();

            mergedMessage.AddInstructions(result.PrintInstructions);

            result.PrintInstructions = mergedMessage;

            return(result);
        }