public void start_round(object sender, int tmp_click_counter) { MOVE move = new MOVE(); Button tmp_button2 = sender as Button; click_table[1] = tmp_button2; click_counter = tmp_click_counter; string player_1_or_2 = click_table[0].Content.ToString(); Thickness tmp_margin1 = WARCAB.click_table[0].Margin; int i_position = int.Parse(click_table[0].Name.Substring(7, 1));// i,j- actual positon of pawn int j_position = int.Parse(click_table[0].Name.Substring(8, 1)); int i_position_target = int.Parse(click_table[1].Name.Substring(7, 1)); int j_position_target = int.Parse(click_table[1].Name.Substring(8, 1)); if ((move.check_possibilities(i_position, j_position, i_position_target, j_position_target)) == false) //checking possibility to move { MessageBox.Show("Zły ruch"); //message if not } else if ( ((click_table[0].Content.ToString() != "11") && (click_table[0].Content.ToString() != "22")) && (move.fight(player_1_or_2, i_position, j_position, i_position_target, j_position_target) == true) ) //checking possibility to make a pawn { swap(tmp_margin1, i_position, j_position, i_position_target, j_position_target); //function to swap two pawns } else if ((click_table[0].Content.ToString() == "11") || (click_table[0].Content.ToString() == "22")) //if player 1 or 2 queen's move { int value_to_target = Math.Abs(i_position_target - i_position); if ((i_position == i_position_target) || (j_position == j_position_target)) { MessageBox.Show("Pojebało Cie?"); } else if (value_to_target == 2) { move.fight(player_1_or_2, i_position, j_position, i_position_target, j_position_target); swap(tmp_margin1, i_position, j_position, i_position_target, j_position_target); } else { move.queen_multi_move(value_to_target, i_position, j_position, i_position_target, j_position_target); swap(tmp_margin1, i_position, j_position, i_position_target, j_position_target); } click_counter = 0; } else//if move is possible, but not making pawn { if ((move.find_neighbor(0, player_1_or_2, i_position, j_position, i_position_target, j_position_target) == true) && //looking for pawn opponent && zabezpieczenie przed przeskokiem o dwie pozycje (move.empty_move(player_1_or_2, i_position, j_position, (i_position_target), (j_position_target)) == true)) { swap(tmp_margin1, i_position, j_position, i_position_target, j_position_target); } else//empty move { if (move.empty_move(player_1_or_2, i_position, j_position, i_position_target, j_position_target) == true)//zabezpieczenie rzed robieniem kroku w tył { swap(tmp_margin1, i_position, j_position, i_position_target, j_position_target);//i robie pusty ruch } else { MessageBox.Show("Zly ruch"); } } } move.queen_possibility(); }
public bool fight(string player_1_or_2, int i_position, int j_position, int i_position_target, int j_position_target)// function for checking possibility to make pawn { bool fight = false; MOVE move = new MOVE(); if ((i_position - 2 >= 0) && (j_position + 2 <= 7))//right up { if ( ((move.find_neighbor(1, player_1_or_2, i_position, j_position, i_position - 1, j_position + 1) == true) && (move.find_neighbor(0, player_1_or_2, i_position - 2, j_position + 2, i_position - 1, j_position + 1) == true) && ((i_position - 2 == i_position_target) && (j_position + 2 == j_position_target))) && (ROUND.round_table[i_position - 1, j_position + 1].Content.ToString() != "0") ) { if (WARCAB.click_table[0].Content.ToString() == ROUND.round_table[i_position - 1, j_position + 1].Content.ToString()) { fight = false; } else { fight = true; grid.Children.Remove(ROUND.round_table[i_position - 1, j_position + 1]); ROUND.round_table[i_position - 1, j_position + 1] = warcab.create_warcab(i_position - 1, j_position + 1, 0); grid.Children.Add(ROUND.round_table[i_position - 1, j_position + 1]); } } } if ((i_position + 2 <= 7) && (j_position + 2 <= 7))//right down { if ( ((move.find_neighbor(1, player_1_or_2, i_position, j_position, i_position + 1, j_position + 1) == true) && (move.find_neighbor(0, player_1_or_2, i_position + 2, j_position + 2, i_position + 1, j_position + 1) == true) && ((i_position + 2 == i_position_target) && (j_position + 2 == j_position_target))) && (ROUND.round_table[i_position + 1, j_position + 1].Content.ToString() != "0") ) { if (WARCAB.click_table[0].Content.ToString() == ROUND.round_table[i_position + 1, j_position + 1].Content.ToString()) { fight = false; } else { fight = true; grid.Children.Remove(ROUND.round_table[i_position + 1, j_position + 1]); ROUND.round_table[i_position + 1, j_position + 1] = warcab.create_warcab(i_position + 1, j_position + 1, 0); grid.Children.Add(ROUND.round_table[i_position + 1, j_position + 1]); } } } if ((i_position - 2 <= 7) && (j_position - 2 <= 7))//left up { if ( ((move.find_neighbor(1, player_1_or_2, i_position, j_position, i_position - 1, j_position - 1) == true) && (move.find_neighbor(0, player_1_or_2, i_position - 2, j_position - 2, i_position - 1, j_position - 1) == true) && ((i_position - 2 == i_position_target) && (j_position - 2 == j_position_target))) && (ROUND.round_table[i_position - 1, j_position - 1].Content.ToString() != "0") ) { if (WARCAB.click_table[0].Content.ToString() == ROUND.round_table[i_position - 1, j_position - 1].Content.ToString()) { fight = false; } else { fight = true; grid.Children.Remove(ROUND.round_table[i_position - 1, j_position - 1]); ROUND.round_table[i_position - 1, j_position - 1] = warcab.create_warcab(i_position - 1, j_position - 1, 0); grid.Children.Add(ROUND.round_table[i_position - 1, j_position - 1]); } } } if ((i_position + 2 <= 7) && (j_position - 2 <= 7))//left up { if ( ((move.find_neighbor(1, player_1_or_2, i_position, j_position, i_position + 1, j_position - 1) == true) && (move.find_neighbor(0, player_1_or_2, i_position + 2, j_position - 2, i_position + 1, j_position - 1) == true) && ((i_position + 2 == i_position_target) && (j_position - 2 == j_position_target))) && (ROUND.round_table[i_position + 1, j_position - 1].Content.ToString() != "0") ) { if (WARCAB.click_table[0].Content.ToString() == ROUND.round_table[i_position + 1, j_position - 1].Content.ToString()) { fight = false; } else { fight = true; grid.Children.Remove(ROUND.round_table[i_position + 1, j_position - 1]); ROUND.round_table[i_position + 1, j_position - 1] = warcab.create_warcab(i_position + 1, j_position - 1, 0); grid.Children.Add(ROUND.round_table[i_position + 1, j_position - 1]); } } } return(fight); }