-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCountry.java
More file actions
90 lines (73 loc) · 1.99 KB
/
Country.java
File metadata and controls
90 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.ArrayList;
/**
* Allows the creation of Risk Country objects.
* @author Ted Mader
* @version Alpha
* @date 5/02/14
**/
public class Country {
private int armies;
private boolean hasPlayer;
private String name;
private Player occupant;
private ArrayList<Country> adjacencies;
public Country(String name) {
this.name = name;
hasPlayer = false;
armies = 0;
System.out.println("Created country: " + name);
}
/**
* Used only when contstructing the country object, it should not be called after
* the board is initialized
**/
public void addAdjacencies(ArrayList<Country> adjacencies) {
this.adjacencies = adjacencies;
}
public String getName() {
return name;
}
/**
* When a player conquers a country the player object is set as the occupant of the
* country
**/
public void setOccupant(Player occupant) {
hasPlayer = true;
this.occupant = occupant;
}
/**
* Returns the player object who currently occupies the country
**/
public Player getOccupant() {
return occupant;
}
/**
* Used to set the number of armies currently stationed in this country
**/
public void setNumArmies(int numArmies) {
armies = numArmies;
}
public void incrementArmies(int numArmies) {
armies = armies + numArmies;
System.out.println(occupant.getName() + " added " + numArmies + " armies to " + name + ".");
}
public void decrementArmies(int numArmies) {
armies = armies - numArmies;
System.out.println(occupant.getName() + " lost " + numArmies + " armies in " + name + ".");
}
/**
* Returns the number of armies currently stationed in this country
**/
public int getArmies() {
return armies;
}
/**
* Returns a list of the country objects that are adjacent to this country on the baord
**/
public ArrayList<Country> getAdjacencies() {
return adjacencies;
}
public boolean hasPlayer() {
return hasPlayer;
}
}