Exemplo n.º 1
0
        public override bool check_step(Tuple <int, int> destination, BoardClass board)
        {
            int  start  = -1;
            bool result = false;

            foreach (var step in chess_steps)
            {
                Tuple <int, int> new_cord = chess_cord;

                while (new_cord.Item1 < board.Height && new_cord.Item2 < board.Width && new_cord.Item1 > start && new_cord.Item2 > start)
                {
                    new_cord = sum_tuples(step, new_cord);
                    if (new_cord.Equals(destination))
                    {
                        result = true;
                        break;
                    }
                    if (board.find_chess_by_coords(new_cord) != null)
                    {
                        break;
                    }
                }

                if (result)
                {
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        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()}");
        }
Exemplo n.º 3
0
        public override bool check_step(Tuple <int, int> destination, BoardClass board)
        {
            int              repeat   = is_started ? 1 : 2;
            bool             result   = false;
            Tuple <int, int> step_one = sum_tuples(chess_cord, attack_steps[0]);
            Tuple <int, int> step_two = sum_tuples(chess_cord, attack_steps[1]);
            bool             one      = (step_one.Equals(destination) && board.find_chess_by_coords(step_one) != null);
            bool             two      = (step_two.Equals(destination) && board.find_chess_by_coords(step_two) != null);

            if (one || two)
            {
                result = true;
            }
            foreach (var step in chess_steps)
            {
                if (result)
                {
                    break;
                }
                Tuple <int, int> new_cord = chess_cord;
                for (int i = 0; i < repeat; i++)
                {
                    new_cord = sum_tuples(step, new_cord);
                    if (board.find_chess_by_coords(new_cord) != null)
                    {
                        break;
                    }
                    if (new_cord.Equals(destination))
                    {
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }