【发布时间】:2020-03-01 16:43:33
【问题描述】:
我知道有一些关于此的帖子,但我找不到任何适合我的问题的帖子。
我开始用 Java 重新创建一个旧的 Flash 游戏,然后我切换到了 unity。
现在我坚持将包含 java 枚举的类移植到 C#
例如,我有以下课程:
物品
武器(扩展物品)
Sword (extends Weapon) Sword 包含枚举类型
enum Type{
//Name min max price 2hand baselvl ranged
Falchion ( 1, 4, 324, false, (byte) 1, false),
Shortsword ( 1, 5, 346, false, (byte) 1, false),
Cutlass ( 2, 6, 411, false, (byte) 3, false),
Throwingknife ( 2, 9, 478, false, (byte) 3, true), //RANGED
Longsword ( 2, 8, 567, true, (byte) 5, false), //TWOHANDED
Broadsword ( 4, 8, 690, false, (byte) 7, false),
Katana ( 4, 11, 807, true, (byte) 9, false), //TWOHANDED
Saber ( 7, 12, 1210, false, (byte) 10, false),
Flamberge ( 8, 17, 1623, true, (byte) 13, false), //TWOHANDED
Lightsaber (12, 20, 2732, false, (byte) 15, false);
final int minDMG;
final int maxDMG;
final int price;
final byte baseLVL;
final boolean twoHanded;
final boolean ranged;
private Type(int minD, int maxD, int p, boolean twoHa, byte bLVL, boolean r) {
this.minDMG = minD;
this.maxDMG = maxD;
this.price = p;
this.twoHanded = twoHa;
this.baseLVL = bLVL;
this.ranged = r;
}
public static final Type[] types = Type.values();
public static Type getType(int i) {
return Type.types[i];
}
}
对于我使用的剑的构造器:
public Sword(int Index) {
super("Sword",2,""+types[Index], types[Index].minDMG,types[Index].maxDMG,types[Index].price,types[Index].twoHanded,types[Index].baseLVL,types[Index].ranged);
}
武器:
public Weapon(String wCl, int wCID, String n,int minD, int maxD, int p, boolean twoHa, byte bLVL, boolean r) {
super("Weapon",n,minD,maxD,p,twoHa, bLVL,r);
this.weaponClass = wCl;
this.weaponClassID = wCID;
}
最后是项目:
public Item(String iC, String n,int minD, int maxD, int p, boolean twoHa, byte bLVL,boolean r) {
//Weapon
this.condition = initCondition();
this.name = n;
this.minDMG = minD * this.condition.multiplier + ((this.condition.multiplier - 1) * 1);
this.maxDMG = maxD * this.condition.multiplier + ((this.condition.multiplier - 1) * 1);
this.price = p * this.condition.multiplier*13;
this.twohanded = twoHa;
this.bodypart = "Hands";
this.ranged = r;
}
初始化它我可以写
Item i = new Sword(0);
我在 C# 中找不到好的解决方案
我在 Item 类中用于 Condition 枚举的第一个解决方案是创建一个新的 c# 类“Condition”
public class Condition
{
readonly string name;
readonly int multiplier;
readonly string color = "GREY";
public Condition(string n, int m, string c) {
this.name = n;
this.multiplier = m;
this.color = c;
}
然后在 Item 类中构建一个用于选择和初始化所述 Condition 的方法
public Condition condition;
public Item(int _luck)
{
this.condition = generateCondition(conditionSelector(_luck));
}
private Condition generateCondition(int selector)
{
if (selector == 0) return new Condition("Godlike" , 15, "YELLOW" ); // 0 --> 1% MAX LVL LUCK Percentage: 0 --> 2%
else if (selector >= 1 && selector <= 2) return new Condition("Legendary" , 10, "WHITE" ); // 1 - 2 --> 2% MAX LVL LUCK Percentage: 1 - 2 --> 4%
else if (selector >= 3 && selector <= 5) return new Condition("Mythical" , 8, "PURPLE" ); // 3 - 5 --> 3% MAX LVL LUCK Percentage: 3 - 5 --> 6%
else if (selector >= 6 && selector <= 9) return new Condition("Ultra Rare", 5, "DARKBLUE" ); // 6 - 9 --> 4% MAX LVL LUCK Percentage: 6 - 9 --> 8%
else if (selector >= 10 && selector <= 14) return new Condition("Rare" , 3, "LIGHTBLUE"); // 10 - 14 --> 5% MAX LVL LUCK Percentage: 10 - 14 --> 10%
else if (selector >= 15 && selector <= 20) return new Condition("Uncommon" , 2, "GREEN" ); // 15 - 20 --> 6% MAX LVL LUCK Percentage: 15 - 20 --> 12%
else if (selector >= 15 && selector <= 20) return new Condition("Common" , 1, "GREY" ); // 21 - 99 --> 79% MAX LVL LUCK Percentage: 21 - 49 --> 58%
return new Condition("Common", 1, "GREY");
}
这适用于项目的条件部分。
但我没有找到将其他类移植到 C# 的好方法
我不知道如何使用 super 等效的 base 使其适合我的项目
如果你有帖子可以帮助我完成我的项目,你可以在下面链接
注意:这是一个私人项目,与任何家庭作业或学习相关的东西无关
【问题讨论】: