Beispiel #1
0
        public static TWEntity?GetPlayersCurrentRoom(TWEntity playerEntity, List <TWEntity> roomEntities)
        {
            TWEntity?result          = null;
            var      roomIdComponent = playerEntity.GetComponentByName <IdComponent>("player current room");

            if (roomIdComponent != null)
            {
                result = roomEntities.FirstOrDefault(x => x.Id == roomIdComponent.Id);
            }

            return(result);
        }
Beispiel #2
0
        public void CanRemoveEntityComponent()
        {
            // Arrange
            var    entity        = new TWEntity("test entity");
            string componentName = "test description component";
            string description   = "This is a test description";

            entity.AddComponent(new DescriptionComponent(componentName, description));
            // Act
            var component = entity.GetComponentByName <DescriptionComponent>(componentName);

            if (component != null)
            {
                entity.RemoveComponent(component);
            }

            // Assert
            entity.Components.Should().BeEmpty();
        }
Beispiel #3
0
        public void CanGetEntityComponentByName()
        {
            // Arrange
            var    entity        = new TWEntity("test entity");
            string componentName = "test description component";
            string description   = "This is a test description";

            entity.AddComponent(new DescriptionComponent(componentName, description));
            // Act
            var component = entity.GetComponentByName <DescriptionComponent>(componentName);

            // Assert
            component.Should().NotBeNull();

            if (component != null)
            {
                component.Name.Should().Be(componentName);
                component.Description.Should().Be(description);
            }
        }
Beispiel #4
0
        public override void Run(TWEntity commandEntity, TWEntity playerEntity, List <TWEntity> roomEntities, TWEntity outputEntity)
        {
            TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
            var      processedComponents = new List <CommandComponent>();

            foreach (var commandComponent in commandEntity.GetComponentsByType <CommandComponent>())
            {
                var commandAsTitleCase = myTI.ToTitleCase(commandComponent.Command !);

                if (Enum.TryParse <Direction>(commandAsTitleCase, out Direction direction))
                {
                    processedComponents.Add(commandComponent);

                    var currentRoomComponent = playerEntity.GetComponentByName <IdComponent>("player current room");
                    var currentRoomEntity    = roomEntities.FirstOrDefault(x => x.Id == currentRoomComponent !.Id);
                    var currentRoomExits     = currentRoomEntity !.GetComponentsByType <ExitComponent>();
                    var exit = currentRoomExits.FirstOrDefault(x => x.Direction.ToString() == commandAsTitleCase);

                    if (exit != null)
                    {
                        var newRoomEntity = roomEntities.FirstOrDefault(x => x.Id == exit.RoomId);

                        if (newRoomEntity != null)
                        {
                            currentRoomComponent !.Id = newRoomEntity.Id;

                            playerEntity.AddComponent(new ShowDescriptionComponent("player new room", newRoomEntity, DescriptionType.Room));
                            playerEntity.AddComponent(Helper.GetRoomExitInfoForRoom(playerEntity, roomEntities, newRoomEntity));
                        }
                    }
                    else
                    {
                        outputEntity.AddComponent(new OutputComponent("output for inaccessible direction", "I cannot go in that direction", OutputType.Regular));
                    }

                    commandEntity.RemoveComponents(processedComponents);
                }
            }
        }