/// <summary> /// Sets starting , target or walls fields depeding on the label. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandleButtonClicked(object sender, EventArgs e) { switch (Label.Text) { case "Please choose your starting point": this.startingField = (PositionInTheLabyrinth)sender; this.startingField.BackColor = Color.Green; Label.Text = "Please choose your targetPoint"; break; case "Please choose your targetPoint": this.targetField = (PositionInTheLabyrinth)sender; this.targetField.BackColor = Color.Red; Label.Text = "Select walls"; break; case "Select walls": this.Walls.Add((PositionInTheLabyrinth)sender); if (((PositionInTheLabyrinth)sender).BackColor == Color.White) { ((PositionInTheLabyrinth)sender).BackColor = Color.Black; } else if (((PositionInTheLabyrinth)sender).BackColor == Color.Black) { ((PositionInTheLabyrinth)sender).BackColor = Color.White; } this.FindPathButton.Visible = true; break; } }
/// <summary> /// Fills the labyrinth and shows it to the user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 30; i++) { for (int j = 0; j < 60; j++) { PositionInTheLabyrinth button = new PositionInTheLabyrinth(i, j) { Location = new Point(j * 20, i * 20), Size = new Size(20, 20), BackColor = Color.White, }; button.Click += HandleButtonClicked; this.buttons[i, j] = button; this.labyrinthPanel.Controls.Add(button); } } }