public InGameControl() { InitializeComponent(); beginGamePhaseControl = new BeginGamePhaseControl { Parent = gameStateMenuPanel, Dock = DockStyle.Fill }; beginGamePhaseControl.OnCommitted += () => { bool isNext = gameFlowHandler.NextPlayer(); if (isNext) { beginGamePhaseControl.ResetControl(); } else { beginGamePhaseControl.Hide(); beginRoundPhaseControl.Show(); GameState = GameState.RoundBeginning; gameFlowHandler.PlayRound(); } gameFlowHandler.Begin(); }; beginRoundPhaseControl = new BeginRoundPhaseControl { Parent = gameStateMenuPanel, Dock = DockStyle.Fill }; beginRoundPhaseControl.OnBegin += () => { beginRoundPhaseControl.Hide(); turnPhaseControl.Show(); GameState = GameState.Deploying; }; turnPhaseControl = new TurnPhaseControl { Parent = gameStateMenuPanel, Dock = DockStyle.Fill }; // reset selection when any other stage than attacking is invoked turnPhaseControl.OnCommitting += () => { gameFlowHandler.ResetSelection(); }; turnPhaseControl.OnDeploying += () => { gameFlowHandler.ResetSelection(); }; turnPhaseControl.OnCommitted += () => { bool isNext = gameFlowHandler.NextPlayer(); turnPhaseControl.Hide(); beginRoundPhaseControl.Show(); GameState = GameState.RoundBeginning; if (!isNext) { gameFlowHandler.PlayRound(); } if (Game.IsFinished()) { gameFlowHandler.End(); } else { gameFlowHandler.Begin(); } }; beginGamePhaseControl.Hide(); beginRoundPhaseControl.Hide(); turnPhaseControl.Hide(); }
private void ImageClick(object sender, MouseEventArgs e) { GameState state = InGameControl.GameState; if (state == GameState.Deploying) { try { switch (e.Button) { case MouseButtons.Left: gameFlowHandler.Deploy(e.X, e.Y, 1); break; case MouseButtons.Right: gameFlowHandler.Deploy(e.X, e.Y, -1); break; } } catch (ArgumentException exception) { #if (DEBUG) MessageBox.Show(exception.Message); #endif } } else if (state == GameState.Attacking) { int selectedRegionsCount = gameFlowHandler.Select(e.X, e.Y); if (selectedRegionsCount == 2) { AttackManagerForm attackManager = new AttackManagerForm { ArmyLowerLimit = 0, ArmyUpperLimit = gameFlowHandler.GetUnitsLeftToAttackInAttackingRegion() }; DialogResult dialogResult = attackManager.ShowDialog(); // execute the attack if (dialogResult == DialogResult.OK) { gameFlowHandler.Attack(attackManager.AttackingArmy); } else { gameFlowHandler.ResetSelection(); } } } else if (state == GameState.GameBeginning) { try { gameFlowHandler.Seize(e.X, e.Y); } catch (ArgumentNullException error) { MessageBox.Show(error.Message); } catch (ArgumentException error) { MessageBox.Show(error.Message); } } }