-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNation.java
More file actions
198 lines (197 loc) · 5.91 KB
/
Copy pathNation.java
File metadata and controls
198 lines (197 loc) · 5.91 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import java.util.*;
/**
* The route class allows adding them to
* the world canvas, contain armies, be
* conquered and others
*
* @author Cesar Vasquez - Ronaldo Henao
* @version 1.0 (September 2nd, 2021)
*/
public class Nation
{
private final int ANCHO = 20;
private final int ALTO = 20;
private String color;
private int xPosition,yPosition;
private int nArmies;
private Rectangle world;
private Rectangle visual;
private Rectangle marca = new Rectangle(ALTO/2,ANCHO/2);
private ArrayList<Route> properRoutes = new ArrayList<Route>();
private boolean conquered;
private boolean isVisible;
/**
* Creates a nation with an army number and is
* identified by a unique color
*/
public Nation(String color, int x, int y, int nArmies, Rectangle world){
this.color = color;
this.world = world;
xPosition = getPositionX(x);
yPosition = getPositionY(y);
this.nArmies = nArmies;
isVisible = false;
visual = new Rectangle(ANCHO,ALTO);
conquered = false;
configureVisual();
}
/**
* This method returns the Y coordinate of
* the world canvas.
* @ return YPosition, YPosition is the Y coordinate of the world canvas
*/
public int extractYCoordinate(){
return world.getYPosition();
}
/**
* This method returns the X coordinate of
* the world canvas.
* @ return XPosition, XPosition is the X coordinate of the world canvas
*/
public int extractXCoordinate(){
return world.getXPosition();
}
/**
* This method returns the x coordinate of the
* nation which must be within the world canvas
* @ return xPosition, xPosition fits the canvas of the world
*/
public int getXPos(){
return this.xPosition+ANCHO/2;
}
/**
* This method returns the number of armed
* @ return nArmies, nArmies is the number of armed
*/
public int getArmies(){
return nArmies;
}
/**
* This method returns whether a natio is conquered or not
* @ return conquered, conquered say if it is true or false
*/
public boolean conquest(){
return this.conquered;
}
/**
* This method places a nation as conquered
* @ param conquista, conquista is the nation to conquer
*/
public void setConquest(boolean conquista){
this.conquered = conquista;
update();
}
/**
* This method returns the y coordinate of the
* nation which must be within the world canvas
* @ return yPosition, yPosition fits the canvas of the world
*/
public int getYPos(){
return this.yPosition+ALTO/2;
}
/**
* This method returns the color of the nation
* @ return color, color is the identifier of the nation
*/
public String getColor(){
return this.color;
}
/**
* This method locates the nation on the canvas of the world
* with its respective color and strict location
*/
public void configureVisual(){
visual.changeColor(color);
visual.changePosition(xPosition, yPosition);
String nArmy = Integer.toString(this.nArmies);
visual.setString(nArmy);
if (conquered){
marca.changeColor("black");
marca.changePosition(xPosition+5, yPosition+5);
}
else marca.changeColor(color);
}
/**
* This method updates the nation's data
*/
public void update(){
configureVisual();
if (isVisible) makeVisible();
}
/**
* This method makes the nation visible
*/
public void makeVisible(){
isVisible = true;
visual.makeVisible();
if(conquered)marca.makeVisible();
}
/**
* This method makes the nation invisible
*/
public void makeInvisible(){
isVisible = false;
visual.makeInvisible();
}
/**
* This method adds an army to a nation
*/
public void addArmy(){
nArmies ++;
update();
}
/**
* This method removes an army from a nation
*/
public void delArmy(){
nArmies --;
update();
}
/**
* This method adds a route of the nation with another
* @ param ruta, ruta is the new route for the nation with another
* @ param rutas, rutas is added to the world is routes
* @ param nation2, nation2 is the nation with which a route will be created
*/
public void addRoute(Route ruta, ArrayList<Route> rutas,Nation nation2){
rutas.add(ruta);
properRoutes.add(ruta);
nation2.addRoute(ruta);
}
/**
* This method adds a new route to the nation is own routes
* @ param ruta, ruta will be added to the nation is own routes
*/
public void addRoute(Route ruta){
if (!properRoutes.contains(ruta))properRoutes.add(ruta);
}
/**
* This method removes a nation from the world canvas
*/
public void delNation(ArrayList<Route> rutas){
this.makeInvisible();
for(Route i: properRoutes) i.delRoute(rutas);
rutas.removeAll(properRoutes);
}
/*
* This method returns the Y coordinate of the nation
* of the taking into account the world canvas
* @ param yPosition, yPosition is the Y coordinate of the antion
*/
private int getPositionY(int yPosition){
int total = world.getHeight();
if (yPosition == 0) return total - yPosition +
world.getYPosition() - ALTO;
return total - yPosition + world.getYPosition();
}
/*
* This method returns the X coordinate of the nation
* of the taking into account the world canvas
* @ param xPosition, xPosition is the X coordinate of the antion
*/
private int getPositionX(int xPosition){
int total = world.getXPosition();
if (xPosition == 0) return total + xPosition;
return total + xPosition-ANCHO;
}
}