public void AllTypesHaveStorages()
    {
        ResourcesStorage storages = new ResourcesStorage();

        Assert.AreEqual(0, storages.NextAmount(ResourceType.Air));
        Assert.AreEqual(0, storages.NextAmount(ResourceType.Food));
        Assert.AreEqual(0, storages.NextAmount(ResourceType.Water));
    }
    public void TryAddRejectsAllDeltas()
    {
        var storages = new ResourcesStorage();

        storages.TryAddDeltas(new[]
        {
            new ResourceDelta(ResourceType.Air, 20), new ResourceDelta(ResourceType.Air, -30),
            new ResourceDelta(ResourceType.Food, 20)
        });

        Assert.AreEqual(0, storages.NextAmount(ResourceType.Air));
        Assert.AreEqual(0, storages.NextAmount(ResourceType.Food));
    }
    public void HappyCase()
    {
        var storages = new ResourcesStorage();

        storages.AddDelta(new ResourceDelta(ResourceType.Air, 20));
        storages.AddDelta(new ResourceDelta(ResourceType.Food, -20));

        Assert.AreEqual(20, storages.NextAmount(ResourceType.Air));
        Assert.AreEqual(-20, storages.NextAmount(ResourceType.Food));

        storages.Tick();

        Assert.AreEqual(20, storages.NextAmount(ResourceType.Air));
        Assert.AreEqual(20, storages.ResourceStorages[ResourceType.Air].CurrentAmount);
    }
Exemplo n.º 4
0
    public void TestUpkeep()
    {
        var station = new Station();
        ResourcesStorage storage = station.ResourcesStorage;

        storage.AddDelta(new ResourceDelta(ResourceType.Air, 20));
        station.DoTurn();
        station.AddUpkeepDelta(new ResourceDelta(ResourceType.Air, -10));

        // upkeep depletes stored resource first
        Assert.AreEqual(10, storage.NextAmount(ResourceType.Air));

        station.DoTurn();
        Assert.AreEqual(0, storage.NextAmount(ResourceType.Air));

        // and will launch resources via the rocket instead of going negative
        station.DoTurn();
        Assert.AreEqual(0, storage.NextAmount(ResourceType.Air));
    }
Exemplo n.º 5
0
    private void TryCompleteProjects(Rocket rocket)
    {
        numCompletedProjectsNextTurn = 0;
        foreach (Project project in projects)
        {
            // Figure out what resources still need to be launched.
            IEnumerable <ResourceDelta> remainingCosts = from cost in project.Cost
                                                         let remaining = cost.Amount - ResourcesStorage.NextAmount(cost.Type)
                                                                         where remaining > 0
                                                                         select new ResourceDelta(cost.Type, remaining);

            // If the rocket doesn't have room for all this, we can't complete this project
            if (!rocket.TryAddCargo(remainingCosts))
            {
                break;
            }

            // This project will be completed this tick.
            numCompletedProjectsNextTurn++;

            // Its resources will be included in the rocket's cargo
            // TODO and hopefully there's space in space for all of it!
            if (!ResourcesStorage.TryAddDeltas(remainingCosts))
            {
                throw new Exception();
            }

            // And they'll be deducted from the storage after that
            ResourcesStorage.TryAddDeltas(project.Cost.Select(cost => new ResourceDelta(cost.Type, -cost.Amount)));
        }
    }