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 +4 -4
- data/lib/language_cards/comparator.rb +2 -2
- data/lib/language_cards/user_interface.rb +84 -25
- data/lib/language_cards/version.rb +1 -1
- data/locales/en.yml +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68244f488493379dce92d1879109a72e4031bc1a7ccfb0e26a29bc99ba65201e
|
|
4
|
+
data.tar.gz: 5d2ad35183a3e9cb97d18092d2abf47623b45fdeca0febba8bab22264b141778
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53e788b04c2d03bec478647f0fb1dadba2c698c977d1e152b88e27e51f25f507232697a7f3db8476ca6beef97ccca6394b70cbc6480c1f6dba87c82be837312b
|
|
7
|
+
data.tar.gz: 843d4a4b94f07afd463eff60b5ed61452f6e5bd4e12b424d1496aec7b5dc2ddfb6173a9de16eab46432d6feb1a51d1ac837535f4042d4f3d5537376a1141f452
|
|
@@ -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:
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
data/locales/en.yml
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
en:
|
|
2
2
|
Menu:
|
|
3
3
|
Title: Language Cards by @6ftdan
|
|
4
|
-
Choose:
|
|
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
|