[英]In Java how would I reference a whole object within a its own class?
I have this in a class called Pokemon and what I would like to do is reference the current object as a whole and pass it through int .use.我在一个名为 Pokemon 的类中有这个,我想做的是将当前对象作为一个整体引用并通过 int .use 传递它。 (I know that you can reference specific pieces of data based on the object using it so I would assume you could do it for the object as a whole) Any help would be greatly appreciated.
(我知道您可以根据使用它的对象引用特定的数据片段,因此我假设您可以为整个对象执行此操作)任何帮助将不胜感激。
public boolean attack(int m,Pokemon p) {
boolean hit = true;
//check what move the use and take away a pp and return it
if (m == 1) {
hit = m1.use(p.getType1(), p.getType2(),**this is where I want to pass the object**);
if (hit == true) {
return true;
} else {
return false;
}
} else if (m == 2) {
hit = m2.use(p.getType1(), p.getType2(),**this is where I want to pass the object**);
if (hit == true) {
return true;
} else {
return false;
}
} else if (m == 3) {
hit = m3.use(p.getType1(), p.getType2(),**this is where I want to pass the object**);
if (hit == true) {
return true;
} else {
return false;
}
} else if (m == 4) {
hit = m4.use(p.getType1(), p.getType2(),**this is where I want to pass the object**);
if (hit == true) {
return true;
} else {
return false;
}
} else {
return true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.