Beispiel #1
0
        } // ako izleze nadvor od igrata dodeka igrata e vo tek.

        private void saveGameDialog()
        {
            startedgame = false;
            RefreshInfoTimer.Stop();
            stopwatch.Stop();
            igra.ts += stopwatch.Elapsed;
            stopwatch.Reset();
            IFormatter     ifrmt = new BinaryFormatter();
            SaveFileDialog sfd   = new SaveFileDialog
            {
                Title  = "Save your game!",
                Filter = "Maze File (.maze)|*.maze"
            };

            try
            {
                if ((sfd.ShowDialog()) == DialogResult.OK)
                {
                    filename = sfd.FileName;
                }
                else
                {
                    throw new Exception("Nevalidni argumenti za save opcijata..");
                }
                FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
                ifrmt.Serialize(fs, igra);
                fs.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Imavme nekakov error. Ve molime predajte ja porakata do nadleznite: " + e.Message);
            }
            StopGame();
        } //save game as .maze file
Beispiel #2
0
        } ///ako uspesno vleze vo finish labelata.

        private void StartGame()
        {
            StopGame();
            status = "Running game..";
            moveCursorToStart();
            stopwatch.Start(); //START STOPERICA
            updateInformation();
            startedgame    = true;
            panel1.Enabled = true;
            hitblock       = false;
            disablePanel2Controls();
            RefreshInfoTimer.Start();
        } // Resetira potrebni textboxovi i timeri/stopwatches i pocnuva.
Beispiel #3
0
        } // Resetira potrebni textboxovi i timeri/stopwatches i pocnuva.

        private void StartGame(Game ig)
        {
            StopGame();
            igra   = ig;
            status = "Running game..";
            moveCursorToStart();
            stopwatch.Start(); //START STOPERICa
            updateInformation();
            startedgame    = true;
            panel1.Enabled = true;
            disablePanel2Controls();

            RefreshInfoTimer.Start();
        } // isto so startgame samo tuka konstruktor prima Game objekt , go koristime pri deserializacija
Beispiel #4
0
        } //save game as .maze file

        public void openGameDialog()
        {
            StopGame();
            RefreshInfoTimer.Stop();
            IFormatter     ifrmt = new BinaryFormatter();
            OpenFileDialog ofd   = new OpenFileDialog
            {
                Title  = "Open your game!",
                Filter = "Maze File (.maze)|*.maze"
            };

            try
            {
                if ((ofd.ShowDialog()) == DialogResult.OK)
                {
                    filename = ofd.FileName;
                }
                FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);

                this.igra = (Game)ifrmt.Deserialize(fs);
                fs.Close();


                StartGame(igra);
                startedgame = true;
                updateInformation();
                listBox1.Items.Clear();
                listBox1.Items.Add(String.Format("[" + DateTime.Now.ToString() + "]: " + "You loaded saved game {0} .", filename));
                listBox1.Items.Add(String.Format("X:{0} Y:{1} HP:{2} Elapsed time:{3} Hits:{4}", igra.snake.position.X.ToString(), igra.snake.position.Y.ToString(), igra.snake.hp.ToString(), igra.getTimespan(stopwatch).ToString("mm\\:ss"), igra.hits.ToString()).ToString());
                foreach (string item in igra.eventlog.ToString().Split('\n'))
                {
                    listBox1.Items.Add(item);
                }
                listBox1.Update();
                // Locating cursor to previosly saved position
                Point startingPoint = panel1.Location;
                startingPoint.Offset(igra.snake.position.X, igra.snake.position.Y);
                Cursor.Position = PointToScreen(startingPoint);
            }
            catch (Exception e)
            {
                listBox1.Items.Add("[" + DateTime.Now.ToString() + "]: " + "Error: " + e.Message);
                StopGame();
                MessageBox.Show("Imavme nekakov error. Ve molime predajte ja porakata do nadleznite: " + e.Message);
            }
        } // Open Game .maze
Beispiel #5
0
        } // Event Trigger za tastatura pritiskanje

        private void StopGame()
        {
            progressBar1.Value     = 100;
            progressBar1.BackColor = DefaultBackColor;
            textBox3.BackColor     = DefaultBackColor;
            stopwatch.Stop(); //STOPWATCH STOP
            igra.ts += stopwatch.Elapsed;
            stopwatch.Reset();
            textBox1.Text = "0";
            textBox2.Text = "0";
            textBox3.Text = "100";
            startedgame   = false;
            enablePanel2Controls();
            igra   = new Game();
            status = "Stopped...";
            RefreshInfoTimer.Stop();
            updateInformation();
        } // Ja stopira igrata(timeri/stopwatches) i update pravi na potrebnite informacii