public void add_chess(ChessClass chess) { if (!(Chesses.Count > (height * width))) { Chesses.Add(chess); } }
private bool is_attack_possible(ChessClass chess_attack, ChessClass second_chess) { bool result = false; if (second_chess?.ChessCode != chess_attack?.ChessCode) { result = true; } return(result); }
public void game_part() { Tuple <int, int> user_cord = get_user_cord("Input coords (or msg): "); for (int i = 0; i < board.Chesses.Count && user_cord != null; i++) { if (board.Chesses[i].GetCords.Equals(user_cord)) { ChessClass chess = board.Chesses[i]; Tuple <int, int> new_cord = get_user_cord("Input new coords: ") ?? user_cord; bool step = chess.check_step(new_cord, board) && chess.ChessCode == CurrentPlayer.ChessCode; if (step) { ChessClass second_chess = board.find_chess_by_coords(new_cord); bool possibe = is_attack_possible(chess, second_chess); if (possibe && second_chess != null) { board.Chesses.Remove(second_chess); if (second_chess is King) { gameover(second_chess); break; } chess.GetCords = new_cord; if (chess is Pawn pawn) { pawn.IsStarted = true; } CurrentPlayer = CurrentPlayer.ChessCode != 0 ? PlayerOneBlack : PlayerTwoWhite; } else if (second_chess == null) { chess.GetCords = new_cord; if (chess is Pawn pawn) { pawn.IsStarted = true; } CurrentPlayer = CurrentPlayer.ChessCode != 0 ? PlayerOneBlack : PlayerTwoWhite; } else { message_buf.Push("Allied Chess!"); } } else { message_buf.Push("This step cant exist!"); } break; } } message_buf.Push($"Move of {CurrentPlayer.ToString()}"); }
public ChessClass find_chess_by_coords(Tuple <int, int> cords) { ChessClass result = null; for (int i = 0; i < Chesses.Count; i++) { if (Chesses[i].GetCords.Equals(cords)) { result = Chesses[i]; break; } } return(result); }
public static void show_gameover_info(ChessClass chess) { Console.WriteLine(chess.get_info()); }
private void gameover(ChessClass chess) { GameStarted = false; DisplayClass.show_gameover_info(chess); }