language_cards 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30c6492cc8237c15ce2dc1d7ff4ecf6d134fd1cf04f0dac4ddcc9b40d9241632
4
- data.tar.gz: 71c83da0b18da3593a60cc7662c7bfac4715cdc06475f93ba84a209063a4504a
3
+ metadata.gz: 68244f488493379dce92d1879109a72e4031bc1a7ccfb0e26a29bc99ba65201e
4
+ data.tar.gz: 5d2ad35183a3e9cb97d18092d2abf47623b45fdeca0febba8bab22264b141778
5
5
  SHA512:
6
- metadata.gz: 10dc5db923a7dfde208de9e8c25e517fb3de597ce049fd43f028a920f53777264821726d11c1166b4d49a8c24b3296ac9c48e7afb86a5f7775b3a403044e2051
7
- data.tar.gz: 5255775dacd450df114b8839700c01771d7ef61a8d101ee91b635ca19cf3738e2f50b708987891b5786783db102988f25f528ea873243f1e1d78eebfa38d6d29
6
+ metadata.gz: 53e788b04c2d03bec478647f0fb1dadba2c698c977d1e152b88e27e51f25f507232697a7f3db8476ca6beef97ccca6394b70cbc6480c1f6dba87c82be837312b
7
+ data.tar.gz: 843d4a4b94f07afd463eff60b5ed61452f6e5bd4e12b424d1496aec7b5dc2ddfb6173a9de16eab46432d6feb1a51d1ac837535f4042d4f3d5537376a1141f452
@@ -19,9 +19,9 @@ module LanguageCards
19
19
  def mapped_as
20
20
  case @mapping.first
21
21
  when :k
22
- @mapped_as.keys
22
+ @mapped_as.keys.first
23
23
  else
24
- @mapped_as.values
24
+ @mapped_as.values.first
25
25
  end
26
26
  end
27
27
 
@@ -4,26 +4,34 @@ module LanguageCards
4
4
  class UserInterface
5
5
  def initialize
6
6
  @last = nil
7
+ @mode = [:translate, :typing].cycle
7
8
  end
8
9
 
9
10
  def main_menu(courses:)
10
11
  title = I18n.t 'Menu.Title'
12
+ select = I18n.t 'Menu.Choose'
13
+ mode = case @mode.peek
14
+ when :translate then I18n.t('Menu.ModeTranslate')
15
+ when :typing then I18n.t('Menu.ModeTyping')
16
+ end
17
+ mexit = I18n.t 'Menu.Exit'
18
+
11
19
  <<-MAINMENU
12
20
  #{'~' * SUBMENUWIDTH}
13
21
  #{title}#{('v' + VERSION).rjust(SUBMENUWIDTH - title.length)}
14
22
  #{'~' * SUBMENUWIDTH}
15
-
16
- Select an option:
23
+ #{select}#{(I18n.t('Menu.GameMode') + mode).rjust(SUBMENUWIDTH - select.length)}
17
24
 
18
25
  #{ courses.each.with_index.map {|item,index| "#{index + 1}: #{item}\n" }.join.chop }
19
- #{I18n.t 'Menu.Exit'}
20
26
 
27
+ #{mexit}#{("m: " + I18n.t('Menu.ToggleGameMode')).rjust(SUBMENUWIDTH - mexit.length)}
21
28
  #{'~' * SUBMENUWIDTH}
22
29
  MAINMENU
23
30
  end
24
31
 
25
32
  def score_menu(correct:, incorrect:)
26
33
  score = "#{I18n.t 'Game.ScoreMenu.Score'}: #{correct.to_i} #{I18n.t 'Game.ScoreMenu.OutOf'} #{correct.to_i + incorrect.to_i}"
34
+
27
35
  <<-SCOREMENU
28
36
  #{'~' * SUBMENUWIDTH}
29
37
  #{score + I18n.t('Menu.Exit').rjust(SUBMENUWIDTH - score.length)}
@@ -33,6 +41,7 @@ SCOREMENU
33
41
  end
34
42
 
35
43
  def start(cards)
44
+ @courses = cards.classes
36
45
  clear
37
46
 
38
47
  CLI.say SPLASH_SCREEN
@@ -41,33 +50,22 @@ SCOREMENU
41
50
  begin
42
51
  loop do
43
52
  clear
