private void OpacityBtn_Click(object sender, RoutedEventArgs e) { SoundPlayer sp = new SoundPlayer(); sp.SoundLocation = "Sound_18567.wav"; sp.Load(); sp.Play(); DoubleAnimation animationOpacityOn = new DoubleAnimation(Opacity = 1, new Duration(TimeSpan.FromMilliseconds(1000)), FillBehavior.HoldEnd); animationOpacityOn.AutoReverse = true; Cow2.BeginAnimation(OpacityProperty, animationOpacityOn); if (B1.Opacity == 1 && B2.Opacity == 1 && B3.Opacity == 1 && B4.Opacity == 1) { string SelectedByPlayerNumber = B1.number.ToString() + B2.number.ToString() + B3.number.ToString() + B4.number.ToString(); int countOfBulls = 0; int countOfCows = 0; if (SelectedByPlayerNumber[0] == '0') { MessageBox.Show("Zero cannot stand in first position. It is a four digit number!"); } else { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (SelectedByPlayerNumber[i] == UnknownNumber[j]) { if (i == j) { countOfBulls++; } else { countOfCows++; } break; } } } TableOfResults.Text += SelectedByPlayerNumber + " " + "Bulls:" + " " + countOfBulls + " " + "Cows:" + " " + countOfCows + "\r\n"; countOfStrokes++; if (countOfBulls == 4) { GameIsWonStatus = true; MessageBox.Show("Congratulations! You guessed the number!"); } } } else { MessageBox.Show("Set all the digits of the number and try again!"); } }
static void MainB() { Cow2 c1 = new Cow2(); Cow2 c2 = new Cow2(); c1.Moo(); c1.Moo(); c1.Moo(); c2.Moo(); }
private void Form1_Load(object sender, EventArgs e) { //Schovat Kravy a Byky #region Bull1.Hide(); Bull2.Hide(); Bull3.Hide(); Bull4.Hide(); Cow1.Hide(); Cow2.Hide(); Cow3.Hide(); Cow4.Hide(); point = 0; lblPoint.Text = point.ToString(); #endregion //Generovani #region //Prvni kroky #region Random rnd = new Random(); num1 = 0; num2 = 0; num3 = 0; num4 = 0; #endregion //Generovani #region num1 = rnd.Next(0, 9); num2 = rnd.Next(0, 9); while (num2 == num1) { num2 = rnd.Next(0, 9); } num3 = rnd.Next(0, 9); while (num3 == num2 || num3 == num1) { num3 = rnd.Next(0, 9); } num4 = rnd.Next(0, 9); while (num4 == num3 || num4 == num2 || num4 == num1) { num4 = rnd.Next(0, 9); } #endregion //Uchovani #region data = new string[] { num1.ToString(), num2.ToString(), num3.ToString(), num4.ToString(), }; System.IO.File.WriteAllLines("data.txt", data); #endregion #endregion }
private void BtnOk_Click(object sender, EventArgs e) { //Hide Cows and Bulls #region Bull1.Hide(); Bull2.Hide(); Bull3.Hide(); Bull4.Hide(); Cow1.Hide(); Cow2.Hide(); Cow3.Hide(); Cow4.Hide(); #endregion //Accept data #region data = System.IO.File.ReadAllLines("data.txt"); num1 = Convert.ToInt32(data[0]); num2 = Convert.ToInt32(data[1]); num3 = Convert.ToInt32(data[2]); num4 = Convert.ToInt32(data[3]); #endregion //Zero #region bull = 0; cow = 0; #endregion //Divide a number (rozdělit na celé císlo) #region int i = Convert.ToInt32(textBox1.Text); int a = i / 1000; int b = (i - (a * 1000)) / 100; int c = ((i - ((a * 1000) + (b * 100))) / 10); int d = (i - ((a * 1000) + (b * 100) + (c * 10))); #endregion //chief code (Hlavni kod) #region if (a == b || a == c || a == d) { MessageBox.Show("Type different numbers"); } else { if (b == a || b == c || b == d) { MessageBox.Show("Type different numbers"); } else { if (c == d || c == b || c == a) { MessageBox.Show("Type different numbers"); } else { //Beyond (Dal) #region //Bulls #region if (a == num2 || a == num3 || a == num4) { bull++; } if (b == num1 || b == num3 || b == num4) { bull++; } if (c == num1 || c == num2 || c == num4) { bull++; } if (d == num1 || d == num2 || d == num3) { bull++; } #endregion //Cow #region if (a == num1) { cow++; } if (b == num2) { cow++; } if (c == num3) { cow++; } if (d == num4) { cow++; } #endregion #endregion } } } #endregion //Show #region //bull #region if (bull == 1) { Bull1.Show(); } if (bull == 2) { Bull1.Show(); Bull2.Show(); } if (bull == 3) { Bull1.Show(); Bull2.Show(); Bull3.Show(); } if (bull == 4) { Bull1.Show(); Bull2.Show(); Bull3.Show(); Bull4.Show(); } #endregion //cow #region if (cow == 1) { Cow1.Show(); } if (cow == 2) { Cow1.Show(); Cow2.Show(); } if (cow == 3) { Cow1.Show(); Cow2.Show(); Cow3.Show(); } if (cow == 4) { Cow1.Show(); Cow2.Show(); Cow3.Show(); Cow4.Show(); if (point == 1) { blabla = "You are lucky! XD"; } else if (point <= 10) { blabla = "Very very good! Nice game! xD"; } else if (point > 10 && point <= 20) { blabla = "Not bad!"; } else if (point > 20) { blabla = "May be better."; } MessageBox.Show("You won! You had " + point.ToString() + " attempts! " + blabla); } #endregion #endregion //Points #region point++; lblPoint.Text = point.ToString(); #endregion }
public static void Moo(this Cow2 _this) { _this.numMoos++; Console.WriteLine("Mooooo" + _this.numMoos); }