private void ShowResults() { lstResults.Title = "Results"; lstResults.Columns = new List <ListColumn>() { new ListColumn(LangResources.CurLang.League, 175), new ListColumn(LangResources.CurLang.Home, 250), new ListColumn(" ", 50, HorizontalAlignment.Center), new ListColumn(LangResources.CurLang.Away, 250, HorizontalAlignment.Right) }; List <ListRow> rows = new List <ListRow>(); TeamAdapter ta = new TeamAdapter(); LeagueAdapter la = new LeagueAdapter(); foreach (Fixture f in SetupData.FixtureData) { rows.Add(new ListRow(f.UniqueID, new List <object>() { la.GetLeague(f.LeagueID).Name, ta.GetTeam(f.TeamIDs[0]).Name, string.Format("{0} - {1}", f.Score[0].ToString(), f.Score[1].ToString()), ta.GetTeam(f.TeamIDs[1]).Name })); } lstResults.Rows = rows; lstResults.SelectionMode = SelectMode.Highlight; }
private bool MatchStarting_Worker(Fixture f) { TeamAdapter ta = new TeamAdapter(); UI.txtHome.Text = ta.GetTeam(f.TeamIDs[0]).Name; UI.txtAway.Text = ta.GetTeam(f.TeamIDs[1]).Name; return(true); }
/// <summary> /// Loop round all AI teams, and select a team appropriate to play the fixture. /// </summary> public void SelectTeamIfPlaying() { FixtureAdapter fa = new FixtureAdapter(); WorldAdapter wa = new WorldAdapter(); TeamAdapter ta = new TeamAdapter(); ManagerAdapter ma = new ManagerAdapter(); List <Fixture> AllFixtures = fa.GetFixtures(wa.CurrentDate); int TESTf = 0; foreach (Fixture f in AllFixtures) { TESTf++; Debug.Print("Fixture " + f.ToString()); for (int t = 0; t <= 1; t++) { Team ThisTeam = ta.GetTeam(f.TeamIDs[t]); Manager M = ma.GetManager(ThisTeam.ManagerID); if (!M.Human) { Team Opposition = ta.GetTeam(f.TeamIDs[1 - t]); PlayerAdapter pa = new PlayerAdapter(); int[,] PlayerGridPositions = new int[5, 8]; // TODO: Maybe not hard code these... for (int x = 0; x <= PlayerGridPositions.GetUpperBound(0); x++) { for (int y = 0; y <= PlayerGridPositions.GetUpperBound(1); y++) { PlayerGridPositions[x, y] = -1; } } Formation TeamFormation = new FormationAdapter().GetFormation(ThisTeam.CurrentFormation); List <AvailablePlayer> avail = GetEligiblePlayers(ThisTeam, f); foreach (Point2 point in TeamFormation.Points) { AvailablePlayer SelPlayer = FindBestPlayerForPosition(point, avail); if (SelPlayer == null) { throw new Exception("Unable to find a player for this position"); } PlayerGridPositions[point.X, point.Y] = SelPlayer.PlayerID; avail.Remove(SelPlayer); } ta.SavePlayerFormation(ThisTeam.UniqueID, TeamFormation.UniqueID, PlayerGridPositions); } } } }
private bool MatchFinished_Worker(Fixture f) { TeamAdapter ta = new TeamAdapter(); string result = "{0} {1} - {2} {3}"; result = string.Format(result, ta.GetTeam(f.TeamIDs[0]).Name, f.Score[0], f.Score[1], ta.GetTeam(f.TeamIDs[1]).Name); System.Diagnostics.Debug.WriteLine(result); return(true); }
/// <summary> /// Run all the matches for the current game date /// </summary> /// <param name="MatchCallback"></param> public void Run(IMatchCallback MatchCallback) { MatchPlayer mp = new MatchPlayer(); WorldAdapter wa = new WorldAdapter(); FixtureAdapter fa = new FixtureAdapter(); TeamAdapter ta = new TeamAdapter(); ManagerAdapter ma = new ManagerAdapter(); foreach (Fixture f in fa.GetFixtures(wa.CurrentDate)) { mp.Fixture = f; mp.Interactive = false; for (int t = 0; t <= 1; t++) { if (ma.GetManager(ta.GetTeam(f.TeamIDs[t]).ManagerID).Human) { mp.Interactive = true; break; } } mp.MatchCallback = MatchCallback; mp.StartMatch(); } MatchCallback.MatchdayComplete(); }
private ScreenReturnData SetupGame() { ScreenReturnData ValidationResult = ValidateInput(); if (ValidationResult != null) { return(ValidationResult); } Manager you = new Manager(); you.FirstName = txtFirstName.Text; you.LastName = txtSurname.Text; you.Human = true; you.DateOfBirth = new DateTime(Convert.ToInt32(cboDOBYear.Text), cboDOBMonth.SelectedIndex + 1, Convert.ToInt32(cboDOBDay.Text)); you.Reputation = 50; ManagerAdapter ma = new ManagerAdapter(); int ManagerID = ma.AddManager(you); Team T = ta.GetTeam(lstTeams.SelectedID); ma.AssignToTeam(ManagerID, T.UniqueID); return(new ScreenReturnData(ScreenReturnCode.Ok)); }
/// <summary> /// Updates the team statistics from the fixtures/matches that have just been played /// </summary> /// <param name="fixtures">List of fixture objects to update</param> public void UpdateMatchStats(List <Fixture> fixtures) { const int POINTS_WON = 3; const int POINTS_DRAWN = 1; TeamAdapter ta = new TeamAdapter(); foreach (Fixture fixture in fixtures) { TeamStats[] stats = new TeamStats[2]; for (int t = 0; t <= 1; t++) { stats[t] = ta.GetTeam(fixture.TeamIDs[t]).SeasonStatistics; stats[t].GamesPlayed++; stats[t].GoalsScored += fixture.Score[t]; stats[t].GoalsConceded += fixture.Score[1 - t]; } if (fixture.Score[0] == fixture.Score[1]) { for (int t = 0; t <= 1; t++) { stats[t].Drawn += 1; stats[t].Points += POINTS_DRAWN; } } else { int WinningTeam = -1; int LosingTeam = -1; if (fixture.Score[0] > fixture.Score[1]) { WinningTeam = 0; LosingTeam = 1; } else { WinningTeam = 1; LosingTeam = 0; } stats[WinningTeam].Won += 1; stats[LosingTeam].Lost += 1; stats[WinningTeam].Points += POINTS_WON; } for (int t = 0; t <= 1; t++) { ta.UpdateTeamSeasonStatistics(fixture.TeamIDs[t], stats[t]); } } }
public void PopulatePlayerStatuses(MatchStatus ms, Fixture f) { List <PlayerStatus> StatusList; for (int t = 0; t <= 1; t++) { ms.OverallPlayerEffectiveRating[t] = 0; TeamAdapter ta = new TeamAdapter(); Team Team = ta.GetTeam(f.TeamIDs[t]); PlayerAdapter pa = new PlayerAdapter(); StatusList = new List <PlayerStatus>(); TacticEvaluation Eval = new TacticEvaluation(); int selected = 0; int totalEffectiveRating = 0; const double HealthDeteriorationPower = 4; foreach (KeyValuePair <int, TeamPlayer> kvp in Team.Players) { Player p = pa.GetPlayer(kvp.Value.PlayerID); PlayerStatus ps = new PlayerStatus(); ps.PlayerID = kvp.Value.PlayerID; ps.Playing = kvp.Value.Selected; ps.CurrentHealth = p.Health; ps.CurrentHealthDeterioration = Math.Pow(1 - (Convert.ToDouble(p.Fitness) / 100), HealthDeteriorationPower); if (ps.Playing == PlayerSelectionStatus.Starting) { selected++; PlayerPosition pos = GridLengthToPosition(kvp.Value); ps.EffectiveRating = CalculatePlayerEffectivenessInPosition(kvp.Value); totalEffectiveRating += ps.EffectiveRating; Eval.AddRatingForPosition(pos, ps.EffectiveRating); StatusList.Add(ps); } ps = null; } ms.OverallPlayerEffectiveRating[t] = (selected > 0 ? totalEffectiveRating / selected : 0); ms.PlayerStatuses[t] = StatusList; ms.Evaluation[t] = Eval; StatusList = null; } }
public void ShowTeamScreen(int TeamID) { TeamAdapter ta = new TeamAdapter(); ShowTeamScreen(ta.GetTeam(TeamID)); }
private void NextManagerOrContinueDay() { ManagerAdapter ma = new ManagerAdapter(); FixtureAdapter fa = new FixtureAdapter(); WorldAdapter wa = new WorldAdapter(); TeamAdapter ta = new TeamAdapter(); if (HumanManagers == null) { // Going to first manager, which means we have to run Start Of Day, unless loading from a savegame if (!SaveGameJustLoaded) { RunProcesses(false); } else { SaveGameJustLoaded = false; } HumanManagers = ma.GetHumanManagers(); PlayingHumanManager = 0; wa.CurrentManagerID = HumanManagers[PlayingHumanManager].UniqueID; if (HumanManagers.Count() < 1) { throw new Exception("No human managers"); } } else { // Check selections if a matchday if (fa.IsTodayAMatchDay(HumanManagers[PlayingHumanManager].CurrentTeam)) { const int REQUIREDCOUNT = 11; int PlayerCount = ta.CountSelectedPlayers(HumanManagers[PlayingHumanManager].CurrentTeam); if (PlayerCount < REQUIREDCOUNT) { UiUtils.OpenDialogBox(UiUtils.MainWindowGrid, LangResources.CurLang.MatchDay, string.Format(LangResources.CurLang.YouHaveNotSelectedEnoughPlayers, PlayerCount, REQUIREDCOUNT), new List <DialogButton>() { new DialogButton(LangResources.CurLang.OK, null, null) }); return; } } // Go to next human manager PlayingHumanManager++; if (PlayingHumanManager >= HumanManagers.Count()) { HumanManagers = null; wa.CurrentManagerID = -1; } else { wa.CurrentManagerID = HumanManagers[PlayingHumanManager].UniqueID; } } if (HumanManagers != null) { // Display home screen for the current manager Manager PlayingManager = HumanManagers[PlayingHumanManager]; ShowHomeScreenForCurrentManager(PlayingManager); if (fa.IsTodayAMatchDay(PlayingManager.CurrentTeam)) { Fixture f = fa.GetNextFixture(PlayingManager.CurrentTeam, wa.CurrentDate); int Opposition = (f.TeamIDs[0] != PlayingManager.CurrentTeam ? f.TeamIDs[0] : f.TeamIDs[1]); string Message = string.Format(LangResources.CurLang.YouHaveAMatchAgainst, ta.GetTeam(Opposition).Name); UiUtils.OpenDialogBox(UiUtils.MainWindowGrid, LangResources.CurLang.MatchDay, Message, new List <DialogButton>() { new DialogButton(LangResources.CurLang.OK, null, null) }); } } else { if (fa.IsTodayAMatchDay()) { ShowGameScreen(new MatchdayMain(), true); } else { RunProcesses(true); } } }