lkr-codebreaker 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a948948ff2bb60da3871d149614d5ed7e60e875281ba17fedac58bab146f14ed
4
- data.tar.gz: 10540077c5b0145af825cf81990f385a4b588516c48272f0a163cdb47adcb34d
3
+ metadata.gz: ea7a3562e0b7c78bc04ed84af1d37464d49bc6505aeba3a4b09186a0e82953c5
4
+ data.tar.gz: 5689b331868ec9b646c2242613c3eb69f9c1fc2e63c42ba0cb06a5beed9e5815
5
5
  SHA512:
6
- metadata.gz: 55a1f2d7ebfee728186cb1c89540530e7cb198fca596165e9f1b7e260b3d7f575e305584fd90acda02a76319b6eb78c454c10b3fa7ed06cac0a5bbcf9f265752
7
- data.tar.gz: e8ef3c40043834d71df01549dac7de1531ae7ccf25ae74f15b531e49457cb928a9566386758a8a3931b123db9b5d896e42d7636d69ac639240954b030bbfa152
6
+ metadata.gz: 577ccab19ff047286ba393a1213f8d78d2486a1eee398bcdb2fcd2597163d74475495106e8e19443a6efddd5abc917ac741489c5ae009d2061cb28497b07cffe
7
+ data.tar.gz: 229429120368afe42aea5fa2b3fcf397cd75157f246c3ec7244b366a2134111aa4ac5d5b435e184ece08e633fa68d0ec430569ecce77afb4d6d01cf09cf6586c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lkr-codebreaker (0.1.0)
4
+ lkr-codebreaker (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,7 +7,7 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'codebreaker'
10
+ gem 'lkr-codebreaker'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -25,16 +25,6 @@ module Codebreaker
25
25
  exact_matches + number_matches
26
26
  end
27
27
 
28
- def save_result(username:, game_status:, file_name: 'player_results.txt')
29
- File.open(file_name, 'a') do |file|
30
- file.puts("Name: #{username}")
31
- file.puts("Game status: #{game_status}")
32
- file.puts("Attempts used: #{@used_attempts}")
33
- file.puts("Hints used: #{@used_hints}")
34
- file.puts('*' * 40)
35
- end
36
- end
37
-
38
28
  private
39
29
 
40
30
  def generate
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lkr-codebreaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Kozhemyako
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-23 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,10 +68,8 @@ files:
68
68
  - codebreaker.gemspec
69
69
  - lib/codebreaker.rb
70
70
  - lib/codebreaker/game.rb
71
- - lib/codebreaker/user_interface.rb
72
- - lib/codebreaker/user_interface_helper.rb
73
71
  - lib/codebreaker/version.rb
74
- - lib/main.rb
72
+ - lkr-codebreaker-0.1.0.gem
75
73
  homepage:
76
74
  licenses:
77
75
  - MIT
@@ -1,110 +0,0 @@
1
- require_relative 'game'
2
- require_relative 'user_interface_helper'
3
-
4
- module Codebreaker
5
- class UserInterface
6
- include UiHelper
7
-
8
- def main_menu
9
- greeting_message
10
- gets.chomp == 'exit' ? bye : play
11
- end
12
-
13
- def play
14
- create_new_game
15
- start_game_message
16
- playing
17
- lost unless attempts?
18
- score
19
- after_game_menu
20
- end
21
-
22
- private
23
-
24
- def create_new_game
25
- @game = Game.new
26
- end
27
-
28
- def playing
29
- while attempts?
30
- used_attempts_message
31
- input = gets.chomp
32
- if call_hint?(input)
33
- show_hint
34
- else
35
- result = @game.make_guess(input)
36
- result ? puts(result) : incorrect_format_message
37
- end
38
- if won?(result)
39
- won
40
- break
41
- end
42
- end
43
- end
44
-
45
- def attempts?
46
- @game.used_attempts < Game::ATTEMPTS
47
- end
48
-
49
- def hints?
50
- @game.used_hints < Game::HINTS
51
- end
52
-
53
- def call_hint?(input)
54
- input.match(/^h$/)
55
- end
56
-
57
- def show_hint
58
- hints? ? puts(@game.hint) : no_hints_message
59
- end
60
-
61
- def show_result(result)
62
- puts result
63
- end
64
-
65
- def won?(result)
66
- result == '++++'
67
- end
68
-
69
- def won
70
- @game_status = 'won'
71
- won_message
72
- end
73
-
74
- def lost
75
- @game_status = 'lost'
76
- lost_message
77
- end
78
-
79
- def score
80
- puts "Attempts used: #{@game.used_attempts}"
81
- puts "Hints used: #{@game.used_hints}"
82
- end
83
-
84
- def after_game_menu
85
- after_game_message
86
- choise = gets.chomp[/^[yns]/]
87
-
88
- if choise == 'y' then play end
89
- if choise == 'n' then bye end
90
- if choise == 's' then save end
91
- main_menu
92
- end
93
-
94
- def save
95
- name = ask_name
96
- @game.save_result(username: name, game_status: @game_status)
97
- saved_result_message
98
- end
99
-
100
- def ask_name
101
- puts 'Please, type your name:'
102
- gets.chomp
103
- end
104
-
105
- def bye
106
- puts 'Bye!'
107
- exit
108
- end
109
- end
110
- end
@@ -1,41 +0,0 @@
1
- require_relative 'game'
2
-
3
- module UiHelper
4
- def greeting_message
5
- puts '***Welcome to the Codebreaker game!***'
6
- puts "Enter any characters to start playing or 'exit' for exit"
7
- end
8
-
9
- def start_game_message
10
- puts "Please, enter your code to make guess or 'h' to get a hint"
11
- puts "You have #{Codebreaker::Game::ATTEMPTS} attempts and #{Codebreaker::Game::HINTS} hints"
12
- end
13
-
14
- def used_attempts_message
15
- puts "You used #{@game.used_attempts} attempts." if @game.used_attempts > 0
16
- end
17
-
18
- def no_hints_message
19
- puts 'You used all of hints!'
20
- end
21
-
22
- def incorrect_format_message
23
- puts 'Incoorect format! Please enter 4 digits from 1 to 6'
24
- end
25
-
26
- def won_message
27
- puts '***Congratulations, you won!***'
28
- end
29
-
30
- def lost_message
31
- puts 'You used all of attempts. You lost :('
32
- end
33
-
34
- def after_game_message
35
- puts 'Do you want to play again(y/n) or save score(s)?'
36
- end
37
-
38
- def saved_result_message
39
- puts 'Your result has been saved'
40
- end
41
- end
data/lib/main.rb DELETED
@@ -1,4 +0,0 @@
1
- require_relative 'codebreaker/user_interface'
2
-
3
- ui = Codebreaker::UserInterface.new
4
- ui.main_menu