Sha256: 447b54715aa3924299ebf39c572e23330d34f2c21cdd138bd0ff1471f29b8557

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require './lib/codebreakergem.rb'
include Codebreakergem 

def hello_message
  puts 'Hello'
end

def menu
  puts "Chose action:\n  1) Start\n  2) Rules\n  3) Stats\n  4) Exit\n"
end

def goodbye_message
  puts "Thank you for playing\nSee you next time"
end

def play_game
    user = nil
    user_input = ''
    puts "Input player's name:"
    
    loop do
      user = User.new(gets.chomp)
      break if user.validate?
    end
    game = Game.new(user)

    difficulties = Game::DIFFICULTIES.map(&:name)
    
    loop do
        puts "Chose difficulty"
    difficulties.each {|key| puts " -#{key}"}
    user_input = gets.chomp
    break if difficulties.include? user_input
    puts "Input one of proposed options"
    end
    game.difficulty = Game::DIFFICULTIES.find{|item| item.name == user_input}.dup


    while game.difficulty.attempts.positive? do
      puts 'Input your guess:'
      user_input = gets.chomp
      next unless game.validate_guess(user_input)
      if user_input == "hint"
        puts game.show_hint
      elsif user_input == "exit"
        break
      else
        puts game.try_guess(user_input)
      end
    end
  end

def game_process
  hello_message
  loop do
    menu
    case gets.chomp
    when "Start" then play_game
    when "Rules" then puts Game.rules
    when "Stats" then puts Game.stats
    when "Exit" then break
    else puts "You have passed unexpected command. Please choose one from listed commands"
    end
  end
  goodbye_message
end

def write_to_file(filename, data)
  File.open(filename, 'w') { |file| file.write(data.to_yaml) }
end

#puts(File.expand_path('lib/data'))
#write_to_file(File.expand_path('lib/data') + 'data.yml', "Hello world")
game_process

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreakergem-0.1.5 main.rb