Example #1
0
 private void paint_all_moves(ChainsMas moves)
 {
     //заполнение всех ходов
     richTextBox1.Text = "";
     foreach (Chain item_chain in moves.table_s_chains)
     {
         if (richTextBox1.Text != "")
         {
             richTextBox1.Text += "|\n";
         }
         richTextBox1.Text += item_chain.ToString();
     }
     //отрисовка только доступных
     foreach (Chain item in moves.get_all_high_important_chains())
     {
         foreach (Move item_move in item.chain_s_moves)
         {
             item_move.cell_to.set_mark(true);
         }
     }
 }
Example #2
0
        private void pictureBox_Click(object sender, EventArgs e)
        {
            Cell temp = main.field_state[(int)(sender as PictureBox).Tag] as Cell;

            //режим редактирования
            if (edit_mode)
            {
                if (temp.color != edit_menu_cell.color || temp.king != edit_menu_cell.king)
                {
                    temp.color = edit_menu_cell.color;
                    temp.king  = edit_menu_cell.king;
                    temp.fill_image();
                }
            }
            else
            //игровой режим
            {
                //клик на шашке
                if (temp.color != "empty")
                {
                    bool mark = temp.marked;
                    //чистим все отметки
                    clear_all_marks();

                    //в зависимости от отметки, ставим\убираем ее
                    temp.set_mark(!mark);
                    if (temp.marked)
                    {
                        last_marked = temp;
                        //рисуем доступные ходы
                        mas = new ChainsMas();
                        calc_all_cell_moves(mas, temp, 0, main);
                        paint_all_moves(mas);
                    }
                    else
                    {
                        last_marked = null;
                    }
                }
                else
                //клик по пустому месту
                {
                    //совершение хода
                    if (last_marked != null)
                    {
                        System.Collections.ArrayList chains = mas.get_all_high_important_chains();
                        if (chains.Count > 0)
                        {
                            //поиск move
                            foreach (Chain item in chains)
                            {
                                foreach (Move item_move in item.chain_s_moves)
                                {
                                    //совершение move
                                    if (item_move.cell_to == temp)
                                    {
                                        if (!item_move.jump)
                                        {
                                            //простой ход
                                            clear_all_marks();
                                            item_move.cell_to.color = (item.chain_s_moves[0] as Move).cell_from.color;
                                            item_move.cell_to.king  = item_move.cell_from.king;
                                            item_move.cell_to.fill_image();
                                            (item.chain_s_moves[0] as Move).cell_from.color = "empty";
                                            (item.chain_s_moves[0] as Move).cell_from.king  = false;
                                            (item.chain_s_moves[0] as Move).cell_from.fill_image();
                                        }
                                        else
                                        {
                                            //прыжок со съеданием
                                            string first_color = (item.chain_s_moves[0] as Move).cell_from.color;
                                            foreach (Move internal_move in item.chain_s_moves)
                                            {
                                                clear_all_marks();

                                                internal_move.cell_to.color = first_color;
                                                internal_move.cell_to.king  = internal_move.cell_from.king;
                                                internal_move.cell_to.set_mark(false);
                                                internal_move.cell_from.color = "empty";
                                                internal_move.cell_from.king  = false;
                                                internal_move.cell_from.set_mark(false);

                                                foreach (Cell c in internal_move.eated_cells)
                                                {
                                                    c.color = "empty";
                                                    c.king  = false;
                                                    c.fill_image();
                                                }
                                                //рекурсивно, вызываем этот же метод, если ходы еще есть
                                                mas = new ChainsMas();
                                                calc_all_cell_moves(mas, temp, 0, main);
                                                System.Collections.ArrayList imp_chains = mas.get_all_high_important_chains();
                                                if (mas != null && imp_chains.Count > 0)
                                                {
                                                    internal_move.cell_to.set_mark(true);
                                                    pictureBox_Click(sender, new EventArgs());
                                                }
                                                if (internal_move == item_move)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }