Hej Jacob tak for interesse :-)
Er ny i C# og derfor er koden nok lidt knoldet. Der er ikke så meget kode
her er al kode i klassen rules, som kaldes fra klassen presentation
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace yatzy
- {
- public class rules
- {
- int Sum;
- int d1;
- int d2;
- int d3;
- public bool rule_1;
-
- public string nameRoll;
-
- public rules(string aNameRoll)
- {
- nameRoll = aNameRoll;
- } // lukker rules
- public string rname()
- {
- return nameRoll;
- }
-
- public void setDice(int ad1, int ad2, int ad3)
- {
-
- d1 = ad1;
- d2 = ad2;
- d3 = ad3;
-
- this.Sum = 10; // d1 + d2 + d3;
-
- }
-
- public bool twokB_1()
- {
- return rule_1;
- }
- public int twokI_1()
- {
- int aSum = this.Sum;
-
- return aSum;
-
- }
Her er klassen Presentation
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace yatzy
- {
- public partial class presentation : Form
- {
-
- int rollCount = 0;
- int Roll_1;
- int Roll_2;
- int Roll_3;
- int rulePoint;
- int rulePoint1;
- int rulePoint2;
- int rulePoint3;
- int rulePoint4;
- int rulePoint5;
- int rulePoint6;
- string R_1;
- string R_2;
- string R_3;
- Random MyRoll = new Random();
- player player_1 = new player("Søren");
- rules myDiceRoll = new rules("Roll_1");
-
- public presentation()
- {
- InitializeComponent();
- checkBoxRule1.Enabled = false;
- checkBoxRule1.Enabled = myDiceRoll.twokB_1();
- terningeslag1.Text = "0";
- checkBoxHold1.Enabled = false; checkBoxHold2.Enabled = false; checkBoxHold3.Enabled = false;
- playerName.Text = Convert.ToString(player_1.getPlayerName());
-
- }
-
- public void Welcome_Click(object sender, EventArgs e)
- {
-
- }
-
- public void Number_of_players_cb_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- }
-
- public void label5_Click(object sender, EventArgs e)
- {
-
- }
-
- public void pl25_TextChanged(object sender, EventArgs e)
- {
-
- }
-
- public void pl31_TextChanged(object sender, EventArgs e)
- {
-
- }
-
- public void kastterning_Click(object sender, EventArgs e)
- {
-
- rollCount++;
- if (rollCount > 0)
- { checkBoxHold1.Enabled = true; checkBoxHold2.Enabled = true; checkBoxHold3.Enabled = true; }
-
- if (rollCount < 4)
- {
- if (checkBoxHold1.Checked && checkBoxHold2.Checked && checkBoxHold3.Checked)
- {
-
- Roll_1 = int.Parse(R_1);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = int.Parse(R_2);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = int.Parse(R_3);
- R_3 = Convert.ToString(Roll_3);
- }
- else if (checkBoxHold1.Checked && checkBoxHold2.Checked)
- {
- Roll_1 = int.Parse(R_1);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = int.Parse(R_2);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = MyRoll.Next(1, 7);
- R_3 = Convert.ToString(Roll_3);
- }
-
- else if (checkBoxHold1.Checked && checkBoxHold3.Checked)
- {
- Roll_1 = int.Parse(R_1);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = MyRoll.Next(1, 7);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = int.Parse(R_3);
- R_3 = Convert.ToString(Roll_3);
- }
-
- else if (checkBoxHold2.Checked && checkBoxHold3.Checked)
- {
- Roll_1 = MyRoll.Next(1, 7);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = int.Parse(R_2);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = int.Parse(R_3);
- R_3 = Convert.ToString(Roll_3);
- }
-
- else if (checkBoxHold1.Checked)
- {
- Roll_1 = int.Parse(R_1);
- // Roll_1 = Convert.ToInt16(R_1);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = MyRoll.Next(1, 7);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = MyRoll.Next(1, 7);
- R_3 = Convert.ToString(Roll_3);
-
- }
- else if (checkBoxHold2.Checked)
- {
-
- Roll_1 = MyRoll.Next(1, 7);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = int.Parse(R_2);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = MyRoll.Next(1, 7);
- R_3 = Convert.ToString(Roll_3);
-
- }
-
- else if (checkBoxHold3.Checked)
- {
-
- Roll_1 = MyRoll.Next(1, 7);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = int.Parse(R_2);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = int.Parse(R_3);
- R_3 = Convert.ToString(Roll_3);
-
- }
-
- else
- {
- Roll_1 = MyRoll.Next(1, 7);
- R_1 = Convert.ToString(Roll_1);
- Roll_2 = MyRoll.Next(1, 7);
- R_2 = Convert.ToString(Roll_2);
- Roll_3 = MyRoll.Next(1, 7);
- R_3 = Convert.ToString(Roll_3);
-
- }
- if (rollCount == 3)
- { kastterning.Text = "Vælg en ko"; }
-
- int[] roll_i = { Roll_1, Roll_2, Roll_3 };
- myDiceRoll.setDice(5, 6, 5);
- string[] roll_s = { R_1, R_2, R_3 };
- terningeslag1.Text = roll_s[0];
- terningeslag2.Text = roll_s[1];
- terningeslag3.Text = roll_s[2];
-
- }
- }
-
- private void label3_Click(object sender, EventArgs e)
- {
-
- }
-
- private void label2_Click(object sender, EventArgs e)
- {
-
- }
-
- public void button1_Click(object sender, EventArgs e)
- {
-
- rulePoint = Roll_1 + Roll_2;
-
-
-
- if (checkBoxRule1.Checked && checkBoxRule1.Enabled)
- {
- rulePoint1 = Roll_1 + Roll_2 + Roll_3;
- player_1.setRule_1(rulePoint1);
- labelRule_1.Text = Convert.ToString(player_1.getRule_1());
- checkBoxRule1.Enabled = false;
- }
-
- else
- {
- checkBoxRule1.Enabled = false;
- player_1.setRule_1(0);
- }
-
-
-
- if (checkBoxRule2.Checked && checkBoxRule2.Enabled)
- {
- rulePoint2 = Roll_1 + Roll_2 + Roll_3;
- player_1.setRule_2(rulePoint2);
- labelRule_2.Text = Convert.ToString(player_1.getRule_2());
- checkBoxRule2.Enabled = false;
- }
- else
- {
- player_1.setRule_2(0);
- }
-
- if (checkBoxRule3.Checked && checkBoxRule3.Enabled)
- {
- rulePoint3 = Roll_1 + Roll_2;
- player_1.setRule_3(rulePoint3);
- labelRule_3.Text = Convert.ToString(player_1.getRule_3());
- checkBoxRule3.Enabled = false;
- }
- else
- {
- player_1.setRule_3(0);
- }
-
- // 4+4
- if (checkBoxRule4.Checked && checkBoxRule4.Enabled)
- {
- rulePoint4 = Roll_1 + Roll_2 + Roll_3;
- player_1.setRule_4(rulePoint4);
- labelRule_4.Text = Convert.ToString(player_1.getRule_4());
- checkBoxRule4.Enabled = false;
- }
- else
- {
- player_1.setRule_4(0);
- }
- // 5+5
- if (checkBoxRule5.Checked && checkBoxRule5.Enabled)
- {
- rulePoint5 = Roll_1 + Roll_2 + Roll_3;
- player_1.setRule_5(rulePoint5);
- labelRule_5.Text = Convert.ToString(player_1.getRule_5());
- checkBoxRule5.Enabled = false;
- }
- else
- {
- player_1.setRule_5(0);
- }
- // 6+6
- if (checkBoxRule6.Checked && checkBoxRule6.Enabled)
- {
- rulePoint6 = Roll_1 + Roll_2 + Roll_3;
- player_1.setRule_6(rulePoint6);
- labelRule_6.Text = Convert.ToString(player_1.getRule_6());
- checkBoxRule6.Enabled = false;
- }
- else
- {
- player_1.setRule_6(0);
- }
-
-
- int sumRulePoint = rulePoint1 + rulePoint2 + rulePoint3 + rulePoint4 + rulePoint5 + rulePoint6;
- player_1.setSum(sumRulePoint);
- rollCount = 0;
- terningeslag1.Text = "0";
- terningeslag2.Text = "0";
- terningeslag3.Text = "0";
- labelSum.Text = Convert.ToString(player_1.sum());
- labelBonus.Text = Convert.ToString(player_1.bonus());
- labelTotal.Text = Convert.ToString(player_1.Total());
- kastterning.Text = "Kast terning";
- if (checkBoxHold1.Checked)
- {
- checkBoxHold1.Checked = false;
- }
- if (checkBoxHold2.Checked)
- {
- checkBoxHold2.Checked = false;
- }
- if (checkBoxHold3.Checked)
- {
- checkBoxHold3.Checked = false;
- }
-
- }
-
- public void checkBox3_CheckedChanged(object sender, EventArgs e)
- {
-
- }
-
- private void checkBoxRule2_CheckedChanged(object sender, EventArgs e)
- {
- checkBoxRule2.Enabled = false;
- }
-
- private void label9_Click(object sender, EventArgs e)
- {
-
- }
-
- private void presentation_Load(object sender, EventArgs e)
- {
-
- }
- }
-
- }
samt klassen player, som ikke har indflydelse på klassen rules
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace yatzy
- {
- public class player
- {
- string nameOfPlayer;
- int valueRule_1;
- int valueRule_2;
- int valueRule_3;
- int valueRule_4;
- int valueRule_5;
- int valueRule_6;
- int allSum;
- int aBonus;
- int aTotal;
-
-
-
- public player(string aNameOfPlayer)
- {
- nameOfPlayer = aNameOfPlayer;
- }
- public string getPlayerName()
- {
- return nameOfPlayer;
- }
-
- // RULE 1+1
- public void setRule_1(int aPoint)
- {
- valueRule_1 = aPoint;
- }
-
- public int getRule_1()
- {
- return valueRule_1;
- }
-
- // RULE 3+3
- public void setRule_2(int aPoint)
- {
-
- valueRule_2 = aPoint;
- }
-
- public int getRule_2()
- {
- return valueRule_2;
- }
-
- // RULE 3+3
- public void setRule_3(int aPoint)
- {
-
- valueRule_3 = aPoint;
- }
-
- public int getRule_3()
- {
- return valueRule_3;
- }
-
- // RULE 4+4
- public void setRule_4(int aPoint)
- {
-
- valueRule_4 = aPoint;
- }
-
- public int getRule_4()
- {
- return valueRule_4;
- }
-
- // RULE 5+5
- public void setRule_5(int aPoint)
- {
-
- valueRule_5 = aPoint;
- }
-
- public int getRule_5()
- {
- return valueRule_5;
- }
-
- // RULE 6+6
- public void setRule_6(int aPoint)
- {
-
- valueRule_6 = aPoint;
- }
-
- public int getRule_6()
- {
- return valueRule_6;
- }
-
-
- //SUM
- public void setSum(int aSum)
- {
- allSum = aSum;
- }
- public int sum()
- {
- //allSum = valueRule_1 + valueRule_2 + valueRule_3 + valueRule_4 + valueRule_5 + valueRule_6;
-
- return allSum;
- }
- //BONUS
- public int bonus()
- {
- if (allSum < 3)
- {
- aBonus = 0;
- }
- else
- {
- aBonus = 10;
- }
- return aBonus;
- }
- //TOTAL
- public int Total()
- {
-
- aTotal = allSum + aBonus;
-
- return aTotal;
- }
-
-
- }
- }