/// <summary> /// Initializes a new instance of the <see cref="Simulation" /> class. /// </summary> /// <param name="teams">The teams to be played against each other.</param> /// <param name="ball">The ball.</param> /// <param name="pitchBounds">The pitch boundaries.</param> /// <param name="friction">The friction coefficient.</param> public Simulation(ReadOnlyCollection<Team> teams, PointMass ball, RectangleF pitchBounds, float friction) { Contract.Requires<ArgumentNullException>(teams != null); Contract.Requires<ArgumentNullException>(ball != null); Contract.Requires<ArgumentException>(friction >= 0); Contract.Requires<ArgumentException>(pitchBounds.Width > 0 && pitchBounds.Height > 0); Contract.Requires<ArgumentException>(Contract.ForAll(teams, t => t != null && t.IsValid(pitchBounds))); Contract.Requires<ArgumentException>(pitchBounds.Contains(ball.Position)); _simulate = SimulatePlaying; _teams = teams; _startingPositions = from t in teams select t.PlayerPositions; _ball = ball; _ballStartingPosition = ball.Position; PitchBounds = pitchBounds; Friction = friction; }
/// <summary> /// Initializes a new instance of the <see cref="Simulation" /> class. /// </summary> /// <param name="teams">The teams to be played against each other.</param> /// <param name="ball">The ball.</param> /// <param name="pitchBounds">The pitch boundaries.</param> /// <param name="friction">The friction coefficient.</param> public Simulation(ReadOnlyCollection<Team> teams, PointMass ball, RectangleF pitchBounds, float friction) { Contract.Requires<ArgumentNullException>(teams != null); Contract.Requires<ArgumentNullException>(ball != null); Contract.Requires<ArgumentException>(friction >= 0); Contract.Requires<ArgumentException>(pitchBounds.Width > 0 && pitchBounds.Height > 0); Contract.Requires<ArgumentException>(Contract.ForAll(teams, t => t != null && pitchBounds.IntersectsOrBorders(t.GoalBounds) && t.Players.All(p => pitchBounds.Contains(p.Position)))); Contract.Requires<ArgumentException>(pitchBounds.Contains(ball.Position)); _simulate = SimulatePlaying; _teams = teams; _startingPositions = (from t in teams select (from p in t.Players select p.Position).ToList().AsReadOnly()).ToList().AsReadOnly(); _ball = ball; _ballStartingPosition = ball.Position; PitchBounds = pitchBounds; Friction = friction; }
// Called when the team's have reached their starting positions after executing a reset. private void OnReset() { _ball.Reset(_ballStartingPosition); _simulate = SimulatePlaying; }
// Called when a goal is scored. private void OnGoalScored(Team scoringTeam) { scoringTeam.OnGoalScored(); _simulate = SimulateResetting; }