-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinente.java
More file actions
154 lines (136 loc) · 3.95 KB
/
Copy pathContinente.java
File metadata and controls
154 lines (136 loc) · 3.95 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package risk;
import java.util.ArrayList;
import java.util.Iterator;
/**
*
* @author landr
*/
public class Continente {
String abreviatura;
String nombre;
String color;
ArrayList<Pais> paises = new ArrayList();
public Continente(String nombre, String color, String abreviatura)
{
this.color = color;
this.nombre = nombre;
this.abreviatura = abreviatura;
}
@Override
public String toString()
{
String out = new String();
ArrayList <Jugador> jugadores = new ArrayList<>();
boolean ultimo;
int ejercitos;
out = "{\nnombre: \"" + nombre + "\",\n";
out += "abreviatura: \"" + abreviatura + "\",\n";
out += "jugadores: [ ";
for(int i = 0; i < paises.size(); i++){
Jugador jugador = paises.get(i).getJugador();
if(!jugadores.contains(jugador))
jugadores.add(jugador);
}
for(int i = 0; i < jugadores.size(); i++){
ejercitos = 0;
ultimo = true;
for(Pais pais: jugadores.get(i).getPaises()){
if(pais.getContinente().equals(this)){
ejercitos += pais.getNumeroEjercito();
}
}
out += "{ \"" + jugadores.get(i).getNombre() + "\", " + ejercitos + " }";
for(int j = i+1; j < jugadores.size(); j++){
for(Pais pais: jugadores.get(i).getPaises()){
if(pais.getContinente().equals(this) && (pais.getNumeroEjercito() != 0)){
ultimo = false;
}
}
}
if(!ultimo){
out += ", ";
}
}
out += " ],\n";
out += "numeroEjercitos: " + this.numeroEjercitos() + ",\n";
out += "rearmeContinente: " + this.rearmeContinente() + "\n";
out += "}";
return out;
}
@Override
public boolean equals(Object comparando) {
Continente aux = (Continente) comparando;
return (this.getNombre().equals(aux.getNombre()));
}
//Los getters de continente
public String getNombre()
{
return nombre;
}
public String getColor()
{
return color;
}
public ArrayList<Pais> getPaises()
{
return paises;
}
public String getAbreviatura()
{
return abreviatura;
}
//Los setters de continente
public void setColor(String color)
{
this.color = color;
}
public void seNombre(String nombre)
{
this.nombre = nombre;
}
public void setPaises(ArrayList paises)
{
this.paises = paises;
}
int numeroEjercitos()
{
int num = 0;
for(Pais pais: paises)
num += pais.getNumeroEjercito();
return num;
}
public int rearmeContinente(){
switch(abreviatura){
case "Asia":
return 12;
case "África":
return 6;
case "AméricaNorte":
return 9;
case "AméricaSur": case "Oceanía":
return 4;
case "Europa":
return 7;
default:
return 0;
}
}
public boolean esPaisDelContinente(Pais pais)
{
return paises.contains(pais);
}
public ArrayList<Pais> fronteras()
{
ArrayList<Pais> fronteras = new ArrayList<>();
for(Pais pais: paises)
for(Pais frontera: pais.getFronteras())
if(!fronteras.contains(frontera) && !paises.contains(frontera))
fronteras.add(frontera);
return fronteras;
}
}