Class: Gitscrub::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/gitscrub/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



6
7
8
# File 'lib/gitscrub/game.rb', line 6

def initialize
  @profile = Profile.load
end

Instance Attribute Details

#profileObject

Returns the value of attribute profile.



4
5
6
# File 'lib/gitscrub/game.rb', line 4

def profile
  @profile
end

Instance Method Details

#level_bumpObject



30
31
32
33
34
35
36
37
# File 'lib/gitscrub/game.rb', line 30

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

#play_levelObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitscrub/game.rb', line 10

def play_level
  solve = true
  if profile.level == 0
    UI.puts("Welcome to Gitscrub")
    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!"
        UI.puts level.full_description
      end
    end
  end
end