Ejemplo n.º 1
0
        // Subtract the passed Resources from the player
        public static void SpendResources(Dictionary <ResourceType, int> spentResources)
        {
            if (!HasResources(spentResources))
            {
                return;                                                 // verify the player has enough resources
            }
            foreach (var spentResource in spentResources)               // subtract each spent resource from the player
            {
                _saveFile.Resources[spentResource.Key] -= spentResource.Value;
            }

            OnResourceChangedAction?.Invoke(_saveFile.Resources);
        }
Ejemplo n.º 2
0
        // Add the passed Resources to the player
        public static void AddResources(Dictionary <ResourceType, int> addResources)
        {
            if (addResources == null)
            {
                return;                                         // function is called after every level ends, regardless of whether any resources were gained
            }
            foreach (var addResource in addResources)
            {
                _saveFile.Resources[addResource.Key] += addResource.Value;
            }

            OnResourceChangedAction?.Invoke(_saveFile.Resources);
        }