-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.cpp
44 lines (34 loc) · 881 Bytes
/
match.cpp
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
#include "match.h"
#include <QVariantList>
Match::Match(const Team &first, const Team &second)
{
mState = PENDING;
mMatch.first = first;
mMatch.second = second;
mWinner = NONE;
if( second == Team() ) {
mState = FINISHED;
mWinner = FIRST;
}
}
QPair<Team, Team> Match::teams() const
{
return mMatch;
}
void Match::changeToPlaying()
{
mState = PLAYING;
}
void Match::changeToFinished( bool firstWin )
{
mState = FINISHED;
mWinner = firstWin ? FIRST : SECOND;
}
Team Match::getWinner() const
{
return mWinner == NONE ? Team() : mWinner == FIRST ? mMatch.first : mMatch.second;
}
bool operator==( const Match &one, const Match &other ) {
return (one.teams().first == other.teams().first || one.teams().first == other.teams().second)
&& (one.teams().second == other.teams().first || one.teams().second == other.teams().second) ;
}