public void addGoal(int idGoal, int minutes, int idMatch, int idPlayer) { Goal newGoal = new Goal(idGoal, minutes, this.getMatchById(idMatch), this.getPlayerById(idPlayer)); this.addGoal(newGoal); }
public void addGoal(Goal goal) { foreach (Match match in Matches) { if (match.Id == goal.Match.Id) { match.addGoal(goal); break; } } Goals.Add(goal); }
public PlayTheMatch(MainDoc mainDoc, int idMatch) { Match match = mainDoc.getMatchById(idMatch); random = new Random(); List<Player> homeTeam = mainDoc.getFirstEleven(match.HomeTeam.Name); List<Player> guestTeam = mainDoc.getFirstEleven(match.GuestTeam.Name); int id = 0;//OVA TREBA DA GO DOBIJAM OD BAZATA Participations = new List<Participates>(); AllPlayers = new List<Player>(); //za oznacuvanje deka e odigran using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); String query = "UPDATE Match SET Finished = 'y'" + " WHERE idMatch = " + idMatch; OracleCommand command = new OracleCommand(query, conn); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } totalAssistTokens = totalGoalTokens = totalInterruptTokens = totalSaveTokens = 0; foreach (Player p in homeTeam) { AllPlayers.Add(p); Participations.Add(new Participates(id, p, match, 0, 0, 0, 0));//vaka za site ucesnici se stava isto id totalAssistTokens += p.TokensAssists; //no ovaa lista e samo lokalna za ovaa klasa totalGoalTokens += p.TokensGoals; //i toj index ne se koristi na drugi mesta, pa zatoa ne smeta totalInterruptTokens += p.TokensInterrupts;//ne go izbrisav poleto bidejki koga ke se zemaat site ucestva od glavnata forma totalSaveTokens += p.TokensSaves; //ke bide potrebno i toa pole } foreach (Player p in guestTeam) { AllPlayers.Add(p); Participations.Add(new Participates(id, p, match, 0, 0, 0, 0));//slicna diskusija kako pogore totalAssistTokens += p.TokensAssists; totalGoalTokens += p.TokensGoals; totalInterruptTokens += p.TokensInterrupts; totalSaveTokens += p.TokensSaves; } //sluckite vo dadeni minuti int goalsHome = 0, goalsGuest = 0; for (int minute = 1; minute <= 90; minute++)//0 - goal and eventually assist, 1 - interrupt, 2 save, nothing { int happens = whatHappens(); int nextGoal = 1; if (mainDoc.Goals.Count > 0) nextGoal = mainDoc.Goals[mainDoc.Goals.Count - 1].Id + 1;//Slicno kako kaj Participates, sekade ke se stava nextGoal = 0, no toa ne pravi problem if (happens == 0)//goal { int scorerId = goalScorer(); Goal goal = new Goal(nextGoal, minute, match, AllPlayers[scorerId]); if (scorerId < 11) { goalsHome++; } else { goalsGuest++; } //dodavanje na gol vo bazata using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); OracleCommand command = new OracleCommand("procInsertGoal", conn); command.CommandType = CommandType.StoredProcedure; /* * p_idPlayer in Goal.idPlayer%TYPE, * p_idMatch in Goal.idMatch%TYPE, * p_minutes in Goal.minutes%TYPE) */ command.Parameters.Add("p_idPlayer", OracleDbType.Int32).Value = goal.Player.Id; command.Parameters.Add("p_idMatch", OracleDbType.Int32).Value = goal.Match.Id; command.Parameters.Add("p_minutes", OracleDbType.Int32).Value = goal.Minutes; command.ExecuteNonQuery(); } //azuriranje na mainDoc mainDoc.Goals.Add(goal); match.addGoal(goal); Participations[scorerId].NumGoals++; int assId = assistent(); if (assId != scorerId && (assId - 10) * (scorerId - 10) >= 0) { Participations[assId].NumAssists++; } } else if (happens == 1)//interrupt { int interrupterId = interrupter(); Participations[interrupterId].NumInterrupts++; } else if (happens == 2)//save { int saverId = saver(); Participations[saverId].NumSaves++; } } //obnova na rejtinzi for(int i = 0; i < Participations.Count; i++) { Participates p = Participations[i]; p.calculateMatchRating(); p.MatchRating = (int) ((AllPlayers[i].Rating + 9 * p.MatchRating) / 10); if(i < 11) { p.MatchRating = p.MatchRating + goalsHome * WEIGHT_GOALS_MATCH_RATING - goalsGuest * WEIGHT_GOALS_MATCH_RATING; if (p.Player.Position.Id == 1)//napagac { p.MatchRating += WEIGHT_GOALS_MATCH_RATING * goalsHome; } else if (p.Player.Position.Id == 4)//golman { p.MatchRating -= WEIGHT_GOALS_MATCH_RATING * goalsGuest; } if (goalsHome > goalsGuest) p.MatchRating += WIN_BONUS; } else { p.MatchRating = p.MatchRating + goalsHome * WEIGHT_GOALS_MATCH_RATING - goalsGuest * WEIGHT_GOALS_MATCH_RATING; if (p.Player.Position.Id == 1)//napagac { p.MatchRating += WEIGHT_GOALS_MATCH_RATING * goalsGuest; } else if (p.Player.Position.Id == 4)//golman { p.MatchRating -= WEIGHT_GOALS_MATCH_RATING * goalsHome; } if (goalsHome < goalsGuest) p.MatchRating += WIN_BONUS; } //int nextParticipateId = mainDoc.Par[mainDoc.Goals.Count - 1].Id + 1; //dodavanje na ucestvata vo bazata using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); OracleCommand command = new OracleCommand("procInsertParticipates", conn); command.CommandType = CommandType.StoredProcedure; /* * p_idPlayer in Participates.idPlayer%TYPE, p_idMatch in Participates.idMatch%TYPE, p_numgoals in Participates.numgoals%TYPE, p_numassists in Participates.numassists%TYPE, p_numinterrupts in Participates.NUMINTERRUPTS%TYPE, p_numsaves in Participates.numsaves%TYPE, p_matchrating in Participates.match_rating%TYPE) */ command.Parameters.Add("p_idPlayer", OracleDbType.Int32).Value = p.Player.Id; command.Parameters.Add("p_idMatch", OracleDbType.Int32).Value = p.Match.Id; command.Parameters.Add("p_numgoals", OracleDbType.Int32).Value = p.NumGoals; command.Parameters.Add("p_numassists", OracleDbType.Int32).Value = p.NumAssists; command.Parameters.Add("p_numinterrupts", OracleDbType.Int32).Value = p.NumInterrupts; command.Parameters.Add("p_numsaves", OracleDbType.Int32).Value = p.NumSaves; command.Parameters.Add("p_matchrating", OracleDbType.Int32).Value = p.MatchRating; command.ExecuteNonQuery(); } //azuriranje na Participates } //update na Player rating int homeAvgRating = 0, guestAvgRating = 0; for (int i = 0; i < AllPlayers.Count; i++) { AllPlayers[i].updateRating(Participations[i].MatchRating); //mainDoc.Players[AllPlayers[i].Id].Rating = (double)AllPlayers[i].Rating;//azuriranje vo mainDoc if (i < 11) { homeAvgRating += (int)AllPlayers[i].Rating; } else { guestAvgRating += (int)AllPlayers[i].Rating; } using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); String query = "UPDATE Player SET rating = " + (int)AllPlayers[i].Rating + " WHERE idPlayer = " + AllPlayers[i].Id; OracleCommand command = new OracleCommand(query, conn); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } //update team ratings homeAvgRating /= 11; guestAvgRating /= 11; int homeNewRating = (homeAvgRating + 49 * (int)match.HomeTeam.Rating) / 50; int guestNewRating = (guestAvgRating + 49 * (int)match.GuestTeam.Rating) / 50; match.HomeTeam.Rating = homeNewRating; match.GuestTeam.Rating = guestNewRating; //mainDoc.Teams[match.GuestTeam.Id].Rating = (double) guestNewRating; using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); String query = "UPDATE Team SET rating = " + homeNewRating + " WHERE idTeam = " + match.HomeTeam.Id; OracleCommand command = new OracleCommand(query, conn); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } using (OracleConnection conn = new OracleConnection(FormLogin.connString)) { conn.Open(); String query = "UPDATE Team SET rating = " + guestNewRating + " WHERE idTeam = " + match.GuestTeam.Id; OracleCommand command = new OracleCommand(query, conn); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } }