private void updateLabelandScore(int i) { Yahtzee formYahtzee = Globals.formYahtzee; string targetLabel = "lblTotalScore" + (i + 1); Control[] labels2 = formYahtzee.Controls.Find(targetLabel, true); Label lblScore = (Label)labels2[0]; int score = 0; score = int.Parse((lblScore.Text)); if (score >= 5) { if (i == 0) { int newNumberOfCheats = model.NumberBoughtCheats++; lblAantalCheat1.Text = newNumberOfCheats.ToString(); UseTotalScore(i); } else { int newNumberOfCheats = model.NumberBoughtCheats++; lblAantalCheat2.Text = newNumberOfCheats.ToString(); UseTotalScore(i); } } else { MessageBox.Show("You need at least 5 points to use this cheat!"); } }
private void UseTotalScore(int i) { int totalscore = mScoreboardControl[i].model.TotalScore; totalscore -= 5; Yahtzee formYahtzee = Globals.formYahtzee; formYahtzee.updateTotalLabelScore(i, totalscore); }
public void updateTotalLabelScore(int i, int totalScore) { Yahtzee formYahtzee = Globals.formYahtzee; string targetLabel; targetLabel = "lblTotalScore" + (i + 1); Control[] labels2 = formYahtzee.Controls.Find(targetLabel, true); if (labels2.Length == 1) { lblScore = (Label)labels2[0]; } lblScore.Text = totalScore.ToString(); }
private void btnUseCheat2_Click(object sender, EventArgs e) { if (lblAantalCheat2.Text == "0") { ShowMessageNoCheats("Cheat2"); } else { if (ScoreboardModel.Aantalworpen == 3) { Yahtzee formyahtzee = new Yahtzee(); btnUseOneCheat(2); formyahtzee.extraTeerlingTonen(); } else { MessageBox.Show("Roll at least 3 times before you can use this cheat!"); } } }
public void UpdateTotaalScore() { Yahtzee formYahtzee = Globals.formYahtzee; //Label lblScore = null; string targetLabel; for (int i = 0; i < 2; i++) { int totalScore = 0; for (int j = 0; j < 6; j++) { targetLabel = "lblScore" + (i + 1) + (j + 1); Control[] labels = formYahtzee.Controls.Find(targetLabel, true); if (labels.Length == 1) { lblScore = (Label)labels[0]; // formYahtzee.updateScores( player1Scores , player2Scores) } else { MessageBox.Show("werkt niet"); } totalScore += Int32.Parse(lblScore.Text); } targetLabel = "lblTotalScore" + (i + 1); Control[] labels2 = formYahtzee.Controls.Find(targetLabel, true); if (labels2.Length == 1) { lblScore = (Label)labels2[0]; } else { MessageBox.Show("werkt niet"); } mScoreboardControl[i].model.TotalScore = totalScore; lblScore.Text = mScoreboardControl[i].model.TotalScore.ToString(); } }
public void OnClick(object sender, EventArgs e) { Button clickedButton = (Button)sender; Yahtzee formYahtzee = Globals.formYahtzee; Label lblScore = null; int aantal = 0; int btnScoreWaarde = (clickedButton.Name[clickedButton.Name.Length - 1] - 48); //ASCII code voor 1 is 49(dus -48) //string btnYahtzeeName = clickedButton.Name.ToString(); Boolean yahtzeeWorp = true; // wordt op false gezet zodra er een dobbelsteen verschillend is int yahtzeeWorpWaarde = 0; clickedButton.Enabled = false; for (int i = 0; i < formYahtzee.mAantalTeerlingen; i++) { if (formYahtzee.mTeerlingenControl[i].model.AantalOgen == btnScoreWaarde) { aantal++; } if (i == 0) // eerste dobbelsteen { yahtzeeWorpWaarde = formYahtzee.mTeerlingenControl[i].model.AantalOgen; } else { if (formYahtzee.mTeerlingenControl[i].model.AantalOgen != yahtzeeWorpWaarde) { yahtzeeWorp = false; } } } if (yahtzeeWorp && (btnScoreWaarde == 7)) { MessageBox.Show("Yahtzee"); } //string targetLabel = "lblScore" + suffix; string targetLabel = clickedButton.Name.Replace("btnName", "lblScore"); Control[] labels = formYahtzee.Controls.Find(targetLabel, true); if (labels.Length == 1) { lblScore = (Label)labels[0]; // formYahtzee.updateScores( player1Scores , player2Scores) } else { MessageBox.Show("werkt niet"); } lblScore.Text = (aantal * btnScoreWaarde).ToString(); if (yahtzeeWorp && (btnScoreWaarde == 7)) { lblScore.Text = "50"; } formYahtzee.UpdateTotaalScore(); //MessageBox.Show(""+ btnScoreWaarde); }