Advertisement
shadowplaycoding

P030_Resources

Jul 20th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public enum ResourceType { Food, Minerals, Credits }
  6.  
  7. public class Resources {
  8.  
  9.     public int credits { get; set; }
  10.     public int minerals { get; set; }
  11.     public int food { get; set; }
  12.  
  13.     public Resources(int credits, int minerals, int food)
  14.     {
  15.         this.credits = credits;
  16.         this.minerals = minerals;
  17.         this.food = food;
  18.     }
  19.  
  20.     // Adds an amount to a resource
  21.     // 0 = all resources
  22.     // 1 = credits
  23.     // 2 = minerals
  24.     // 3 = food
  25.     public void AddResource(int resource, int amount)
  26.     {
  27.         switch (resource) {
  28.             case 0:
  29.                 this.credits = this.credits + amount;
  30.                 this.minerals = this.minerals + amount;
  31.                 this.food = this.food + amount;
  32.                 break;
  33.             case 1:
  34.                 this.credits = this.credits + amount;
  35.                 break;
  36.             case 2:
  37.                 this.minerals = this.minerals + amount;
  38.                 break;
  39.             case 3:
  40.                 this.food = this.food + amount;
  41.                 break;
  42.             default:
  43.                 Debug.LogError("Unknown Resource!");
  44.                 break;
  45.         }
  46.     }
  47.  
  48.     public void AddResource(ResourceType type, int amount)
  49.     {
  50.         switch (type)
  51.         {
  52.             case ResourceType.Food:
  53.                 this.food += amount;
  54.                 break;
  55.  
  56.             case ResourceType.Minerals:
  57.                 this.minerals += amount;
  58.                 break;
  59.  
  60.             case ResourceType.Credits:
  61.                 this.credits += amount;
  62.                 break;
  63.  
  64.             default:
  65.                 Debug.LogError("Unknown Resource!");
  66.                 break;
  67.         }
  68.     }
  69.  
  70.     // Subtracts an amount to a resource
  71.     // 0 = all resources
  72.     // 1 = credits
  73.     // 2 = minerals
  74.     // 3 = food
  75.     public void SubtractResource(int resource, int amount)
  76.     {
  77.         switch (resource)
  78.         {
  79.             case 0:
  80.                 this.credits = this.credits - amount;
  81.                 this.minerals = this.minerals - amount;
  82.                 this.food = this.food - amount;
  83.                 break;
  84.             case 1:
  85.                 this.credits = this.credits - amount;
  86.                 break;
  87.             case 2:
  88.                 this.minerals = this.minerals - amount;
  89.                 break;
  90.             case 3:
  91.                 this.food = this.food - amount;
  92.                 break;
  93.             default:
  94.                 Debug.LogError("Unknown Resource!");
  95.                 break;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement