class LoveLetterApplication::Results::ProcessKnightShowdown

Public Instance Methods

call(target_player_id:, game_board:, change_orders:) click to toggle source
# File lib/love_letter_application/results/process_knight_showdown.rb, line 20
def call(target_player_id:, game_board:, change_orders:)
  current_player_id = game_board.current_player_id.to_i
  result = get_result(current_player_id, target_player_id, game_board)
  @@execute[result].(self, current_player_id, target_player_id, game_board, change_orders)
end

Private Instance Methods

do_draw(current_player_id, target_player_id, game_board, change_orders) click to toggle source
# File lib/love_letter_application/results/process_knight_showdown.rb, line 34
def do_draw(current_player_id, target_player_id, game_board, change_orders)
  process_next_player_turn.(
    game_board: game_board,
    change_orders: change_orders.push(knight_drawn_node))
end
do_victory(winning_player_id, losing_player_id, game_board, change_orders) click to toggle source
# File lib/love_letter_application/results/process_knight_showdown.rb, line 40
def do_victory(winning_player_id, losing_player_id, game_board, change_orders)
  eliminate_player.(
    target_player_id: losing_player_id,
    game_board: game_board,
    change_orders: change_orders.push(get_knight_victory_node.(
      winning_player_id: winning_player_id,
      losing_player_id: losing_player_id)))
end
get_result(current_player_id, target_player_id, game_board) click to toggle source
# File lib/love_letter_application/results/process_knight_showdown.rb, line 27
def get_result(current_player_id, target_player_id, game_board)
  current_player = game_board.players.find{|player| player.id.to_i.eql?(current_player_id)}
  target_player = game_board.players.find{|player| player.id.to_i.eql?(target_player_id)}
  #<=> returns -1, 0, or 1.  I add 1 at the end so I can use the result as an array index
  (current_player.hand.first.rank.to_i <=> target_player.hand.first.rank.to_i) + 1
end