Ejemplo n.º 1
0
        private void buttonLosuj_Click(object sender, EventArgs e)
        {
            var a = 0;
            var b = 0;


            try
            {
                a = int.Parse(textBoxOd.Text);
                b = int.Parse(textBoxDo.Text);

                g = new Gra(a, b);


                groupBoxGra.Visible    = true;
                groupBoxLosuj.Enabled  = false;
                groupBoxGra.Enabled    = true;
                buttonHistoria.Enabled = true;
                buttonPrzerwij.Enabled = true;
                timer1.Enabled         = true;
            }
            catch (System.FormatException)
            {
                MessageBox.Show("B³êdne dane");
                textBoxOd.Enabled      = textBoxDo.Enabled = true;
                groupBoxGra.Visible    = false;
                groupBoxLosuj.Enabled  = true;
                groupBoxGra.Enabled    = false;
                buttonHistoria.Enabled = false;
                buttonPrzerwij.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        private void ButtonWylosuj_Click(object sender, EventArgs e)
        {
            try
            {
                int zakresOd = int.Parse(textBoxZakresOd.Text);
                int zakresDo = int.Parse(textBoxZakresDo.Text);
                if (zakresOd >= zakresDo)
                {
                    throw new ArgumentOutOfRangeException();
                }
                gra = new Gra(zakresOd, zakresDo);
            }
            catch (FormatException)
            {
                labelError.Text      = "Błąd! Wprowadziłeś błędne znaki!";
                labelError.ForeColor = Color.Red;
                labelError.Visible   = true;
                return;
            }
            catch (ArgumentOutOfRangeException)
            {
                labelError.Text      = "Błąd! Podałeś zły zakres!";
                labelError.ForeColor = Color.Red;
                labelError.Visible   = true;
                return;
            }

            labelError.Visible = false;

            groupBoxOdgadnij.Visible  = true;
            groupBoxLosowanie.Visible = false;
            buttonNowaGra.Text        = "Od nowa";
            buttonHistoria.Visible    = true;
        }
Ejemplo n.º 3
0
        public void Rozgrywka()
        {
            widok.CzyscEkran();
            // ToDo: obsługa zakresu do losowania
            gra = new Gra(1, 100);
            do
            {
                int propozycja;
                try
                {
                    propozycja = widok.WczytajLiczbe();
                }
                catch (PrzerwaneWprowadzanieException)
                {
                    gra.Poddaj();
                    break;
                }

                switch (gra.Ocena(propozycja))
                {
                case Gra.Odpowiedz.ZaDuzo:
                    widok.WypiszKomunikatZaDuzo(); break;

                case Gra.Odpowiedz.ZaMalo:
                    widok.WypiszKomunikatZaMalo(); break;

                case Gra.Odpowiedz.Trafiony:
                    widok.WypiszKomunikatTrafiony(); break;
                }
            }while (gra.StatusGry == Gra.Status.Trwa);
            // wypisz statystyki gry
            // wypisz historię
        }
 public void Uruchom()
 {
     widok.OpisGry();
     if (WczytajPoprzedniaGre(out Gra wczytanaGra))
     {
         //widok.WczytajPropozycje();
         if (widok.ChceszKontynuowac("Wczytac poprzednia gre? (t/n)"))
         {
             gra = wczytanaGra;
             if (gra.Wznow())
             {
                 UruchomRozgrywke();
             }
             else
             {
                 Console.WriteLine("Gra skonczona.");
             }
         }
         else
         {
             UsunPoprzedniaGre();
         }
     }
     while (widok.ChceszKontynuowac("Czy chcesz kontynuować aplikację (t/n)? "))
     {
         UstawZakresDoLosowania();
         gra = new Gra(MinZakres, MaxZakres);
         UruchomRozgrywke();
     }
 }
Ejemplo n.º 5
0
        private void buttonLosuj_Click(object sender, EventArgs e)
        {
            //wczytaj zakres do losowania
            int a = 0, b = 0;

            try
            {
                a = int.Parse(textBoxOd.Text);
                b = int.Parse(textBoxDo.Text);

                //uwtórz grę

                g = new Gra(a, b);
                textBoxOd.Enabled   = false;
                textBoxDo.Enabled   = false;
                buttonLosuj.Enabled = false;

                //start stopera
                startTime       = DateTime.Now;
                timer1.Tick    += (s, ev) => { czas.Text = String.Format("{0:00}", (DateTime.Now - startTime).ToString()); };
                startTime       = DateTime.Now;
                timer1.Interval = 100;
                timer1.Start();

                gBLosowanie.Visible = true;
            }
            catch (FormatException)
            {
                MessageBox.Show("Podaj zakres.");
            }
        }
Ejemplo n.º 6
0
            public static Gra createOperate(string Gra)

            {
                Gra oper = new Gra();

                switch (Gra)

                {
                case "Tri":

                    oper = new Tri();

                    break;

                case "Rec":

                    oper = new Rec();

                    break;

                case "Squ":

                    oper = new Squ();

                    break;

                case "Cir":

                    oper = new Cir();

                    break;
                }

                return(oper);
            }
Ejemplo n.º 7
0
 private void bpomoc_Click(object sender, EventArgs e)
 {
     Menu.Hide();
     Gra.Hide();
     Poziomy.Hide();
     Pomoc.Show();
 }
Ejemplo n.º 8
0
        private void buttonLosuj_Click(object sender, EventArgs e)
        {
            int a, b;


            if (Int32.TryParse(textBoxZakresOd.Text, out a) && Int32.TryParse(textBoxZakresDo.Text, out b))
            {
                g = new Gra(a, b);

                buttonLosuj.Enabled     = false;
                textBoxZakresOd.Enabled = false;
                textBoxZakresDo.Enabled = false;
                labelStan.Text          = "Wylosowano! Odgadnij!";
                start = DateTime.Now;
                groupBoxGra.Visible    = true;
                buttonPrzerwij.Enabled = true;
                textBoxStrzal.Enabled  = true;
                textBoxStrzal.Text     = "";
                labelKomunikat.Text    = "";

                /*aTimer = new System.Timers.Timer(1000);
                 * aTimer.Elapsed += OnTimedEvent;
                 * aTimer.AutoReset = true;
                 * aTimer.Enabled = true;*/

                // pokazać następne elementy formularza
                // przycisk przerwij/poddaj
            }
        }
Ejemplo n.º 9
0
 private void bcofnij_Click(object sender, EventArgs e)
 {
     Gra.Hide();
     Poziomy.Hide();
     Pomoc.Hide();
     Menu.Show();
 }
Ejemplo n.º 10
0
        public void TestMethod_Constructor_LosowanieOK(int a, int b)
        {
            var g = new Gra(a, b);

            Assert.AreEqual(Math.Min(a, b), g.zakresOd);
            Assert.AreEqual(Math.MaxMin(a, b), g.zakresDo);
        }
Ejemplo n.º 11
0
        public KontrolerCLI()
        {
            gra = new Gra();


            widok = new WidokCLI(this);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Gra w wisielca");

            Gra g = new Gra(); // zosta³ utworzony obiekt i wylosowane s³owo do odgadniecia

            Console.WriteLine(g.AktualnyWzorzec);
            Console.WriteLine(g.AktualnyWzorzec);
            Console.WriteLine(g.StanGry);
            // czy jest litera k
            Console.WriteLine("Czy jest k?");
            g.CzyJest('k');
            Console.WriteLine(g.StanGry);
            Console.WriteLine(g.AktualnyWzorzec);



            g.CzyJest('m');
            Console.WriteLine("Czy jest m?");
            Console.WriteLine(g.StanGry);
            Console.WriteLine(g.AktualnyWzorzec);

            Console.ReadKey();
            // przygotuj obrazki na jutro 50 x 50 pixeli format jpg
        }
Ejemplo n.º 13
0
 public void BinarySerialize(Gra gra)
 {
     using (var stream = new FileStream("zapis.save", FileMode.Create, FileAccess.Write))
     {
         formatter.Serialize(stream, gra);
     }
 }
Ejemplo n.º 14
0
        private void buttonWylosuj_Click(object sender, EventArgs e)
        {
            int a = int.Parse(textBoxZakresOd.Text);
            int b = int.Parse(textBoxZakresDo.Text);

            g = new Gra(a, b);
        }
 private bool WczytajPoprzedniaGre(out Gra poprzedniaGra)
 {
     poprzedniaGra = null;
     if (File.Exists(_plik))
     {
         bool flag = false;
         using (Stream s = new FileStream(_plik, FileMode.Open, FileAccess.Read, FileShare.None))
             using (MemoryStream mS = new MemoryStream())
             {
                 try
                 {
                     DataContractSerializer dcs = new DataContractSerializer(typeof(Gra));
                     var temp = OdszyfrujPlik(s);
                     temp.Save(mS);
                     mS.Position   = 0;
                     poprzedniaGra = (Gra)dcs.ReadObject(mS);
                     flag          = true;
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e.Message);
                     Console.WriteLine("Nie wczytano");
                 }
             }
         return(flag);
     }
     return(false);
 }
Ejemplo n.º 16
0
        private void buttonLosuj_Click(object sender, EventArgs e)
        {
            //try-catch ...

            try
            {
                var a = int.Parse(textBoxOd.Text);
                var b = int.Parse(textBoxDo.Text);

                g = new Gra(a, b);

                buttonLosuj.Enabled = false;
                textBoxOd.Enabled   = textBoxDo.Enabled = false;
                groupBox2.Visible   = true;
            }
            catch
            {
                string            message = "Czy chcesz spróbować ponownie?";
                string            caption = "Wystąpił błąd.";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;
                result = MessageBox.Show(message, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.No)
                {
                    this.Close();
                }
            }
        }
Ejemplo n.º 17
0
 private void button1vsPC_Click(object sender, EventArgs e)
 {
     if (gra != null)
     {
         gra = null;
     }
     gra = new Gra(false, "Gracz vs PC", this);
 }
Ejemplo n.º 18
0
 private void button1vs1_Click(object sender, EventArgs e)
 {
     if (gra != null)
     {
         gra = null;
     }
     gra = new Gra(true, "Gracz vs Gracz", this);
 }
Ejemplo n.º 19
0
        public ActionResult DeleteConfirmed(int id)
        {
            Gra gra = db.Gry.Find(id);

            db.Gry.Remove(gra);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 20
0
        private void buttonWylosuj_Click(object sender, EventArgs e)
        {
            // try-catch
            int zakresOd = int.Parse(textBoxZakresOd.Text);
            int zakresDo = int.Parse(textBoxZakresDo.Text);

            g = new Gra(zakresOd, zakresDo);
        }
Ejemplo n.º 21
0
        public void TestMethod_Ocena_LosowanieOK()
        {
            var g = new Gra(2, 10);

            var odp = g.Ocena(1);

            Assert.IsTrue(odp == Gra.Odp.ZaMalo);
        }
Ejemplo n.º 22
0
        private void buttonWylosuj_Click(object sender, EventArgs e)
        {
            int max = int.Parse(textBoxMaxZakres.Text);
            int min = int.Parse(textBoxMinZakres.Text);

            gra = new Gra(min, max);
            groupBox1.Enabled = false;
        }
Ejemplo n.º 23
0
        public void TestMethod_DefaultConstructor_Losowanie()
        {
            var g = new Gra();

            Assert.AreEqual(1, g.zakresOd);
            Assert.AreEqual(100, g.zakresDo);

            Assert.IsTrue(g.zakresOd <= g.wylosowana && g.wylosowana <= g.wylosowanaDo);
        }
 public void ZakonczGre()
 {
     ZapiszGre();
     gra = null;
     widok.CzyscEkran();
     Console.WriteLine("Gra zakonczona.");
     widok = null;
     System.Environment.Exit(0);
 }
Ejemplo n.º 25
0
 public Main()
 {
     PrepareLevels();
     InitializeComponent();
     Gra.Hide();
     Poziomy.Hide();
     Pomoc.Hide();
     Menu.Show();
 }
Ejemplo n.º 26
0
        private void ButtonLosowanie_Click(object sender, EventArgs e)
        {
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox2.Text);

            g = new Gra(a, b);
            labelKomunikat1.Text        = $"Wylosowano liczbę od {a} do {b}";
            groupBox1.Enabled           = false;
            groupBox2Propozycja.Visible = true;
        }
Ejemplo n.º 27
0
 public ActionResult Edit([Bind(Include = "GraID,Nazwa,Gatunek,Platforma,Producent,RokWydania,Ocena,Opis")] Gra gra)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gra).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gra));
 }
Ejemplo n.º 28
0
 public void ZakonczGre()
 {
     //np. zapisuje stan gry na dysku w celu późniejszego załadowania
     //albo dopisuje wynik do Top Score
     //sprząta pamięć
     gra = null;
     widok.CzyscEkran(); //komunikat o końcu gry
     widok = null;
     System.Environment.Exit(0);
 }
Ejemplo n.º 29
0
        public void Losuj_Zakres_OK(int a, int b)
        {
            // Arrange-Act-Assert
            int x = a;
            int y = b;

            int los = Gra.Losuj(x, y);

            Assert.IsTrue(los >= Math.Min(x, y) && los <= Math.Max(x, y));
        }
Ejemplo n.º 30
0
        private void buttonWylosuj_Click(object sender, EventArgs e)
        {
            int a = int.Parse(textBoxOd.Text);
            int b = int.Parse(textBoxDo.Text);

            g = new Gra(a, b);
            labelKomunikat.Text       = $"Wylosowano liczbę od {a} do {b}";
            groupBoxLosiwanie.Enabled = false;
            groupBoxOdpowiedz.Visible = true;
        }