module LoveLetterApplication::Types

Constants

Card
GameBoard
GameStateEnum
Player

Public Instance Methods

all_players_have_different_ids_and_seats(players) click to toggle source
# File lib/love_letter_application/types/game_board.rb, line 26
def all_players_have_different_ids_and_seats(players)
  id_list = []
  seat_list = []
  players.each do |player|
    if id_list.include?(player.id.to_i)
      raise Dry::Types::ConstraintError::new(
        'All players have distinct ids', players.map(&:id))
    end
    if seat_list.include?(player.seat.to_i)
      raise Dry::Types::ConstraintError::new(
        'All players have distinct seats', players.map(&:seat))
    end
    id_list.push player.id.to_i
    seat_list.push player.seat.to_i
  end
end
call(card) click to toggle source
# File lib/love_letter_application/types/card.rb, line 8
def call(card)
  @@has_card_methods.call(card)
  ::Types::Coercible::Integer.call(card.id)
  ::Types::Coercible::Integer.call(card.rank)
  ::Types::Strict::Bool.call(card.targetable?)
  card
end
verify_current_player_id_is_valid(game_board) click to toggle source
# File lib/love_letter_application/types/game_board.rb, line 43
def verify_current_player_id_is_valid(game_board)
  id_list = game_board.players.map{|player| player.id.to_i}
  if !id_list.include?(game_board.current_player_id.to_i)
    raise Dry::Types::ConstraintError::new(
      "The player id whose turn it is not in the player list (#{id_list})",
      game_board.current_player_id)
  end
end