private void ManualRoll(int dieValue) { string panelName = "panel_d" + dieValue; string labelName = "label_d" + dieValue + "Result"; //I know that none of this is proper practice, but I just wanted to see if I could do it //Parsing based on control name is not ideal var panel = this.Controls.Find(panelName, true).First(); var label = this.Controls.Find(labelName, true).First(); panel_d4.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Qty")).First(); TextBox tb_Qty = panel.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Qty")).First(); TextBox tb_Mod = panel.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Mod")).First(); int result = RollFunctions.RollCalc(tb_Qty.Text, dieValue, tb_Mod.Text); if (result == 1 & dieValue == 20 & string.IsNullOrEmpty(tb_Mod.Text)) { /* * critical fail easter egg * pb_Unlucky.Enabled = true; * pb_Unlucky.Visible = true; * var timer = new System.Timers.Timer(3500); * timer.Elapsed += UnluckyTimerEvent; * timer.Start(); */ } lbl_FinalRoll.Text = result.ToString(); }
private void rollConcat(object sender, EventArgs e) { int total = 0; var panels = diceGroupBox.Controls.OfType <Panel>(); foreach (Panel panel in panels) { Button dieButton = sender as Button; string[] panelSplit = panel.Name.Split('d'); int dieValue = int.Parse(panelSplit[1]); string panelName = "panel_d" + dieValue; string labelName = "label_d" + dieValue + "Result"; //Again, not proper practice. But it was a fun challenge var label = this.Controls.Find(labelName, true).First(); panel_d4.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Qty")).First(); TextBox tb_Qty = panel.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Qty")).First(); TextBox tb_Mod = panel.Controls.OfType <TextBox>().Where(tb => tb.Name.Contains("Mod")).First(); if (!string.IsNullOrEmpty(tb_Qty.Text)) { int result = RollFunctions.RollCalc(tb_Qty.Text, dieValue, tb_Mod.Text); label.Text = result.ToString(); total += result; } label_dbTotal.Text = total.ToString(); } }
private (string Total, string[] IndividualRolls) ParseRoll(string rollString) { int total = 0; string processingType = ""; DieRegex.parseRoll(rollString); string[] rollTokens = rollString.Split('+', '-'); string[] indivRolls = new string[rollTokens.Length]; int indivIndex = 0; int result; foreach (string individualRoll in rollTokens) { string[] rollValue = individualRoll.Split('d'); if (rollValue.Length > 1) { processingType = "dice roll"; } else { processingType = "integer"; } switch (processingType) { case "dice roll": if (rollValue[0].Contains(" ")) { rollValue[0] = rollValue[0].Replace(" ", string.Empty); } if (rollValue[1].Contains(" ")) { rollValue[1] = rollValue[1].Replace(" ", string.Empty); } if (!validRolls.Contains(rollValue[1])) { MessageBox.Show(rollValue[1] + " is not a valid die. Please check your roll string", "Roll check", MessageBoxButtons.OK); return(string.Empty, new string[0]); } else { result = RollFunctions.Roll(Convert.ToInt16(rollValue[0]), Convert.ToInt16(rollValue[1])); total += result; indivRolls[indivIndex] = result.ToString(); indivIndex++; } break; case "integer": result = int.Parse(rollValue[0]); total += result; indivRolls[indivIndex] = result.ToString(); indivIndex++; break; } } return(total.ToString(), indivRolls); }
private void TriggerSkillRoll(object sender, DataGridViewCellMouseEventArgs e) { int SelectedRow = e.RowIndex; var row = SkillsTable.Rows[SelectedRow]; int modValue = int.Parse(row[1].ToString()); var rollResult = RollFunctions.Roll(1, 20); var total = modValue + rollResult; lbl_FinalRoll.Text = total.ToString(); }