44
-
45
- CLI.say main_menu(courses: cards.classes)
46
- value = CLI.ask("").to_i - 1
47
- courses = cards.classes
53
+
54
+ CLI.say main_menu(courses: courses)
55
+
56
+ value = CLI.ask("")
57
+
58
+ next @mode.next if value =~ /\Am\z/i
59
+ value = value.to_i - 1 rescue next
60
+
61
+ @last = nil
48
62
  if (0..courses.length-1).include? value
49
- collection = cards.select_collection(courses[value])
63
+ collection = cards.select_collection(courses(value))
50
64
  begin
51
65
  loop do
52
66
  clear
53
67
  CLI.say score_menu(correct: @correct, incorrect: @incorrect)
54
- comp_bitz = collection.rand
55
- input = CLI.ask("#{I18n.t('Game.TypeThis')} #{collection.mapped_as.first}: #{comp_bitz.display}")
56
- if collection.correct? input, comp_bitz
57
- @correct = @correct.to_i + 1
58
- @last = [
59
- I18n.t('Game.Correct'),
60
- "#{input} = #{comp_bitz.display}"
61
- ].join(" ")
62
- else
63
- @incorrect = @incorrect.to_i + 1
64
- @last = [
65
- I18n.t('Game.Incorrect'),
66
- "#{input} != #{comp_bitz.display}",
67
- I18n.t('Game.Its'),
68
- "#{comp_bitz.expected}"
69
- ].join(" ")
70
- end
68
+ game_logic(collection)
71
69
  end
72
70
  rescue SystemExit, Interrupt
73
71
  end
@@ -82,6 +80,67 @@ SCOREMENU
82
80
  def clear
83
81
  printf ::LanguageCards::ESC::CLEAR
84
82
  end
83
+
84
+ IC=Struct.new(:collection, :mode) do
85
+ def input
86
+ @input
87
+ end
88
+
89
+ def get_input
90
+ @input ||= CLI.ask("#{I18n.t('Game.TypeThis')} #{collection.mapped_as}: #{display}")
91
+ end
92
+
93
+ def comp_bitz
94
+ @comp_bitz ||= collection.rand
95
+ end
96
+
97
+ def display
98
+ comp_bitz.display
99
+ end
100
+
101
+ def expected
102
+ comp_bitz.expected
103
+ end
104
+
105
+ def correct_msg
106
+ "#{I18n.t('Game.Correct')} #{input} = #{display}"
107
+ end
108
+
109
+ def incorrect_msg
110
+ output = "#{I18n.t('Game.Incorrect')} #{input} != #{display}"
111
+ output << " #{I18n.t('Game.Its')} #{expected}" if mode == :translate
112
+ output
113
+ end
114
+
115
+ def valid?
116
+ collection.correct?(input, comp_bitz)
117
+ end
118
+ end
119
+
120
+ def game_logic(c)
121
+ ic = IC.new(c, @mode.peek)
122
+ ic.get_input
123
+ ic.valid? ? last_was_correct(ic) : last_was_incorrect(ic)
124
+ end
125
+
126
+ def last_was_correct(ic)
127
+ @correct = @correct.to_i + 1
128
+ @last = ic.correct_msg
129
+ end
130
+
131
+ def last_was_incorrect(ic)
132
+ @incorrect = @incorrect.to_i + 1
133
+ @last = ic.incorrect_msg
134
+ end
135
+
136
+ def courses(value = nil)
137
+ courses = @courses.select {|c| detect_course_mode(c) == @mode.peek }
138
+ value ? courses[value] : courses
139
+ end
140
+
141
+ def detect_course_mode str
142
+ str.split(JOIN).last.split(" => ").inject(:==) ? :typing : :translate
143
+ end
85
144
  end
86
145
  end
87
146
 
@@ -1,3 +1,3 @@
1
1
  module LanguageCards
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
data/locales/en.yml CHANGED
@@ -1,7 +1,11 @@
1
1
  en:
2
2
  Menu:
3
3
  Title: Language Cards by @6ftdan
4
- Choose: Choose your flash cards.
4
+ Choose: Select an option
5
+ GameMode: "GAME MODE: "
6
+ ToggleGameMode: Change Mode
7
+ ModeTranslate: Translate
8
+ ModeTyping: Typing
5
9
  Exit: Press CTRL-C to quit.
6
10
  Game:
7
11
  TypeThis: Type the following in
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: language_cards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark