public Game(string stage, DateTime date, Team team1, Team team2, string stadium, string city) { Stage = stage; Date = date; Stadium = stadium; City = city; Teams = new Dictionary<string, Team>(); Scores = new Dictionary<string, int>(); Fouls = new Dictionary<string, int>(); Team1ID = team1.TeamID; Team2ID = team2.TeamID; Team1 = team1; Team2 = team2; Teams.Add(team1.TeamID, team1); Teams.Add(team2.TeamID, team2); Scores.Add(team1.TeamID, 0); Scores.Add(team2.TeamID, 0); Fouls.Add(team1.TeamID, 0); Fouls.Add(team2.TeamID, 0); PlayingTeamID = team1.TeamID; AwaitingTeamID = team2.TeamID; //PlayingTeamID = team2.TeamID; //AwaitingTeamID = team1.TeamID; Team1BallStrength = 50; Team2BallStrength = 50; }
public Player(Team team, int number) : base(20, 1.0, false) { this.Id = number.ToString("00"); this.Team = team; this.IsPlaying = false; friction = 0.025F; position = new Vector2D(0, 0); }
private void ResetPlayerPositions(Team xt1, Team xt2, Canvas xrootCanvas, List<Discoid> xdiscoids, double leftEndX, double rightEndX, double topEndY, double bottomEndY) { hasPendingGoalResolution = false; int columnCount1 = currentGame.Teams[currentGame.Team1ID].Formation.Length; int columnCount2 = currentGame.Teams[currentGame.Team2ID].Formation.Length; int currentColumn1 = 0; int currentColumn2 = 0; int currentRow1 = 0; int currentRow2 = 0; int rowCount1 = currentGame.Teams[currentGame.Team1ID].Formation[currentColumn1]; int rowCount2 = currentGame.Teams[currentGame.Team2ID].Formation[currentColumn2]; double columnWidth1 = ((rightEndX - leftEndX) / 2) / columnCount1; double columnWidth2 = ((rightEndX - leftEndX) / 2) / columnCount2; double rowHeight1 = 2 * ((bottomEndY - topEndY) / 2) / rowCount1; double rowHeight2 = 2 * ((bottomEndY - topEndY) / 2) / rowCount2; for (int i = 0; i <= 10; i++) { rowCount1 = currentGame.Teams[currentGame.Team1ID].Formation[currentColumn1]; rowCount2 = currentGame.Teams[currentGame.Team2ID].Formation[currentColumn2]; double vOffset1 = ((bottomEndY - topEndY) / 2) - (rowCount1 * rowHeight1) / 2; double vOffset2 = ((bottomEndY - topEndY) / 2) - (rowCount2 * rowHeight2) / 2; Player p1 = currentGame.Teams[currentGame.Team1ID].players[i]; Player p2 = currentGame.Teams[currentGame.Team2ID].players[i]; p1.Position.X = leftEndX + columnWidth1 * (0.5) + columnWidth1 * currentColumn1; p1.Position.Y = topEndY + rowHeight1 * (0.5) + rowHeight1 * currentRow1 + vOffset1; currentRow1++; if (currentRow1 == rowCount1) { currentRow1 = 0; currentColumn1++; if (currentColumn1 < currentGame.Teams[currentGame.Team1ID].Formation.Length) { rowCount1 = currentGame.Teams[currentGame.Team1ID].Formation[currentColumn1]; columnWidth1 = ((rightEndX - leftEndX) / 2) / columnCount1; rowHeight1 = 2 * ((bottomEndY - topEndY) / 2) / rowCount1; } } p2.Position.X = rightEndX - columnWidth2 * (0.5) - columnWidth2 * currentColumn2; p2.Position.Y = topEndY + rowHeight2 * (0.5) + rowHeight2 * currentRow2 + vOffset2; currentRow2++; if (currentRow2 == rowCount2) { currentRow2 = 0; currentColumn2++; if (currentColumn2 < currentGame.Teams[currentGame.Team2ID].Formation.Length) { rowCount2 = currentGame.Teams[currentGame.Team2ID].Formation[currentColumn2]; columnWidth2 = ((rightEndX - leftEndX) / 2) / columnCount2; rowHeight2 = 2 * ((bottomEndY - topEndY) / 2) / rowCount2; } } } }
private List<GhostBall> GetGhostBalls(Team team, Ball ball, bool despair) { List<GhostBall> ghostBalls = new List<GhostBall>(); int i = 0; foreach (Player player in team.players) { if (player.IsPlaying) { foreach (Goal goal in goals) { List<Point> hotSpots = goal.HotSpots; foreach (Point hotSpot in hotSpots) { //distances between goal hotspot and ball center double dxGoalBallOn = hotSpot.X - ball.Position.X; double dyGoalBallOn = hotSpot.Y - ball.Position.Y; double hGoalBallOn = Math.Sqrt(dxGoalBallOn * dxGoalBallOn + dyGoalBallOn * dyGoalBallOn); double a = dyGoalBallOn / dxGoalBallOn; //distances between ball on center and ghost ball center double hBallOnGhost = (ball.Radius - 1.5) * 2.0; double dxBallOnGhost = hBallOnGhost * (dxGoalBallOn / hGoalBallOn); double dyBallOnGhost = hBallOnGhost * (dyGoalBallOn / hGoalBallOn); //ghost ball coordinates double gX = ball.Position.X - dxBallOnGhost; double gY = ball.Position.Y - dyBallOnGhost; double dxGhostPlayer = player.Position.X - gX; double dyGhostPlayer = player.Position.Y - gY; double hGhostPlayer = Math.Sqrt(dxGhostPlayer * dxGhostPlayer + dyGhostPlayer * dyGhostPlayer); //distances between ball center and player center double dxBallOnPlayer = ball.Position.X - player.Position.X; double dyBallOnPlayer = ball.Position.Y - player.Position.Y; double hBallOnPlayer = Math.Sqrt(dxBallOnPlayer * dxBallOnPlayer + dyBallOnPlayer * dyBallOnPlayer); //if (((Math.Sign(dxGoalBallOn) == Math.Sign(dxBallOnPlayer) || dxGoalBallOn == 0) && (Math.Sign(dyGoalBallOn) == Math.Sign(dyBallOnPlayer) || dyGoalBallOn == 0))) //{ // GhostBall ghostBall = new GhostBall(player, new Point(gX, gY), hBallOnPlayer, a, 0); // ghostBalls.Add(ghostBall); // i++; //} int value = 0; if ( !(((Math.Sign(dxGoalBallOn) == Math.Sign(dxBallOnPlayer) || dxGoalBallOn == 0) && (Math.Sign(dyGoalBallOn) == Math.Sign(dyBallOnPlayer) || dyGoalBallOn == 0))) ) { value += 10; } GhostBall ghostBall = new GhostBall(player, new Point(gX, gY), hBallOnPlayer, a, value); ghostBalls.Add(ghostBall); i++; } } } } return ghostBalls; }