Class: Chess::Player
- Inherits:
-
Object
- Object
- Chess::Player
- Includes:
- PlayMovesByType
- Defined in:
- lib/chess/player/player.rb
Overview
Player
Constant Summary
Constants included from Display
Instance Attribute Summary collapse
-
#selected_piece ⇒ Object
Returns the value of attribute selected_piece.
Instance Method Summary collapse
-
#change_player_turn(board) ⇒ void
change player turn.
-
#initialize ⇒ Player
constructor
A new instance of Player.
-
#select_move(board, move_pos) ⇒ void
select a move.
Methods included from PlayMovesByType
#play_move_by_type, #play_normal_move, #update_player_board_data
Methods included from PlayKingMoves
#castling_move?, #play_castling_move, #play_king_move, #play_rook_jump_move
Methods included from PlayPawnMoves
#attacking_en_passant?, #move_two_step, #pawn_is_promoting?, #pawn_two_step_move?, #play_pawn_move, #play_pawn_promotion, #remove_en_passant_from_board, #remove_enemy_en_passant_pawn, #set_board_possible_en_passant
Methods included from Display
#bg_color, #color, #display_board, #display_buttons, #king_check_dot, #move_dots, #print_board_data, #print_files, #print_piece_square, #print_square, #prompt_enter_code, #prompt_pawn_promotion_choices, #prompt_save_name, #prompt_select_save, #prompt_start_choices, #redraw_display, #square_bg_color_name, #square_string
Constructor Details
#initialize ⇒ Player
Returns a new instance of Player.
11 12 13 |
# File 'lib/chess/player/player.rb', line 11 def initialize @selected_piece = '' end |
Instance Attribute Details
#selected_piece ⇒ Object
Returns the value of attribute selected_piece.
9 10 11 |
# File 'lib/chess/player/player.rb', line 9 def selected_piece @selected_piece end |
Instance Method Details
#change_player_turn(board) ⇒ void
This method returns an undefined value.
change player turn
30 31 32 33 34 35 36 37 |
# File 'lib/chess/player/player.rb', line 30 def change_player_turn(board) current_player_color = board.current_player board.current_player = if current_player_color == 'w' 'b' else 'w' end end |
#select_move(board, move_pos) ⇒ void
This method returns an undefined value.
select a move
19 20 21 22 23 24 25 |
# File 'lib/chess/player/player.rb', line 19 def select_move(board, move_pos) if @selected_piece.valid_moves.include?(move_pos) play_move_by_type(@selected_piece, board, move_pos) else pp 'invalid move' end end |