Sha256: 3198f68dfb297b359d815fee58bc898cf1e3cd4a60bda4005d7df697a13cc820

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "aasm"

module CribbageGame
  class Fsm
    include AASM

    aasm do
      state :cutting_for_deal, initial: true
      state :flipping_top_card
      state :discarding, :dealing, :playing
      state :scoring_opponent_hand, :scoring_dealer_hand, :scoring_dealer_crib
      state :game_over

      event :deal do
        transitions from: :cutting_for_deal, to: :dealing
        transitions from: :scoring_dealer_crib, to: :dealing
      end

      event :discard do
        transitions from: :dealing, to: :discarding
      end

      event :flip_top_card do
        transitions from: :discarding, to: :flipping_top_card
      end

      event :play do
        transitions from: :flipping_top_card, to: :playing
      end

      event :score do
        transitions from: :playing, to: :scoring_opponent_hand
        transitions from: :scoring_opponent_hand, to: :scoring_dealer_hand
        transitions from: :scoring_dealer_hand, to: :scoring_dealer_crib
      end

      event :declare_winner do
        transitions to: :game_over
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cribbage_game-0.1.0 lib/cribbage_game/fsm.rb