📄 continent.java
字号:
// Yura Mamyrin, Group D
package risk.engine.core;
import java.util.*;
import java.awt.Color;
import java.io.*;
/**
* <p> Continent </p>
* @author Yura Mamyrin
*/
public class Continent implements Serializable {
private static final long serialVersionUID = 1L;
private String idString; // used by the map editor
private String name;
private Color color;
private int armyValue;
private Vector territoriesContained = new Vector();
/**
* Creates a continent object
* @param n the continent name
* @param c the continent colour
* @param noa the number of armies recieved when the whole continent is owned
*/
public Continent(String id, String n, int noa, Color c) {
idString = id;
name = n;
color = c;
armyValue = noa;
}
public String toString() {
if (armyValue!=0) {
return idString+" ["+armyValue+"]";
}
return idString;
}
public String getIdString() {
return idString;
}
public void setIdString(String a) {
idString = a;
}
/**
* Returns the name of the continent
* @return name
*/
public String getName() {
return name;
}
public void setName(String a) {
name = a;
}
/**
* Returns the colour of the continent
* @return color
*/
public Color getColor() {
return color;
}
public void setColor(Color a) {
color = a;
}
/**
* Returns the number of armies the continent is worth
* @return armyValue
*/
public int getArmyValue() {
return armyValue;
}
public void setArmyValue(int a) {
armyValue = a;
}
/**
* Checks if the player owns all the territories within a continent
* @param p player object
* @return true if the player owns all the territories within a continent,
* otherwise false if the player does not own the all the territories
*/
public boolean isOwned(Player p) {
int ownedByPlayer=0;
for (int c=0; c< territoriesContained.size() ; c++) {
if ( ((Country)territoriesContained.elementAt(c)).getOwner() == p ) {
ownedByPlayer++;
}
}
if ( ownedByPlayer==territoriesContained.size() ) {
return true;
}
else {
return false;
}
}
/**
* Returns a vector of the territories contained within a continent
* @return territoriesContained
*/
public Vector getTerritoriesContained() {
return territoriesContained;
}
/**
* Adds country to a continent
* @param t the country object
*/
public void addTerritoriesContained(Country t) {
territoriesContained.add(t);
}
public boolean equals(Object o) {
return (o != null &&
o instanceof Continent &&
((Continent)o).name.equals(name) &&
((Continent)o).idString.equals(idString) &&
((Continent)o).armyValue == armyValue
);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -