Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DoNaTio s.r.o.
PiPo
Commits
7f0bc29f
Commit
7f0bc29f
authored
Dec 17, 2014
by
Monika
Browse files
whoIsOnServe
parent
1827acee
Changes
1
Hide whitespace changes
Inline
Side-by-side
WhoIsOnServe.js
0 → 100644
View file @
7f0bc29f
/**
* WhoIsTurn
* @returns {{getCount: Function, addPlayer: Function}}
* todo refactor create common parent class for whoIsTurn and WhoIsOnServe methods resetTeamStack, getNext
*/
module
.
exports
=
function
(
PlayersColliction
,
Score
)
{
var
_playersColliction
=
PlayersColliction
;
var
_score
=
Score
;
var
_whichTeam
=
1
;
var
_team0
=
[];
var
_team1
=
[];
var
_actId
=
0
;
return
{
resetTeamStack
:
function
()
{
var
allPlayers
=
_playersColliction
.
getAllPlayers
();
for
(
var
key
in
allPlayers
)
{
if
(
allPlayers
[
key
].
getTeam
()
==
0
)
{
_team0
.
push
(
key
);
}
else
{
_team1
.
push
(
key
);
}
}
},
getTeam
:
function
()
{
return
_whichTeam
;
},
getActId
:
function
()
{
return
_actId
;
},
getNext
:
function
()
{
var
next
;
if
(
_whichTeam
)
{
if
(
_team1
.
length
==
0
)
{
this
.
resetTeamStack
(
1
);
}
next
=
_team1
[
0
];
_team1
.
splice
(
0
,
1
);
}
else
{
if
(
_team0
.
length
==
0
)
{
this
.
resetTeamStack
(
0
);
}
next
=
_team0
[
0
];
_team0
.
splice
(
0
,
1
);
}
_actId
=
next
;
return
next
;
},
getWhoIsOnServe
:
function
()
{
var
sumScoreTeams
=
_score
.
getScore
();
var
sumScore
=
sumScoreTeams
.
team0
+
sumScoreTeams
.
team1
;
if
(
sumScore
%
2
==
0
){
if
(
_whichTeam
)
{
_whichTeam
=
0
;
}
else
{
_whichTeam
=
1
;
}
}
console
.
log
(
this
.
getNext
(),
'
serve
'
);
return
this
.
getNext
();
}
};
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment