Sha256: c8cab425784f432b6ad13ed3825cbd51f58e545e8a8718a37d0303177838b79e

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

require 'stores/store'
class App < React::Component::Base

  render(DIV) do
    puts "rendering: game_state = #{Store.game_state}"
    puts "their_id: #{Store.state.their_id}, my_id: #{Store.my_id} words: #{Store.state.word}"
    DIV { Store.message } if Store.message
    send Store.game_state # for each game_state we have a method below...
    Guesses() unless Store.my_guesses.empty?
  end

  def initializing
    SPAN { '...' }
  end

  def picking_word
    InputWord label: 'pick a five letter word', button: 'play', operation: Ops::ReadyToPlay
  end

  def waiting_for_other_player
    SPAN { "Your word is: #{Store.my_word}. Waiting for the other player to pick their word..." }
    BUTTON { 'Change Your Word' }.on(:click) { Ops::ChangeWord() }
  end

  def waiting_for_your_guess
    InputWord label: 'guess a word', button: 'guess', operation: Ops::Guess
  end

  def waiting_for_their_guess
    SPAN { 'waiting for the other player to guess...' }
  end

  def waiting_for_a_clue_from_them
    SPAN { 'waiting for the other player to give you the number correct...' }
  end

  def waiting_for_a_clue_from_you
    SPAN { "Your word is '#{Store.my_word}'." }
    SELECT do
      OPTION(selected: true,  disabled: true) { "How many correct in '#{Store.current_guess}'?" }
      (0..5).each { |count| OPTION(value: count) { count.to_s } }
      OPTION(value: :win) { "#{Store.current_guess} is correct!"}
    end.on(:change) do |e|
      if e.target.value == :win
        Ops::YouWin()
      else
        Ops::Clue their_word: Store.current_guess, my_word: Store.my_word, correct: e.target.value
      end
    end
  end

  def you_win
    DIV { "YOU WIN :-)" }
    play_again
  end

  def they_win
    DIV { "they won :-("}
    play_again
  end

  def play_again
    BUTTON { 'Play Again!' }.on(:click) { Ops::PlayAgain() }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyper-operation-0.5.4 examples/five-letter-word-game/app/hyperloop/components/app.rb
hyper-operation-0.5.3 examples/five-letter-word-game/app/hyperloop/components/app.rb
hyper-operation-0.5.2 examples/five-letter-word-game/app/hyperloop/components/app.rb
hyper-operation-0.5.1 examples/five-letter-word-game/app/hyperloop/components/app.rb
hyper-operation-0.5.0 examples/five-letter-word-game/app/hyperloop/components/app.rb