-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
126 lines (111 loc) · 3.37 KB
/
deploy.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
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
var firstTurn = true;
function startReinforcePhase(){
$('#clicked').removeAttr('d');
$('#hovering').removeAttr('d');
$('#country1').text("Click on a country");
var name = "Player 1";
var color = 'blue';
if(turn=="player2"){
name = "Player 2";
color ='red';
}
$('#roundInfo').text("Reinforce Phase for "+name);
$('#roundInfo').css('color',color);
$("#troopInfo").html("Troops remaining: <span id='numTroops'>"+ players[turn]["troops"] + "</span>");
}
$('#playButton').click(function(evt){
$('#playButton').hide();
$('#statButton').show();
$('#gameInterface').show();
$(".pText").show();
$(".icon").show();
init();
turn = "player1";
$('#topBtn').click(function(evt){
fortifyTroops(turn, clicked, "plus");
$('#numTroops').html(players[turn]["troops"]);
});
$('#botBtn').click(function(evt){
fortifyTroops(turn, clicked, "minus");
$('#numTroops').html(players[turn]["troops"]);
});
$('#statButton').click(function(){
var p1Territories = 0;
var p2Territories = 0;
var p1Troops = 0;
var p2Troops = 0;
$('.country').each(function(){
var countryId = this.getAttribute('id');
if(countries[countryId][1] == "player1"){
p1Territories++;
p1Troops += countries[countryId][2];
}
else{
p2Territories++;
p2Troops += countries[countryId][2];
}
});
// console.log($('.test')[0]);
$($('.p1stat')[0]).text(p1Territories);
$($('.p1stat')[1]).text(p1Troops);
$($('.p2stat')[0]).text(p2Territories);
$($('.p2stat')[1]).text(p2Troops);
});
startReinforcePhase();
});
$('#nextBtn').click(function(evt){
var name = "Player 1";
if(turn=="player2")
name = "Player 2";
if(phase=="start"){
if(players[turn]["troops"]>0)
alert('Must place all troops first');
else if(turn=="player2"){
turn="player1";
startAttackPhase();
}
else{
turn="player2";
$('#numTroops').html(players[turn]["troops"]);
$('#roundInfo').html("Reinforce Phase for Player 2");
$('#roundInfo').css('color','red');
}
}
else if(phase=="reinforce"){
if(players[turn]["troops"]>0)
alert('Must place all troops first');
else{
startAttackPhase();
}
}
else if(phase=="attack"){
startMovePhase();
}
else if(phase=="move"){
if(players[turn]["troops"] > 0)
alert("You have troops waiting to be moved");
else{
if(turn=="player1")
turn="player2"
else
turn="player1"
//stops player 2 from getting extra troops on first round
if(!firstTurn){
players[turn]["troops"] = calcReinforcements(turn);
phase="reinforce";
startReinforcePhase();
}
else{
startAttackPhase();
firstTurn = false;
}
}
}
});
function calcReinforcements(player){
// based on risk rules without cards or continents
var temp = Math.floor(players[player]['countriesHeld'] / 3);
if(temp < 3)
temp = 3;
return temp;
}