我是编程和 OOP 的新手,所以请原谅我缺乏知识。
作为我的 Rock、Paper 和 Scissors 游戏的一部分,我想在 VB.NET 中创建一个具有子类(Rock、Paper 和 Scissors)的抽象超类(武器)。我找到了 JAVA 等价物:
public abstract class Weapon implements Comparable<Weapon> {
}
public class Paper extends Weapon {
@Override
public int compareTo(Weapon o) {
if (o instanceof Paper)
return 0;
else if (o instanceof Rock)
return 1;
return -1;
}
}
public class Rock extends Weapon {
@Override
public int compareTo(Weapon o) {
if (o instanceof Rock)
return 0;
else if (o instanceof Scissors)
return 1;
return -1;
}
}
public class Scissors extends Weapon {
@Override
public int compareTo(Weapon o) {
if (o instanceof Scissors)
return 0;
else if (o instanceof Paper)
return 1;
return -1;
}
}
我目前有以下内容:
Public MustInherit Class Weapons
Public Class Rock
Inherits Weapons
Public Function compareTo(ByVal Weapons As Object) As Integer
End Function
End Class
Public Class Paper
Inherits Weapons
Public Function compareTo(ByVal Weapons As Object) As Integer
End Function
End Class
Public Class Scissors
Inherits Weapons
Public Function compareTo(ByVal Weapons As Object) As Integer
End Function
End Class
结束类
有人可以更正代码,以便可以比较 Rock、Paper 和 Scissors 对象。任何帮助将不胜感激。
谢谢