I'm beginning the long process of developing an Adventure Game/RPG and I was hoping to get some review on a resource system I'm coming up with. How it works is, a resource is generic to every resource in the world. Each resource will have a name, a random yield, and a random quality. So I've created an interface for the generic properties and function each resource will have.
Interface
public interface IResource{
string Name {get;set;}
string Quality {get;set;}
int Yield{get;set;}
string ConvertQualityToString();
int GetResourceYield();
}
Then I implement the interface in an actual resource base class.
Implementation
public class Resource : MonoBehaviour, IResource{
public string Name { get; set; }
public string Quality { get; set; }
public int Yield { get; set; }
public string ConvertQualityToString(){
var val = Random.Range(0, 3);
string quality;
switch (val){
case 1:
quality = "Good";
break;
case 2:
quality = "Great";
break;
default:
quality = "Poor";
break;
}
return quality;
}
public int GetResourceYield(){
var val = Random.Range(1, 25);
return val;
}
}
And finally, I create the specific resource itself and attach it to my game object in the inspector.
Resource Class
public class Granite : Resource{
void Start(){
Name = "Granite";
Quality = ConvertQualityToString();
Yield = GetResourceYield();
}
}
Is this the proper way to work this system? Obviously, the system actually does work as when I log the values on startup, Yield
and Quality
are randomized and the Name
for each resource object I create is correct. Is there a better way to do this? Are there things I should change? Thanks in advance.