Class: PaitinHangman::GameResumption

Inherits:
GameEngine show all
Defined in:
lib/paitin_hangman/game_resumption.rb

Instance Attribute Summary collapse

Attributes inherited from GameEngine

#count, #guess, #misses, #player2, #right_guesses

Instance Method Summary collapse

Methods inherited from GameEngine

#cheat_or_quit_or_history, #compare_guess, #correct_guess, #end_game, #history, #history_verify_guess, #print_history, #quit_or_save, #right_guess, #save_game, #verify_guess, #win_game, #wrong_guess

Methods included from SimpleMethods

#choice_integrity, #decide, #length_one?, #number?, #option_integrity, #unique?, #verify_name_integrity

Constructor Details

#initializeGameResumption

Returns a new instance of GameResumption.



5
6
7
8
9
10
11
12
13
14
# File 'lib/paitin_hangman/game_resumption.rb', line 5

def initialize
  file_name = File.join(File.dirname(File.expand_path(__FILE__)), '../../games.yml')
  @all_games = YAML.load_stream(File.open(file_name, "a+"))
  puts "Enter the name you used to store the game"
  name = STDIN.gets.chomp.upcase
  @saved_game = all_games.select do |game|
    game.player_name == name
  end
  initialize_cont(name)
end

Instance Attribute Details

#all_gamesObject (readonly)

Returns the value of attribute all_games.



4
5
6
# File 'lib/paitin_hangman/game_resumption.rb', line 4

def all_games
  @all_games
end

Instance Method Details

#choice_integritiesObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/paitin_hangman/game_resumption.rb', line 27

def choice_integrities
  puts "Now enter the number for the game you want to play".blue
  @choice = STDIN.gets.chomp.to_i
  until @choice > 0 && @choice <= @saved_game.length
    puts "Enter a number that has a game please"
    @choice = STDIN.gets.chomp.to_i
  end
  @choice -= 1
  load_properties
end

#initialize_cont(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/paitin_hangman/game_resumption.rb', line 16

def initialize_cont(name)
  if @saved_game.empty?
    puts "You have no saved game with that name".red
    puts "START A NEW GAME INSTEAD".yellow
    exit
  end
  puts "Here are the saved games found for #{name}\n\n"
  print_function
  choice_integrities
end

#load_propertiesObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/paitin_hangman/game_resumption.rb', line 38

def load_properties
  @game_object = @saved_game[@choice]
  @name = @game_object.player_name
  @misses = @game_object.misses
  @right_guesses = @game_object.right_guesses
  @chances = @game_object.chances
  @word_control = @game_object.word_control
  @game_word = @game_object.game_word
  load_properties_cont
end

#load_properties_contObject



49
50
51
52
# File 'lib/paitin_hangman/game_resumption.rb', line 49

def load_properties_cont
  @count = @game_object.count
  trials(@chances)
end


54
55
56
57
58
59
# File 'lib/paitin_hangman/game_resumption.rb', line 54

def print_function
  @saved_game.length.times do |index|
    print "#{index + 1}.\t"
    puts @saved_game[index], "\n"
  end
end

#setupObject



73
74
75
76
# File 'lib/paitin_hangman/game_resumption.rb', line 73

def setup
  puts "Now, continue playing..."
  puts @word_control.gsub("_", "__ ").upcase
end

#trials(chances) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/paitin_hangman/game_resumption.rb', line 62

def trials(chances)
  setup
  chances.times do |counter|
    @counter = counter
    verify_guess(chances)
    compare_guess
    win_game(chances, counter, @name)
  end
  end_game(@name)
end