/
pais.js
72 lines (59 loc) · 1.66 KB
/
pais.js
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
module.exports = function Pais(id,nombre,continente){
this.id = id;
this.nombre = nombre;
this.continente = continente;
this.ejercito = 1;
this.limitrofes = [];
this.ejercitosPasados = {};
this.pasarEjercito = function(toPais,cantidad){
var paisDesde = this;
var paisHacia = toPais;
var cantidad = cantidad;
if(cantidad<=3 && cantidad>=1 && cantidad<=(this.ejercito-1)){
paisDesde.enviarEjercito(paisDesde,paisHacia,cantidad);
}
}
this.enviarEjercito = function(paisDesde,paisHacia,cantidad){
paisHacia.ejercito+=cantidad;
paisDesde.ejercito-=cantidad;
}
this.addJugador = function(jugador){
this.jugador = jugador;
}
this.addLimitrofes = function(limitrofes){
this.limitrofes = limitrofes;
}
this.addEjercito = function(cantidad){
if(this.jugador.ejercitosDisponibles >= cantidad){
this.ejercito+=cantidad;
this.jugador.removeEjercitosDisponibles(cantidad);
return true;
}
return false;
}
this.removeEjercito = function(cantidad){
if(this.ejercito >= cantidad){
this.ejercito-=cantidad;
this.jugador.addEjercitosDisponibles(cantidad);
return true;
}
return false;
}
this.isLimitrofeEnemigo = function(pais){
return this.jugador != pais.jugador &&
this.limitrofes.indexOf(pais)>-1;
}
this.isLimitrofeAliado = function(pais){
return this.jugador == pais.jugador &&
this.limitrofes.indexOf(pais)>-1;
}
this.countEjercitosPasados = function(){
var count = 0;
for (var property in this.ejercitosPasados) {
if (this.ejercitosPasados.hasOwnProperty(property)) {
count+=this.ejercitosPasados[property] ;
}
}
return count;
}
}