private void SaveGame(string NewName) { WorldAdapter wa = new WorldAdapter(); if (NewName != null && NewName != "") { wa.SaveGameName = NewName; } if (wa.SaveGameName == "" || wa.SaveGameName == null) { UiUtils.OpenTextInputDialog(grdMain, LangResources.CurLang.SaveGame, LangResources.CurLang.GameHasNotBeenSavedBefore, SaveGameInputCallback); } else { GameIO io = new GameIO(); io.SaveGameName = wa.SaveGameName; io.SaveGame(); List <DialogButton> buttons = new List <DialogButton>(); buttons.Add(new DialogButton(LangResources.CurLang.OK, null, null)); UiUtils.OpenDialogBox(grdMain, LangResources.CurLang.SaveGame, String.Format(LangResources.CurLang.GameSavedSuccessfully, wa.SaveGameName), buttons); } }
/// <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 void RunProcesses(bool EndOfDay) { Dictionary <string, object> WaitScreen = UiUtils.OpenPleaseWait(UiUtils.MainWindowGrid, LangResources.CurLang.DailyUpdate); Thread t = new Thread(() => { Thread.Sleep(250); if (EndOfDay) { ProcessManager.RunEndOfDay(); } else { ProcessManager.RunStartOfDay(SaveGameJustLoaded); } }); t.IsBackground = true; t.Start(); UiUtils.WaitForThread(t); UiUtils.RemoveControl((WaitScreen[ReturnedUIObjects.GridContainer] as Grid)); if (EndOfDay) { // Goto Next day WorldAdapter wa = new WorldAdapter(); GameDate.Text = wa.CurrentDate.ToString("dd MMMM yyyy"); NextManagerOrContinueDay(); } }
public void SetupGameScreenData(GameScreenSetup dataFromUI) { if (dataFromUI.TeamData == null) { throw new Exception("TeamData is null"); } ManagerAdapter ma = new ManagerAdapter(); WorldAdapter wa = new WorldAdapter(); SetupData = dataFromUI; SetupData.ManagerData = ma.GetManager(SetupData.TeamData.ManagerID); MyTeam = (wa.CurrentManagerID == SetupData.TeamData.ManagerID); if (MyTeam) { SetupData.MainButtons.Add(LangResources.CurLang.Save); SetupData.MainButtons.Add(LangResources.CurLang.UndoChanges); } SetupData.MainButtons.Add(LangResources.CurLang.Back); SetupData.ShowContinueButton = MyTeam; SetupData.Title1 = SetupData.TeamData.Name; SetupData.Title2 = SetupData.ManagerData.Name; ctlFormation.team = SetupData.TeamData; }
public void SetupGameScreenData(GameScreenSetup dataFromUI) { if (dataFromUI.TeamData == null) { throw new Exception("TeamData is null"); } ManagerAdapter ma = new ManagerAdapter(); WorldAdapter wa = new WorldAdapter(); SetupData = dataFromUI; SetupData.ManagerData = ma.GetManager(SetupData.TeamData.ManagerID); MyTeam = (wa.CurrentManagerID == SetupData.TeamData.ManagerID); SetupData.ShowContinueButton = MyTeam; SetupData.MainButtons.Add(LangResources.CurLang.Tactics); SetupData.MainButtons.Add(LangResources.CurLang.Back); SetupData.Title1 = SetupData.TeamData.Name; SetupData.Title2 = SetupData.ManagerData.Name; UpdatePlayers(); }
public static void RunStartOfDay(bool SaveGameJustLoaded) { if (!RegisteredStandardHandlers) { RegisterAllStandardHandlers(); } if (SaveGameJustLoaded) { return; } WorldAdapter wa = new WorldAdapter(); foreach (IProcess Handler in ProcessHandlers) { for (int i = 1; i <= 4; i++) { try { switch (i) { case 1: Handler.StartOfDay(); break; case 2: if (wa.CurrentDate == wa.PreSeasonDate) { Handler.PreSeasonStart(); } break; case 3: if (wa.CurrentDate == wa.MainSeasonDate) { Handler.SeasonStart(); } break; case 4: if (new FixtureAdapter().IsTodayAMatchDay()) { Handler.MatchDayStart(); } break; } } #pragma warning disable CS0168 catch (NotImplementedException ex) #pragma warning restore CS0168 { // Silently fail on a NotImplementedException ONLY, because not all classes will implement something } } } }
/// <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); } } } }
public void ShowTacticsScreen(Team t) { WorldAdapter wa = new WorldAdapter(); bool MyTeam = (wa.CurrentManagerID == t.ManagerID); GameScreenSetup data = new GameScreenSetup(); data.TeamData = t; ShowGameScreen(new TacticsScreen(), data, MyTeam); }
public static void RunEndOfDay() { if (!RegisteredStandardHandlers) { RegisterAllStandardHandlers(); } WorldAdapter wa = new WorldAdapter(); foreach (IProcess Handler in ProcessHandlers) { for (int i = 1; i <= 4; i++) { try { switch (i) { case 1: if (new FixtureAdapter().IsTodayAMatchDay()) { Handler.MatchDayEnd(); } break; case 2: Handler.SeasonEnd(); break; case 3: if (wa.CurrentDate == wa.MainSeasonDate.AddDays(-1)) { Handler.PreSeasonEnd(); } break; case 4: Handler.EndOfDay(); break; } } #pragma warning disable CS0168 catch (NotImplementedException ex) #pragma warning restore CS0168 { // Silently fail on a NotImplementedException ONLY, because not all classes will implement something } } } // Go to next day, whoop! wa.AdvanceDate(); }
private void Headings() { Title1.Text = CurrentScreen.SetupData.Title1; Title2.Text = CurrentScreen.SetupData.Title2; if (CurrentScreen.SetupData.ShowDate) { WorldAdapter wa = new WorldAdapter(); GameDate.Visibility = Visibility.Visible; GameDate.Text = wa.CurrentDate.ToString("dd MMMM yyyy"); } else { GameDate.Visibility = Visibility.Hidden; } }
public ScreenReturnData MainButtonClick(int buttonId) { if (!MatchdayComplete) { Thread rm = new Thread(this.RunMatchday); rm.IsBackground = true; rm.Start(); return(new ScreenReturnData(ScreenReturnCode.None)); } else { FixtureAdapter fa = new FixtureAdapter(); WorldAdapter wa = new WorldAdapter(); SetupData.Parent.ShowResultsScreen(fa.GetFixtures(wa.CurrentDate)); return(new ScreenReturnData(ScreenReturnCode.None)); } }
static internal void RunPlanetaryPool() { var structure = new GravitationalStructureArchanDas(); World world = new World(); foreach (Tetrahedron tet in structure.GetTetrahedra()) { world.AddProjectile(new ProjectileN.Tetrahedron(ConvertToUtilityVector(tet.Points[0]), ConvertToUtilityVector(tet.Points[1]), ConvertToUtilityVector(tet.Points[2]), ConvertToUtilityVector(tet.Points[3]), tet.Mass)); } Projectile projectile = new Projectile(position: ConvertToUtilityVector(structure.StartingPoint.PositionVector()), velocity: ConvertToUtilityVector(structure.StartingVelocity), acceleration: new UtilityLibraries.Vector(0, 0, 0), mass: 100000); Dictionary <ProjectileParent, ProjectileParent> conn = new Dictionary <ProjectileParent, ProjectileParent>(); foreach (ProjectileParent p in world.projectiles) { conn.Add(p, projectile); } world.connections = conn; world.AddProjectile(projectile); var engine = new WorldAdapter(world); var visualization = new PlanetaryPoolVisualization(structure, engine); Timeline.MaximumPoints = 3000; var fullViz = new MotionVisualizer3DControl(visualization); fullViz.Manager.Add3DGraph("Position", () => engine.Time, () => ConvertToDongUtilityVector(engine.Projectiles[engine.Projectiles.Count - 1].Position), "Time (s)", "Position (m)"); fullViz.Manager.Add3DGraph("Velocity", () => engine.Time, () => ConvertToDongUtilityVector(engine.Projectiles[engine.Projectiles.Count - 1].Velocity), "Time (s)", "Velocity (m/s)"); fullViz.Manager.Add3DGraph("Acceleration", () => engine.Time, () => ConvertToDongUtilityVector(engine.Projectiles[engine.Projectiles.Count - 1].Acceleration), "Time (s)", "Acceleration (m/s^2)"); fullViz.Manager.AddSingleGraph("X vs. Y", ConvertColor(Colors.Teal), () => engine.Projectiles[engine.Projectiles.Count - 1].Position.X, (() => engine.Projectiles[0].Position.X), "Y (m)", "X (m)"); fullViz.FastDraw = true; fullViz.Show(); }
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); } } }
public void CreateSeasonFixtures() { // First find first available Saturday WorldAdapter wa = new WorldAdapter(); DateTime FirstMatchDate = wa.MainSeasonDate; while (FirstMatchDate.DayOfWeek != DayOfWeek.Saturday) { FirstMatchDate = FirstMatchDate.AddDays(1); } FixtureAdapter fa = new FixtureAdapter(); fa.ClearFixtures(); LeagueAdapter la = new LeagueAdapter(); List <League> Leagues = la.GetLeagues(); foreach (League L in Leagues) { // Get teams in the league we're looking at. TeamAdapter ta = new TeamAdapter(); List <Team> TeamList = ta.GetTeamsByLeague(L.UniqueID); // Create that league's fixtures (Circle Method) // https://en.wikipedia.org/wiki/Round-robin_tournament int NumberOfTeams = TeamList.Count(); int Half = NumberOfTeams / 2; int[] TeamIDs = new int[NumberOfTeams + 1]; // Create a grid with an additional blank space to allow rotation for (int i = 0; i < TeamList.Count(); i++) { TeamIDs[i] = TeamList[i].UniqueID; } TeamIDs[NumberOfTeams] = -999; // For debugging DateTime MatchDate = FirstMatchDate; for (int HomeAwayLeg = 1; HomeAwayLeg <= 2; HomeAwayLeg++) { bool homeFirst = (HomeAwayLeg == 1); for (int wk = 1; wk <= NumberOfTeams - 1; wk++) { // Make the week's fixtures for (int gridpos = 0; gridpos < Half; gridpos++) { Fixture f = new Fixture(); f.Date = MatchDate; f.LeagueID = L.UniqueID; if (homeFirst) { f.TeamIDs[0] = TeamIDs[gridpos]; f.TeamIDs[1] = TeamIDs[gridpos + Half]; } else { f.TeamIDs[1] = TeamIDs[gridpos]; f.TeamIDs[0] = TeamIDs[gridpos + Half]; } fa.AddFixture(f); } // Rotate the grid! (Clockwise, as opposed to the description in the wiki link) // Top "row" (first half) need to move L to R // Bottom "row" (second half) need to move R to L // Bottom left cell moves into position 1 and position 0 doesn't move // Comments below refer to 16 teams, grid positions 0-7 (top), 8-15 (bottom), 16 spare. TeamIDs[NumberOfTeams] = TeamIDs[Half - 1]; // Top right cell to bottom row, spare cell for (int i = Half - 2; i >= 1; i--) // Move top row, except cell zero and rightmost cell, right one { TeamIDs[i + 1] = TeamIDs[i]; } TeamIDs[1] = TeamIDs[Half]; // Bottom left cell to position 1 for (int i = Half; i <= NumberOfTeams - 1; i++) // Shift entire bottom row (including spare, excluding bottom left) left by one cell { TeamIDs[i] = TeamIDs[i + 1]; } // Go to next date MatchDate = MatchDate.AddDays(7); homeFirst = !homeFirst; } } } }