public void setCurrentColor(cell_type type) { selected_color = cell_colors[(int)type]; current_selection_box.BackColor = cell_colors[(int)type]; }
private void GenerateWalls() { int current_index = 0; foreach (PictureBox cell in cells) { if (cell.BackColor == Color.Blue) { current_index = cells.IndexOf(cell); int a_x = current_index % current_width; int a_y = (int)Math.Ceiling((double)(current_index / current_width)); if (outOfBoundCells(a_x, a_y)) { PictureBox cell_left = cells[getIndexAt(a_x - 1, a_y)]; PictureBox cell_right = cells[getIndexAt(a_x + 1, a_y)]; PictureBox cell_top = cells[getIndexAt(a_x, a_y - 1)]; PictureBox cell_bottom = cells[getIndexAt(a_x, a_y + 1)]; cell_type code = getTileCode(cell_left, cell_right, cell_top, cell_bottom); switch (code) { // walls case (cell_type.top): if (cell_top.BackColor == cell_colors[(int)cell_type.left]) { cell_top.BackColor = cell_colors[(int)cell_type.bottom_right_inner_corner]; } else if (cell_top.BackColor == cell_colors[(int)cell_type.right]) { cell_top.BackColor = cell_colors[(int)cell_type.bottom_left_inner_corner]; } else if (cell_top.BackColor == cell_colors[(int)cell_type.empty]) { cell_top.BackColor = cell_colors[(int)cell_type.top]; } break; case (cell_type.right): if (cell_right.BackColor == cell_colors[(int)cell_type.top]) { cell_right.BackColor = cell_colors[(int)cell_type.bottom_left_inner_corner]; } else if (cell_right.BackColor == cell_colors[(int)cell_type.bottom]) { cell_right.BackColor = cell_colors[(int)cell_type.top_left_inner_corner]; } else if (cell_right.BackColor == cell_colors[(int)cell_type.empty]) { cell_right.BackColor = cell_colors[(int)cell_type.right]; } break; case (cell_type.bottom): if (cell_bottom.BackColor == cell_colors[(int)cell_type.left]) { cell_bottom.BackColor = cell_colors[(int)cell_type.top_right_inner_corner]; } else if (cell_bottom.BackColor == cell_colors[(int)cell_type.right]) { cell_bottom.BackColor = cell_colors[(int)cell_type.top_left_inner_corner]; } else if (cell_bottom.BackColor == cell_colors[(int)cell_type.empty]) { cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; } break; case (cell_type.left): if (cell_left.BackColor == cell_colors[(int)cell_type.top]) { cell_right.BackColor = cell_colors[(int)cell_type.bottom_right_inner_corner]; } else if (cell_left.BackColor == cell_colors[(int)cell_type.bottom]) { cell_left.BackColor = cell_colors[(int)cell_type.top_right_inner_corner]; } else if (cell_left.BackColor == cell_colors[(int)cell_type.empty]) { cell_left.BackColor = cell_colors[(int)cell_type.left]; } break; // outter corners case (cell_type.top_right_outter_corner): cells[getIndexAt(a_x + 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_right_outter_corner]; cell_top.BackColor = cell_colors[(int)cell_type.top]; cell_right.BackColor = cell_colors[(int)cell_type.right]; break; case (cell_type.bottom_right_outter_corner): cells[getIndexAt(a_x + 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_right_outter_corner]; cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; cell_right.BackColor = cell_colors[(int)cell_type.right]; break; case (cell_type.bottom_left_outter_corner): cells[getIndexAt(a_x - 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_left_outter_corner]; cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; cell_left.BackColor = cell_colors[(int)cell_type.left]; break; case (cell_type.top_left_outter_corner): cells[getIndexAt(a_x - 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_left_outter_corner]; cell_top.BackColor = cell_colors[(int)cell_type.top]; cell_left.BackColor = cell_colors[(int)cell_type.left]; break; case (cell_type.top_and_bottom): if (cell_top.BackColor == cell_colors[(int)cell_type.left]) { cell_top.BackColor = cell_colors[(int)cell_type.bottom_right_inner_corner]; } else if (cell_top.BackColor == cell_colors[(int)cell_type.right]) { cell_top.BackColor = cell_colors[(int)cell_type.bottom_left_inner_corner]; } else if (cell_top.BackColor == cell_colors[(int)cell_type.empty]) { cell_top.BackColor = cell_colors[(int)cell_type.top]; } if (cell_bottom.BackColor == cell_colors[(int)cell_type.left]) { cell_bottom.BackColor = cell_colors[(int)cell_type.top_right_inner_corner]; } else if (cell_bottom.BackColor == cell_colors[(int)cell_type.right]) { cell_bottom.BackColor = cell_colors[(int)cell_type.top_left_inner_corner]; } else if (cell_bottom.BackColor == cell_colors[(int)cell_type.empty]) { cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; } break; case (cell_type.left_and_right): if (cell_left.BackColor == cell_colors[(int)cell_type.top]) { cell_right.BackColor = cell_colors[(int)cell_type.bottom_right_inner_corner]; } else if (cell_left.BackColor == cell_colors[(int)cell_type.bottom]) { cell_left.BackColor = cell_colors[(int)cell_type.top_right_inner_corner]; } else if (cell_left.BackColor == cell_colors[(int)cell_type.empty]) { cell_left.BackColor = cell_colors[(int)cell_type.left]; } if (cell_right.BackColor == cell_colors[(int)cell_type.top]) { cell_right.BackColor = cell_colors[(int)cell_type.bottom_left_inner_corner]; } else if (cell_right.BackColor == cell_colors[(int)cell_type.bottom]) { cell_right.BackColor = cell_colors[(int)cell_type.top_left_inner_corner]; } else if (cell_right.BackColor == cell_colors[(int)cell_type.empty]) { cell_right.BackColor = cell_colors[(int)cell_type.right]; } break; case (cell_type.top_cul): cell_top.BackColor = cell_colors[(int)cell_type.top]; cell_right.BackColor = cell_colors[(int)cell_type.right]; cell_left.BackColor = cell_colors[(int)cell_type.left]; cells[getIndexAt(a_x + 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_right_outter_corner]; cells[getIndexAt(a_x - 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_left_outter_corner]; break; case (cell_type.right_cul): cell_top.BackColor = cell_colors[(int)cell_type.top]; cell_right.BackColor = cell_colors[(int)cell_type.right]; cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; cells[getIndexAt(a_x + 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_right_outter_corner]; cells[getIndexAt(a_x + 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_right_outter_corner]; break; case (cell_type.bottom_cul): cell_left.BackColor = cell_colors[(int)cell_type.left]; cell_right.BackColor = cell_colors[(int)cell_type.right]; cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; cells[getIndexAt(a_x + 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_right_outter_corner]; cells[getIndexAt(a_x - 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_left_outter_corner]; break; case (cell_type.left_cul): cell_top.BackColor = cell_colors[(int)cell_type.top]; cell_left.BackColor = cell_colors[(int)cell_type.left]; cell_bottom.BackColor = cell_colors[(int)cell_type.bottom]; cells[getIndexAt(a_x - 1, a_y - 1)].BackColor = cell_colors[(int)cell_type.top_left_outter_corner]; cells[getIndexAt(a_x - 1, a_y + 1)].BackColor = cell_colors[(int)cell_type.bottom_left_outter_corner]; break; } } } } secondPass(); backup(); }