101 lines
2.4 KiB
C#
101 lines
2.4 KiB
C#
|
|
namespace WebEMSim
|
|
{
|
|
public class Match
|
|
{
|
|
public enum MatchResult
|
|
{
|
|
TEAM_A_WIN = 0, TEAM_B_WIN = 1, DRAW = 2
|
|
}
|
|
|
|
private Team[] _teams = new Team[2];
|
|
|
|
private int[] _goals = new int[2];
|
|
|
|
private MatchResult _result;
|
|
|
|
|
|
|
|
|
|
public Match(Team team1, Team team2)
|
|
{
|
|
_teams[0] = team1;
|
|
_teams[1] = team2;
|
|
}
|
|
|
|
private void CommitStats()
|
|
{
|
|
for (int teamIdx = 0; teamIdx < _teams.Length; teamIdx++)
|
|
{
|
|
int goalsFor = _goals[teamIdx];
|
|
int goalsAgainst = _goals[1 - teamIdx];
|
|
|
|
int points = 0;
|
|
|
|
if(_result == (MatchResult)teamIdx) //vergleiche enum
|
|
{
|
|
points = 3;
|
|
}
|
|
|
|
if(_result == MatchResult.DRAW)
|
|
{
|
|
points = 1;
|
|
}
|
|
|
|
_teams[teamIdx].LogStats(points, goalsFor, goalsAgainst);
|
|
}
|
|
}
|
|
|
|
private void CalculateResult()
|
|
{
|
|
if (_goals[0] > _goals[1])
|
|
{
|
|
_result = MatchResult.TEAM_A_WIN;
|
|
return;
|
|
}
|
|
|
|
if (_goals[1] > _goals[0])
|
|
{
|
|
_result = MatchResult.TEAM_B_WIN;
|
|
return;
|
|
}
|
|
|
|
_result = MatchResult.DRAW;
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
for (int goalsIdx = 0; goalsIdx < _goals.Length; goalsIdx++)
|
|
{
|
|
_goals[goalsIdx] = Random.Shared.Next(6);
|
|
}
|
|
|
|
CalculateResult();
|
|
CommitStats();
|
|
}
|
|
|
|
private Team GetWinner()
|
|
{
|
|
if (_result == Match.MatchResult.TEAM_A_WIN)
|
|
{
|
|
return _teams[0];
|
|
}
|
|
|
|
if (_result == Match.MatchResult.TEAM_B_WIN)
|
|
{
|
|
return _teams[1];
|
|
}
|
|
|
|
Table drawResolver = new([_teams[0], _teams[1]]);
|
|
|
|
return drawResolver.GetTable()[0];
|
|
}
|
|
|
|
public MatchResult Result { get => _result; }
|
|
public Team Winner { get => GetWinner(); }
|
|
public Team TeamA { get => _teams[0]; }
|
|
public Team TeamB { get => _teams[1]; }
|
|
public int GoalsA { get => _goals[0]; }
|
|
public int GoalsB { get => _goals[1]; }
|
|
}
|
|
}
|