所以我有Gitem型
type Gitem =
|Weapon of Weapon
|Bomb of Bomb
|Monster of Monster
|Armour of Armour
|Potion of Potion
|None
Run Code Online (Sandbox Code Playgroud)
这用于在记录中存储不同类型的对象,要清楚,我遇到问题的类型如下所示:
type Monster={
name:string;
dVal:float;
dType:DamType;
hVal:float;
info:string;
dInfo:string;
dCry:string;
Special:bool;
sItem:obj;
}
type Armour={
name:string;
aVal:float;
dType:DamType;
info:string;
iSpace:int;
hidden:bool;
}
type Weapon={
name:string;
dVal:float;
dType:DamType;
info:string;
iSpace:int;
hidden:bool;
}
Run Code Online (Sandbox Code Playgroud)
问题是,Gitem将Monster作为一种潜在类型,但是怪物可以拥有炸弹,武器或盔甲作为他们的系统,因此我制造了类型物体.后来在我的代码中写道:
match monster.sItem with //gives them the item if the monster drops one
| Bomb bomb ->
procBomb bomb
| Weapon weap ->
procWeap weap
| Potion pot -> …Run Code Online (Sandbox Code Playgroud) f# ×1