Exemplo n.º 1
0
 private void Repeat(object sender, EventArgs e)
 {
     nextButton.Enabled = true;
     ResetStateHighlight(State);
     State = GameState.Deploying;
     HighlightCorrectButton(State);
     gameFlowHandler.ResetTurn();
     InvokeStateEvent(State);
 }
Exemplo n.º 2
0
 private void Committing(object sender, EventArgs e)
 {
     nextButton.Enabled = true;
     ResetStateHighlight(State);
     // committing phase
     State = GameState.Committing;
     // highlight
     HighlightCorrectButton(State);
     OnCommitting?.Invoke();
 }
Exemplo n.º 3
0
        private void Attacking(object sender, EventArgs e)
        {
            nextButton.Enabled = true;
            ResetStateHighlight(State);
            // committing phase
            if (State > GameState.Attacking)
            {
                OnReset?.Invoke(GameState.Committing);
            }

            State = GameState.Attacking;
            // highlight
            HighlightCorrectButton(State);
            // propagate into outer form
            OnAttacking?.Invoke();
        }
Exemplo n.º 4
0
        private void HighlightCorrectButton(GameState state)
        {
            switch (state)
            {
            case GameState.Deploying:
                deployLabel.BackColor = Color.GreenYellow;
                break;

            case GameState.Attacking:
                attackLabel.BackColor = Color.GreenYellow;
                break;

            case GameState.Committing:
                commitLabel.BackColor = Color.GreenYellow;
                break;
            }
        }
Exemplo n.º 5
0
        private void ResetStateHighlight(GameState state)
        {
            switch (state)
            {
            case GameState.Deploying:
                deployLabel.BackColor = Color.Transparent;
                break;

            case GameState.Attacking:
                attackLabel.BackColor = Color.Transparent;
                break;

            case GameState.Committing:
                commitLabel.BackColor = Color.Transparent;
                break;
            }
        }
Exemplo n.º 6
0
        private void Deploying(object sender, EventArgs e)
        {
            nextButton.Enabled = true;
            ResetStateHighlight(State);

            // committing phase
            if (State > GameState.Deploying)
            {
                gameFlowHandler.ResetAttacking();
            }

            State = GameState.Deploying;

            // highlight button
            HighlightCorrectButton(State);

            OnDeploying?.Invoke();
        }
Exemplo n.º 7
0
        private void InvokeStateEvent(GameState state)
        {
            switch (state)
            {
            case GameState.Deploying:
                OnDeploying?.Invoke();
                break;

            case GameState.Attacking:
                OnAttacking?.Invoke();
                break;

            case GameState.Committing:
                OnCommitting?.Invoke();
                break;

            case GameState.Committed:
                OnCommitted?.Invoke();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
        }
Exemplo n.º 8
0
        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);
                }
            }
        }