public override void OnInit() { Logger.Info("Starting game with controller {0} and players {1} and {2}", this.MainSettings.Controller.GetType().Name, this.Players[0].Name, this.Players[1].Name); base.OnInit(); this.StaticEntities = new ClashEngine.NET.EntitiesManager.EntitiesManager(this.GameInfo); this.Controller.GameState = this; this.MainSettings.VictoryRules.GameState = this; this.Controller.PreGameStarted(); this.Players[0].Type = PlayerType.First; this.PlayerControllers[0].Player = this.Players[0]; this.PlayerControllers[0].GameState = this; this.PlayerControllers[0].Initialize(this.OwnerManager, this.GameInfo.MainWindow.Input); this.Players[1].Type = PlayerType.Second; this.PlayerControllers[1].Player = this.Players[1]; this.PlayerControllers[1].GameState = this; this.PlayerControllers[1].Initialize(this.OwnerManager, this.GameInfo.MainWindow.Input); float h = NET.Settings.ScreenSize * (Configuration.Instance.WindowSize.Height / (float)Configuration.Instance.WindowSize.Width); var cam = new ClashEngine.NET.Graphics.Cameras.Movable2DCamera(new OpenTK.Vector2(NET.Settings.ScreenSize, h), new System.Drawing.RectangleF(0f, 0f, this.Map.Size.X, Math.Max(this.Map.Size.Y + NET.Settings.MapMargin, h))); this.Camera = cam; this.StaticEntities.Add(cam.GetCameraEntity(Configuration.Instance.CameraSpeed)); this.StaticEntities.Add(this.Map); this.StaticEntities.Add(new Player.PlayerEntity(this.Players[0], this)); this.StaticEntities.Add(new Player.PlayerEntity(this.Players[1], this)); //Od tej chwili to kontroler jest odpowiedzialny za wszystko. this.Controller.GameStarted(); Logger.Info("Game started"); }
private bool GameStartedHandler(Message msg) { if (this.InGame) return false; Messages.GameStarted gameStarted = new Messages.GameStarted(msg); var p1 = this.PlayersInLobby.Find(p => p.UserId == gameStarted.PlayerA); var p2 = this.PlayersInLobby.Find(p => p.UserId == gameStarted.PlayerB); this.Players = new Player.Player[] { new Player.Player(p1.Nick, p1.Nation, 100) { Type = Interfaces.Player.PlayerType.First }, new Player.Player(p2.Nick, p2.Nation, 100) { Type = Interfaces.Player.PlayerType.Second } }; this.Map = new Maps.DefaultMap(); float h = NET.Settings.ScreenSize * (Configuration.Instance.WindowSize.Height / (float)Configuration.Instance.WindowSize.Width); var cam = new ClashEngine.NET.Graphics.Cameras.Movable2DCamera(new OpenTK.Vector2(NET.Settings.ScreenSize, h), new System.Drawing.RectangleF(0f, 0f, this.Map.Size.X, Math.Max(this.Map.Size.Y + NET.Settings.MapMargin, h))); this.Camera = cam; this.Entities.Add(cam.GetCameraEntity(Configuration.Instance.CameraSpeed)); this.Entities.Add(this.Map); this.Entities.Add(new Player.PlayerEntity(this.Players[0], this)); this.Entities.Add(new Player.PlayerEntity(this.Players[1], this)); if (this.UserId == gameStarted.PlayerA) { //TODO: GUI dla gracza A } else if (this.UserId == gameStarted.PlayerB) { //TODO: GUI dla gracza B } else { //TODO: GUI obserwatora } return true; }