使用此函数,我试图查看 myPlayerUp(玩家对象)是否等于玩家向量 myPlayers 中的任何玩家对象。它是说“方法 myPlayers(int) 未定义该类型”,即使上面使用了向量。我要以错误的方式进行比较吗?这是全班
package model;
//import yahtzee.model.boolean;
import java.util.Vector;
//import yahtzee.model.int;
//import yahtzee.model.void;
import model.Player;
public class YahtzeeEngine {
public static final int MAX_ROLLS= 0;
private Vector<Player> myPlayers;
private Roller myRoller;
private Player myPlayerUp;
private int myNumberRollsUsed;
public Vector myPlayer;
public YahtzeeEngine(int numPlayers) {
myPlayers = new Vector<Player>(numPlayers);
myNumberRollsUsed = 0;
}
public void startGame() {
int i;
for(i = 0; i<=myPlayers.size(); i++){
myPlayers.add(new Player());
}
this.selectPlayerUp(myPlayers.get(0));
myNumberRollsUsed = 0;
myRoller = new Roller();
myPlayerUp = new Player();
}
public void selectPlayerUp(Player player) {
myPlayerUp = player;
}
public void switchPlayerUp() {
int x;
int y;
for(x = 0; x<=myPlayers.size(); x++){
if(myPlayerUp == myPlayers(x) && x < myPlayers.size()-1){
y = x;
}
if(myPlayerUp == myPlayers(x) && x == myPlayers.size()-1){
y = 0;
}
}
myPlayerUp = myPlayers(y);
}
public boolean incrementRollsUsed() {
myNumberRollsUsed++;
return false;
}
public void resetNumberRollsUsed() {
myNumberRollsUsed = 0;
}
public Roller getRoller() {
return myRoller;
}
public Player getPlayerUp() {
return myPlayerUp;
}
public Vector<Player> getPlayers() {
return myPlayers;
}
public int getNumberRollsUsed() {
return myNumberRollsUsed;
}
public String toString() {
return null;
}
}
这是它给我“myPlayers”向量错误的地方
public void switchPlayerUp() {
int x;
int y;
for(x = 0; x<=myPlayers.size(); x++){
if(myPlayerUp == myPlayers(x) && x < myPlayers.size()-1){
y = x;
}
if(myPlayerUp == myPlayers(x) && x == myPlayers.size()-1){
y = 0;
}
}
myPlayerUp = myPlayers(y);
}