Sha256: ac6438761b5256bf5a269ac63010df86af9201c38b4fd62088dee5cc17a7a8c5

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

module Githug
  class Game

    attr_accessor :profile

    def initialize
      @profile = Profile.load
    end

    def play_level
      solve = true
      if profile.level.nil?
        UI.puts("Welcome to Githug")
        solve = false
        level_bump
      else
        level = Level.load(profile.level)
        if solve && level
          if level.solve
            UI.success "Congratulations, you have solved the level"
            level_bump
          else
            UI.error "Sorry, this solution is not quite right!"
            profile.current_attempts += 1
            profile.save

            if (profile.current_attempts > 2 && profile.current_attempts % 3 == 0)
              UI.error "Don't forget you can type `githug hint` for a hint and `githug reset` to reset the current level"
            end

            UI.puts level.full_description
          end
        end
      end
    end

    def test_level(level, errors = nil)
      UI.puts level.full_description
      method = :solve
      method = :test if errors
      if level.send(method)
        UI.success "Valid solution"
      else
        UI.error "Invalid solution"
      end
    end

    def level_bump
      profile.level_bump
      if level = Level.load(profile.level)
        UI.puts(level.full_description)
        level.setup_level
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
githug-0.3.3 lib/githug/game.rb
githug-0.3.2 lib/githug/game.rb
githug-0.3.1 lib/githug/game.rb
githug-0.3.0 lib/githug/game.rb
githug-0.2.12 lib/githug/game.rb