lib/chess/game.rb
# Allows a player to take a turn
Allows a player to take a turn
Allows a player to take a turn
def take_turn
      puts "\n" + ("-" * 60)
      puts "#{@turn.name} (#{@turn.color}), it is your turn."
      puts @board
      output_if_checked
      from_position = player_choose_piece
      to_position = player_choose_move_piece(from_position)
      until @board.valid_move?(from_position[0], from_position[1],
                               to_position[0], to_position[1])
        puts "Not a valid move! Try another move.\n\n"
        from_position = player_choose_piece
        to_position = player_choose_move_piece(from_position)
      end
      @board.move_piece(from_position[0], from_position[1],
                        to_position[0], to_position[1])
      @turn = switch_player(@turn)
    end
def take_turn puts "\n" + ( "-" * 60 ) puts "#{@turn.name} (#{@turn.color}), it is your turn." puts @board output_if_checked from_position = player_choose_piece to_position = player_choose_move_piece ( from_position ) until @board . valid_move? ( from_position [ 0 ] , from_position [ 1 ] , to_position [ 0 ] , to_position [ 1 ] ) puts "Not a valid move! Try another move.\n\n" from_position = player_choose_piece to_position = player_choose_move_piece ( from_position ) end @board . move_piece ( from_position [ 0 ] , from_position [ 1 ] , to_position [ 0 ] , to_position [ 1 ] ) @turn = switch_player ( @turn ) end
Allows a player to take a turn
Allows a player to take a turn