/// <summary> /// Initializes <see cref="MapHandlerControl"/> instance. /// </summary> /// <param name="gameFlowHandler"></param> public void Initialize(GameFlowHandler gameFlowHandler) { this.gameFlowHandler = gameFlowHandler; if (gameFlowHandler == null) { throw new ArgumentException(); } gameMapPictureBox.SizeMode = PictureBoxSizeMode.Normal; gameMapPictureBox.Image = gameFlowHandler.ImageProcessor.MapImage; gameMapPictureBox.Height = gameMapPictureBox.Image.Height; gameMapPictureBox.Width = gameMapPictureBox.Image.Width; gameMapPictureBox.BackgroundImage = gameFlowHandler.ImageProcessor.TemplateImage; this.gameFlowHandler.OnImageChanged += gameMapPictureBox.Refresh; }
public void Initialize(GameFlowHandler gameFlowHandler) { this.gameFlowHandler = gameFlowHandler; }
public void Initialize(Game game) { if (game == null) { throw new ArgumentException("Game cannot be null."); } MapImageProcessor mapImageProcessor; using (UtilsDbContext db = new UtilsDbContext()) { MapInfo mapInfo = (from item in db.Maps where item.Id == game.Map.Id select item).First(); mapImageProcessor = MapImageProcessor.Create(game.Map, mapInfo.ImageColoredRegionsPath, mapInfo.ColorRegionsTemplatePath, mapInfo.ImagePath, game.IsFogOfWar); } // initialize game switch (game.GameType) { case GameType.SinglePlayer: gameFlowHandler = new SingleplayerGameFlowHandler(game, mapImageProcessor); break; case GameType.MultiplayerHotseat: gameFlowHandler = new HotseatGameFlowHandler(game, mapImageProcessor); break; case GameType.MultiplayerNetwork: throw new NotImplementedException(); } // initialize map processor mapHandlerControl.Initialize(gameFlowHandler); gameFlowHandler.OnRoundPlayed += () => { using (UtilsDbContext db = new UtilsDbContext()) { gameFlowHandler.Game.Save(db); } }; gameFlowHandler.OnBegin += () => { MessageBox.Show($"Player {gameFlowHandler.PlayerOnTurn.Name} is on turn."); }; gameFlowHandler.OnEnd += player => { MessageBox.Show($"Player {player.Name} has won the game!"); beginGamePhaseControl.Hide(); turnPhaseControl.Hide(); beginRoundPhaseControl.Hide(); GameState = GameState.GameEnd; }; beginGamePhaseControl.Initialize(gameFlowHandler); turnPhaseControl.Initialize(gameFlowHandler); // initialize game state if (game.RoundNumber == 0) { GameState = GameState.GameBeginning; beginGamePhaseControl.Show(); gameFlowHandler.Begin(); } else if (game.IsFinished()) { gameFlowHandler.End(); } else { GameState = GameState.RoundBeginning; beginRoundPhaseControl.Show(); gameFlowHandler.Begin(); } }