-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dojo.js
141 lines (129 loc) · 3.81 KB
/
Dojo.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function Dojo (nm, auth, key, state, fList, rList, aNav, nc){
this.name = nm;
this.author = auth;
this.key = key;
this.dojoState = state;
this.fighterList = fList;
this.numFighters = fList.length;
this.rankedList = rList;
this.arrayNav = aNav;
this.newChallenger = nc;
this.logFighters = function(arr) {
var str = "";
for (var i = 0; i < arr.length; i++) {
str += arr[i].name + "(" + arr[i].score + ")" + ", ";
}
console.log(str);
}
this.fight = function(pos) {
if (this.newChallenger != pos) {
this.fighterList.swap(this.arrayNav, this.arrayNav - 1);
}
this.fighterList[this.arrayNav].score += this.fighterList[this.arrayNav - 1].score + 1;
this.arrayNav++;
if (this.arrayNav == this.numFighters) {
if (this.declareWinner(pos) == CLOSED) {
this.dojoState = CLOSED;
// console.log("dojoState:" + this.dojoState);
return;
}
}
else {
if (pos == LEFT) {
displayFighter(RIGHT, this.fighterList[this.arrayNav], 0);
this.newChallenger = RIGHT;
}
else {
displayFighter(LEFT, this.fighterList[this.arrayNav], 0);
this.newChallenger = LEFT;
}
}
saveDojoCookie();
// this.logFighters(this.fighterList);
// console.log(this.arrayNav);
};
this.favorite = function(pos) {
// this.logFighters(this.fighterList);
if (this.newChallenger != pos) {
this.fighterList.swap(this.arrayNav, this.arrayNav - 1);
}
// this.logFighters(this.fighterList);
this.fighterList[this.arrayNav].score += this.fighterList[this.arrayNav - 1].score + 1;
this.fighterList.swap(this.arrayNav, this.numFighters - 1);
this.fighterList[this.numFighters - 1].score = this.numFighters - 1;
// this.logFighters(this.fighterList);
this.arrayNav = this.numFighters;
if (this.arrayNav == this.numFighters) {
if (this.declareWinner(pos) == CLOSED) {
this.dojoState = CLOSED;
// console.log("dojoState:" + this.dojoState);
return;
}
}
saveDojoCookie();
// this.logFighters(this.fighterList);
}
this.declareWinner = function(pos) {
// console.log(this.fighterList[this.arrayNav - 1].name + "(" + this.fighterList[this.arrayNav - 1].score + ")");
addWinner(this.fighterList[this.arrayNav - 1])
this.rankedList.push(this.fighterList.pop());
this.arrayNav--;
this.numFighters--;
// console.log(this.arrayNav);
this.logFighters(this.rankedList);
// console.log("numFighters: " + this.numFighters);
if (this.numFighters <= 0) {
// this.logFighters(this.rankedList);
this.closeDojo();
saveDojoCookie();
return CLOSED;
}
else {
if (this.fighterList[this.arrayNav - 1].score == this.numFighters - 1) {
if (this.declareWinner() == CLOSED) {
if (pos == LEFT) {
displayFighter(LEFT, BLANKFIGHTER, 1, true);
displayFighter(RIGHT, BLANKFIGHTER, 0, true);
}
else {
displayFighter(LEFT, BLANKFIGHTER, 0, true);
displayFighter(RIGHT, BLANKFIGHTER, 1, true);
}
saveDojoCookie();
return CLOSED;
}
}
else {
this.arrayNav--;
while (this.numFighters > 2 && this.arrayNav > 1 && this.fighterList[this.arrayNav - 1].score == 0) {
this.arrayNav--;
}
if (pos == LEFT) {
displayFighter(0, this.fighterList[this.arrayNav - 1], 1);
displayFighter(1, this.fighterList[this.arrayNav], 0);
}
else {
displayFighter(0, this.fighterList[this.arrayNav - 1], 0);
displayFighter(1, this.fighterList[this.arrayNav], 1);
}
this.newChallenger = 1;
saveDojoCookie();
return OPEN;
}
}
}
this.openDojo = function() {
displayFighter(LEFT,this.fighterList[this.arrayNav-1],NOANIMATION);
displayFighter(RIGHT,this.fighterList[this.arrayNav],NOANIMATION);
this.dojoState = OPEN;
}
this.closeDojo = function() {
console.log("Dojo Closed");
if (!menuExpanded) {
showPersonal();
toggleMenu();
sendResults();
}
this.dojoState = CLOSED;
}
}