Advertisement
shadowplaycoding

P021_Resources

Jun 12th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Resources {
  6.  
  7.     public int credits { get; set; }
  8.     public int minerals { get; set; }
  9.     public int food { get; set; }
  10.  
  11.     public Resources(int credits, int minerals, int food)
  12.     {
  13.         this.credits = credits;
  14.         this.minerals = minerals;
  15.         this.food = food;
  16.     }
  17.  
  18.     // Adds an amount to a resource
  19.     // 0 = all resources
  20.     // 1 = credits
  21.     // 2 = minerals
  22.     // 3 = food
  23.     public void AddResource(int resource, int amount)
  24.     {
  25.         switch (resource) {
  26.             case 0:
  27.                 this.credits = this.credits + amount;
  28.                 this.minerals = this.minerals + amount;
  29.                 this.food = this.food + amount;
  30.                 break;
  31.             case 1:
  32.                 this.credits = this.credits + amount;
  33.                 break;
  34.             case 2:
  35.                 this.minerals = this.minerals + amount;
  36.                 break;
  37.             case 3:
  38.                 this.food = this.food + amount;
  39.                 break;
  40.             default:
  41.                 Debug.LogError("Unknown Resource!");
  42.                 break;
  43.         }
  44.     }
  45.  
  46.     // Subtracts an amount to a resource
  47.     // 0 = all resources
  48.     // 1 = credits
  49.     // 2 = minerals
  50.     // 3 = food
  51.     public void SubtractResource(int resource, int amount)
  52.     {
  53.         switch (resource)
  54.         {
  55.             case 0:
  56.                 this.credits = this.credits - amount;
  57.                 this.minerals = this.minerals - amount;
  58.                 this.food = this.food - amount;
  59.                 break;
  60.             case 1:
  61.                 this.credits = this.credits - amount;
  62.                 break;
  63.             case 2:
  64.                 this.minerals = this.minerals - amount;
  65.                 break;
  66.             case 3:
  67.                 this.food = this.food - amount;
  68.                 break;
  69.             default:
  70.                 Debug.LogError("Unknown Resource!");
  71.                 break;
  72.         }
  73.     }
  74.  
  75.     /*
  76.     Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  77.     Removing this comment forfits any rights given to the user under licensing.
  78.     */
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement