Geo*_*ion 0 c# arrays variables
我正在做一个(非常基本的)游戏.因此,我需要为(很多)实体存储数据.
所以我提出了这个概念:
String[] Entity_Data = new String[EntityCount];
Entity_Data[0] = "1 12 98 45";//Or other numbers...
Run Code Online (Sandbox Code Playgroud)
第一个数字可能是饥饿状态或步行速度,甚至是X或Y坐标.
有没有办法为数组中的每个变量赋予多个值?
对于如何在单个变量中存储多个值的基本问题,请使用List,Dictionary或Tuple之类的内容:
List<String> items = new List<String>() {
"one", "two", "three"
};
Dictionary<String, String> items = new Dictionary<String, String>() {
{"name 1", "value 1"},
{"name 2", "value 2"}
{"name 3", "value 3"}
};
var items = new Tuple<string, int, int>("Bad Guy", 100, 50);
Run Code Online (Sandbox Code Playgroud)
那就是说,你做错了.创建一个类并使用完全限定的属性/属性.像这样的东西:
public class Enemy {
private Int32 MaxHitPoints;
private Int32 CurrentHitPoints;
private Int32 Strength;
private Int32 Speed;
private List<Weapons>;
public Hit(Int32 power) {
CurrentHitPoints = CurrentHitPoints - power;
if (CurrentHitPoints <= 0) {
Die();
Explode();
MakeAMess();
}
}
}
Run Code Online (Sandbox Code Playgroud)
等等......可能值得在game-dev.SE上阅读 /提问.