public void Reset() { counter = 30; label2.ForeColor = Color.Black; lives = 3; MyTimer = null; lastPoint = Point.Empty; isMouseDown = new Boolean(); isKeyPressed = new Boolean(); labirint = null; cellSize = 0; x = 0; y = 0; xEnd = 0; yEnd = 0; preyX = -1; preyY = -1; startingPoint = Point.Empty; endingPoint = Point.Empty; img = null; hintOn = false; pictureBox1.Controls.Clear(); pc2 = new PictureBox(); pc2.BackColor = Color.Transparent; pc2.Parent = pictureBox1; pc2.Size = new Size(pictureBox1.Size.Width, pictureBox1.Size.Height); pc2.MouseDown += new MouseEventHandler(PictureBox1_MouseDown); pc2.MouseUp += new MouseEventHandler(PictureBox1_MouseUp); pc2.MouseMove += new MouseEventHandler(PictureBox1_MouseMove); pictureBox1.Image = null; pictureBox1.BorderStyle = BorderStyle.FixedSingle; }
private void button1_Click(object sender, EventArgs e) { label2.ForeColor = Color.Black; label3.Text = "Životi: 3"; preyX = -1; preyY = -1; if (MyTimer != null) { MyTimer.Stop(); MyTimer.Tick -= MyTimer_Tick; } pictureBox1.BorderStyle = BorderStyle.None; int level = Int32.Parse(comboBox1.SelectedItem.ToString()); int gridSize = level * 5; labirint = new ColoredPathGrid(gridSize, gridSize); cellSize = (pictureBox1.Size.Width - 1) / gridSize; startingPoint = pictureBox1.Location; startingPoint.Offset(cellSize / 2, cellSize / 2); labirint.Distances = labirint[0, 0].Distances; xEnd = labirint._farthest.Column; yEnd = labirint._farthest.Row; endingPoint = new Point(labirint._farthest.Column * cellSize + cellSize / 2, labirint._farthest.Row * cellSize + cellSize / 2); x = 0; y = 0; isKeyPressed = false; if (radioButton1.Checked) { Random random = new Random(); preyX = random.Next(0, gridSize); preyY = random.Next(0, gridSize); while ((preyX == 0 && preyY == 0) || (preyX == xEnd && preyY == yEnd)) { preyX = random.Next(0, gridSize); preyY = random.Next(0, gridSize); } } if (radioButton3.Checked) { counter = level * 15; if (counter >= 60) { int mins = (int)(counter / 60); int secs = counter - mins * 60; String text = String.Concat("0", mins.ToString()); text = String.Concat(text, ":"); text = String.Concat(text, secs); label2.Text = text; } else { String text = String.Concat("00:", counter); label2.Text = text; } MyTimer = new Timer(); MyTimer.Interval = (1000); MyTimer.Tick += new EventHandler(MyTimer_Tick); MyTimer.Start(); } else { label2.Text = "--:--"; } refreshPicture(); Button hintButton = new Button(); hintButton.Text = "&Hint"; hintButton.Location = new Point(23, 420); hintButton.Click += new EventHandler(Hint_Click); Controls.Add(hintButton); }