public Form1() { InitializeComponent(); yahtzee = new Yahtzee(); diceButtonWith = this.ClientRectangle.Width / (Yahtzee.GetNumberOfDice() + 1); buttonHeight = this.ClientRectangle.Height / (yahtzee.GetNumberOfScoreOptions() + 1 + buttonHeightLeftOver); diceToPutAway = new List <Dice>(); UpdateDice(); UpdateScoreOptionButtons(); UpdateRerollButton(); UpdateScoreBoard(); }
private void UpdateScoreOptionButtons() { if (scoreOptionButtons == null && scoreOptionButtonFunction == null) { scoreOptionButtons = new Button[yahtzee.GetNumberOfScoreOptions()]; scoreOptionButtonFunction = new ButtonFunction[scoreOptionButtons.Length]; Action <Object> scoreButtonFunction = (Object scoreOption) => { if (yahtzee.GetIfOption(scoreOption)) { diceToPutAway.Clear(); yahtzee.UseScoreOption(scoreOption); yahtzee.NextRound(); UpdateDice(); UpdateScoreOptionButtons(); UpdateScoreBoard(); UpdateRerollButton(); } else { MessageBox.Show(messageBoxScoreOptionNotPossible); } }; for (int i = 0; i < scoreOptionButtons.Length; i++) { scoreOptionButtons[i] = new Button(); Point point = new Point(0, buttonHeight * (i + 1)); scoreOptionButtons[i].Location = point; scoreOptionButtons[i].Width = this.ClientRectangle.Width; scoreOptionButtons[i].Height = buttonHeight; scoreOptionButtons[i].Click += new EventHandler(UseScoreButton); scoreOptionButtonFunction[i] = new ButtonFunction(scoreOptionButtons[i], scoreButtonFunction, null); Controls.Add(scoreOptionButtons[i]); } } else if (scoreOptionButtons == null || scoreOptionButtonFunction == null) { throw new Exception(exceptionUpdateScoreOptionButtonsDoesntFullyExist); } else { for (int i = 0; i < scoreOptionButtons.Length; i++) { Controls.Remove(scoreOptionButtons[i]); } } string[] scoreTexts = yahtzee.GetScoreOptionsText(); object[] scoreOptions = yahtzee.GetScoreOptions(); int numberOfButton = 0; for (int i = 0; i < scoreOptions.Length; i++) { if (scoreOptions[i] != null && numberOfButton < scoreOptionButtons.Length) { scoreOptionButtons[numberOfButton].Text = scoreTexts[i]; scoreOptionButtons[numberOfButton].Location = new Point(0, buttonHeight * (numberOfButton + 1)); Controls.Add(scoreOptionButtons[numberOfButton]); scoreOptionButtonFunction[numberOfButton].SetFunctionParameter(scoreOptions[i]); numberOfButton++; } } }