m0rse_c0de 0.3.2 → 0.3.8
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/README.md +22 -0
- data/lib/hashes/hashes.rb +1 -14
- data/lib/m0rse.rb +30 -30
- data/lib/sound/beeps/dah.wav +0 -0
- data/lib/sound/beeps/dit.wav +0 -0
- data/lib/sound/sound.rb +24 -8
- data/lib/teacher/hangman.rb +130 -0
- data/lib/teacher/teacher.rb +39 -30
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb38c6816fa1eef56c647bcdda493cb1f9be0a47aa35311efa32ec763a23dc79
|
4
|
+
data.tar.gz: 0c64785f5a54ab08ce269c4b9a51d6c0405eaa4692243402311301f72cd21429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 960618fbc70ea05cf422a1ca0eb7eda1d3840b5cb1ef147e6d5e299c7c11dfd4b51d348a1e67add3ef995164f325d19a3edcee9f8dc758216741ba1e6b8932db
|
7
|
+
data.tar.gz: 657fb662dc56ede3929250133c86be7156ed02db7a137ac47301f932f78752b0c7f5aefdba999dcf62961d9acffc49eb4b98db5b75bc2c10747a6414dcd6afd8
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#m0rse_c0de
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
```
|
5
|
+
require 'm0rse'
|
6
|
+
|
7
|
+
include M0rse
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
call ```Morse.teacher``` contains small games that you can play from the terminalto help you learn morse code:
|
12
|
+
|
13
|
+
```Morse.teacher.hangman```
|
14
|
+
```Morse.teacher.practice```
|
15
|
+
|
16
|
+
|
17
|
+
call ```Morse.blink(text)``` to make your terminal blink in morse code (windows only)
|
18
|
+
call ```Morse.play(text)``` to make your computer play morse code
|
19
|
+
|
20
|
+
other methods are self-explanatory.
|
21
|
+
|
22
|
+
|
data/lib/hashes/hashes.rb
CHANGED
@@ -18,20 +18,7 @@ module Translation
|
|
18
18
|
'0' => '-----', ', ' => '--..--', '.' => '.-.-.-',
|
19
19
|
'?' => '..--..', '/' => '-..-.', '-' => '-....-', ' ' => '\\'}
|
20
20
|
|
21
|
-
@@morsetoascii =
|
22
|
-
'-.-.' => 'c', '-..' => 'd', '.' => 'e',
|
23
|
-
'..-.' => 'f', '--.' => 'g', '....' => 'h',
|
24
|
-
'..' => 'i', '.---' => 'j', '-.-' => 'k',
|
25
|
-
'.-..' => 'l', '--' => 'm', '-.' => 'n',
|
26
|
-
'---' => 'o', '.--.' => 'p', '--.-' => 'q',
|
27
|
-
'.-.' => 'r', '...' => 's', '-' => 't',
|
28
|
-
'..-' => 'u', '...-' => 'v', '.--' => 'w',
|
29
|
-
'-..-'=> 'x', '-.--' => 'y', '--..' => 'z',
|
30
|
-
'.----' => '1', '..---' => '2', '...--' => '3',
|
31
|
-
'....-' => '4', '.....' => '5', '-....' => '6',
|
32
|
-
'--...' => '7', '---..' => '8', '----.' => '9',
|
33
|
-
'-----' => '0', '--..--' => ',', '.-.-.-' => '.',
|
34
|
-
'..--..' => '?', '-..-.' => '/', '-....-' => '-', '\\' => ' '}
|
21
|
+
@@morsetoascii = @@asciitomorse.invert
|
35
22
|
|
36
23
|
|
37
24
|
end
|
data/lib/m0rse.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
require_relative './hashes/hashes.rb'
|
2
|
-
|
3
|
-
require_relative './sound/sound.rb'
|
4
|
-
rescue
|
5
|
-
puts "Morse.play and Morse.blink methods won't work for #{RUBY_PLATFORM}"
|
6
|
-
end
|
2
|
+
require_relative './sound/sound.rb'
|
7
3
|
require_relative './teacher/teacher.rb'
|
4
|
+
require_relative './teacher/hangman.rb'
|
5
|
+
|
8
6
|
|
7
|
+
include H4ngman
|
9
8
|
include Translation
|
10
9
|
include Te4cher
|
11
|
-
|
12
|
-
|
13
|
-
rescue
|
14
|
-
end
|
10
|
+
include Beeper
|
11
|
+
|
15
12
|
|
16
13
|
module M0rse
|
17
14
|
|
15
|
+
@@teacher = Teacher
|
16
|
+
|
18
17
|
class Morse
|
19
|
-
|
20
18
|
def self.text_to_morse(text_)
|
21
19
|
morse_ = []
|
22
20
|
text_.downcase!
|
@@ -67,49 +65,51 @@ module M0rse
|
|
67
65
|
text_ = file_.readlines.map(&:chomp).join()
|
68
66
|
result_ = self.text_to_morse(text_)
|
69
67
|
file_.close()
|
70
|
-
File.open("#{filename_}-Morsed", "w")
|
68
|
+
new_file = File.open("#{filename_}-Morsed", "w")
|
69
|
+
File.write(new_file, result_)
|
71
70
|
end
|
72
71
|
|
73
72
|
def self.blink(text_)
|
74
73
|
morse_ = self.text_to_morse(text_)
|
75
|
-
for
|
76
|
-
if
|
74
|
+
for char in morse_.split(//)
|
75
|
+
if char == '.'
|
77
76
|
system('color 70')
|
78
77
|
sleep(0.01)
|
79
78
|
system('color 07')
|
80
|
-
elsif
|
79
|
+
elsif char == '-'
|
81
80
|
system('color 70')
|
82
81
|
sleep(0.2)
|
83
82
|
system('color 07')
|
84
|
-
elsif
|
83
|
+
elsif char == ' '
|
85
84
|
sleep(0.3)
|
86
|
-
elsif
|
85
|
+
elsif char == '\\'
|
87
86
|
sleep(0.7)
|
88
87
|
end
|
89
88
|
end; "completed"
|
90
89
|
end
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
|
92
|
+
def self.play(text_, speed=1)
|
93
|
+
morse_ = self.text_to_morse(text_)
|
94
|
+
begin
|
95
|
+
for char in morse_.split(//)
|
96
|
+
if char == '.'
|
97
97
|
Beeper.dit
|
98
|
-
elsif
|
98
|
+
elsif char == '-'
|
99
99
|
Beeper.dah
|
100
|
-
elsif
|
101
|
-
sleep(0.375)
|
102
|
-
elsif
|
103
|
-
sleep(0.875)
|
100
|
+
elsif char == ' '
|
101
|
+
sleep(0.375*speed)
|
102
|
+
elsif char == '\\'
|
103
|
+
sleep(0.875*speed)
|
104
104
|
end
|
105
105
|
end; "completed"
|
106
|
+
rescue
|
107
|
+
puts "something went wrong..."
|
106
108
|
end
|
107
|
-
rescue
|
108
|
-
ensure
|
109
109
|
end
|
110
110
|
|
111
|
-
def self.
|
112
|
-
|
111
|
+
def self.teacher
|
112
|
+
@@teacher
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
data/lib/sound/beeps/dah.wav
CHANGED
File without changes
|
data/lib/sound/beeps/dit.wav
CHANGED
File without changes
|
data/lib/sound/sound.rb
CHANGED
@@ -1,14 +1,30 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'win32/sound'
|
2
3
|
|
3
|
-
include Win32
|
4
|
+
include Win32
|
4
5
|
|
5
|
-
module Beeper
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module Beeper
|
7
|
+
def dit
|
8
|
+
Sound.play("#{__dir__}/beeps/dit.wav")
|
9
|
+
end
|
10
|
+
|
11
|
+
def dah
|
12
|
+
Sound.play("#{__dir__}/beeps/dah.wav")
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
module Beeper
|
19
|
+
def dit
|
20
|
+
system("play #{__dir__}/beeps/dit.wav -q -t alsa")
|
21
|
+
end
|
22
|
+
|
23
|
+
def dah
|
24
|
+
system("play #{__dir__}/beeps/dah.wav -q -t alsa")
|
25
|
+
end
|
26
|
+
|
12
27
|
end
|
13
28
|
|
14
29
|
end
|
30
|
+
|
@@ -0,0 +1,130 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module H4ngman
|
4
|
+
|
5
|
+
class Hangman
|
6
|
+
@hangman_sprite5 = '''
|
7
|
+
---
|
8
|
+
|
|
9
|
+
( )
|
10
|
+
|
11
|
+
|
12
|
+
'''
|
13
|
+
@hangman_sprite4 = '''
|
14
|
+
---
|
15
|
+
|
|
16
|
+
( )
|
17
|
+
I
|
18
|
+
|
19
|
+
'''
|
20
|
+
|
21
|
+
@hangman_sprite3 = '''
|
22
|
+
---
|
23
|
+
|
|
24
|
+
( )
|
25
|
+
-I
|
26
|
+
|
27
|
+
'''
|
28
|
+
|
29
|
+
@hangman_sprite2 = '''
|
30
|
+
---
|
31
|
+
|
|
32
|
+
( )
|
33
|
+
-I-
|
34
|
+
|
35
|
+
'''
|
36
|
+
|
37
|
+
@hangman_sprite1 = '''
|
38
|
+
---
|
39
|
+
|
|
40
|
+
( )
|
41
|
+
-I-
|
42
|
+
/
|
43
|
+
|
44
|
+
'''
|
45
|
+
|
46
|
+
@hangman_sprite0 = '''
|
47
|
+
---
|
48
|
+
|
|
49
|
+
( )
|
50
|
+
-I-
|
51
|
+
/ \
|
52
|
+
|
53
|
+
'''
|
54
|
+
|
55
|
+
def self.finish
|
56
|
+
if @remaining_credits == 0
|
57
|
+
puts "GAME OVER, YOU LOSE :("
|
58
|
+
elsif
|
59
|
+
puts "YOU WON! CONGRATS"
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "the word was #{Morse.text_to_morse(@keyword)}"
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.choose_word(list_)
|
67
|
+
@keyword = list_.sample
|
68
|
+
puts "Your word has been selected!"
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.generate_mystery_text
|
72
|
+
@mystery_text = ("?"*@keyword.length).split(//)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.handle_mystery_text
|
76
|
+
begin
|
77
|
+
@mystery_text = @mystery_text.split(//)
|
78
|
+
rescue
|
79
|
+
end
|
80
|
+
matching_indexes = @keyword.split(//).each_index.select { |i| @keyword[i] == @user_answer }
|
81
|
+
for index in matching_indexes
|
82
|
+
@mystery_text.delete_at index
|
83
|
+
@mystery_text.insert(index, @user_answer)
|
84
|
+
end
|
85
|
+
@mystery_text = @mystery_text.join()
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.display
|
89
|
+
sprite_dict = {5 => @hangman_sprite5, 4 => @hangman_sprite4, 3 => @hangman_sprite3, 2 =>@hangman_sprite2, 1 =>@hangman_sprite1, 0 => @hangman_sprite0}
|
90
|
+
self.handle_mystery_text
|
91
|
+
puts @mystery_text
|
92
|
+
puts sprite_dict[@remaining_credits]
|
93
|
+
puts "You have #{@remaining_credits} tries left."
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.main
|
97
|
+
self.generate_mystery_text
|
98
|
+
@correct_guesses = []
|
99
|
+
@remaining_credits = 6
|
100
|
+
while @remaining_credits != 0
|
101
|
+
print "Try to guess the word or a character that the word consists! (in morse) --> "
|
102
|
+
@user_answer = Morse.morse_to_text(gets.chomp.strip)
|
103
|
+
system('clear')
|
104
|
+
system('cls')
|
105
|
+
|
106
|
+
if @keyword.include?(@user_answer)
|
107
|
+
puts "#{Morse.text_to_morse(@user_answer)} is an accurate guess!"
|
108
|
+
if @user_answer == @keyword
|
109
|
+
break
|
110
|
+
else
|
111
|
+
@correct_guesses.append(@user_answer)
|
112
|
+
end
|
113
|
+
|
114
|
+
elsif not @keyword.include?(@user_answer) or @user_answer == ''
|
115
|
+
puts "#{Morse.text_to_morse(@user_answer)} isn't an accurate guess."
|
116
|
+
@remaining_credits = @remaining_credits - 1
|
117
|
+
end
|
118
|
+
|
119
|
+
self.display
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
self.finish
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
data/lib/teacher/teacher.rb
CHANGED
@@ -2,13 +2,40 @@
|
|
2
2
|
module Te4cher
|
3
3
|
class Teacher
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
@@word_list = ['Ruby', 'Red', 'Awesome', 'Burzum',
|
6
|
+
'Help', 'Blood', 'Emergency', 'Death',
|
7
|
+
'Morse', 'SOS', 'SQL', 'Wreck', 'Ship',
|
8
|
+
'You', 'Us', 'America', 'Boat', 'Hello',
|
9
|
+
'Amazed', 'Python', 'Life', 'acme',
|
10
|
+
'antiseptically', 'boudoir', 'cesium', 'circumscribing',
|
11
|
+
'collegians', 'confessionals', 'erectly', 'finagler',
|
12
|
+
'hostelries', 'howdah', 'impetigo', 'lampposts', 'lisle',
|
13
|
+
'mestizos', 'overcooked', 'slippage', 'slouchiest',
|
14
|
+
'strumpet', 'terabyte', 'transfiguration', 'twill',
|
15
|
+
'undersold', 'unsheathed', 'whelps', 'adlumidine',
|
16
|
+
'alinasal', 'aramina', 'begreen', 'bembixes',
|
17
|
+
'boundly', 'cannibalean', 'chondrinous', 'colickiest',
|
18
|
+
'cullas', 'hartake', 'interchangings', 'marquito',
|
19
|
+
'miscegenationists', 'peremption', 'quesitive', 'ragnarok',
|
20
|
+
'reconciliated', 'sepsine', 'sickless', 'sigillaria',
|
21
|
+
'staphyledema', 'undelible', 'unruth', 'yaourti',
|
22
|
+
'avoid', 'bottle', 'briefly', 'bug',
|
23
|
+
'dedicated', 'establish', 'everything', 'goes',
|
24
|
+
'harm', 'inferior', 'killed', 'leader',
|
25
|
+
'noticed', 'quicker', 'recovered', 'reflects',
|
26
|
+
'retain', 'self', 'should', 'signal',
|
27
|
+
'simultaneously', 'stayed', 'tomorrow', 'virtue',
|
28
|
+
'weird', 'adlumidine', 'alinasal', 'aramina',
|
29
|
+
'begreen', 'bembixes', 'boundly', 'cannibalean',
|
30
|
+
'chondrinous', 'colickiest', 'cullas', 'hartake',
|
31
|
+
'interchangings', 'marquito', 'miscegenationists', 'peremption',
|
32
|
+
'quesitive', 'ragnarok', 'reconciliated', 'sepsine',
|
33
|
+
'sickless', 'sigillaria', 'staphyledema', 'undelible', 'unruth', 'yaourti'] #todo: complete
|
34
|
+
|
9
35
|
|
36
|
+
def self.practice
|
10
37
|
while true
|
11
|
-
random_word =
|
38
|
+
random_word = @@word_list.sample.upcase!
|
12
39
|
correct_answer = Morse.text_to_morse(random_word)
|
13
40
|
puts "translate ---> #{random_word}"
|
14
41
|
print 'Your answer: '
|
@@ -17,45 +44,27 @@ module Te4cher
|
|
17
44
|
puts 'Correct! Moving to the next word...'
|
18
45
|
sleep(2)
|
19
46
|
else
|
20
|
-
puts "Wrong! The correct answer was: #{correct_answer}
|
47
|
+
puts "Wrong! The correct answer was: #{correct_answer} \nmoving to the next word..."
|
21
48
|
sleep(2)
|
22
49
|
end
|
23
50
|
end
|
24
51
|
end
|
25
52
|
|
53
|
+
def self.hangman
|
54
|
+
Hangman.choose_word(@@word_list)
|
55
|
+
Hangman.main
|
56
|
+
end
|
57
|
+
|
26
58
|
def self.show_hashes
|
27
59
|
for char, morse in @@asciitomorse
|
28
60
|
print char, ' --> ', morse, ' '
|
29
61
|
end; 'Morse Alphabet'
|
30
62
|
end
|
31
|
-
|
32
|
-
|
33
|
-
def self.main
|
34
|
-
greeting = '''
|
35
|
-
|
36
|
-
Welcome to teaching mode! If you want to practice: input PRACTICE,
|
37
|
-
if you want to view the Morse alphabet input ALPHABET.
|
38
|
-
|
39
|
-
'''
|
40
|
-
|
41
|
-
puts greeting
|
42
|
-
|
43
|
-
@choice = gets.chomp
|
44
|
-
|
45
|
-
if @choice == 'PRACTICE'
|
46
|
-
self.start_practice
|
47
|
-
|
48
|
-
elsif @choice == 'ALPHABET'
|
49
|
-
self.show_hashes
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
63
|
end
|
54
|
-
|
55
64
|
end
|
56
65
|
|
57
66
|
|
58
67
|
|
59
68
|
|
60
69
|
|
61
|
-
|
70
|
+
|
metadata
CHANGED
@@ -1,40 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m0rse_c0de
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burzum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: win32-sound
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.6.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.6.2
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
|
-
extra_rdoc_files:
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
32
33
|
files:
|
34
|
+
- README.md
|
33
35
|
- lib/hashes/hashes.rb
|
34
36
|
- lib/m0rse.rb
|
35
37
|
- lib/sound/beeps/dah.wav
|
36
38
|
- lib/sound/beeps/dit.wav
|
37
39
|
- lib/sound/sound.rb
|
40
|
+
- lib/teacher/hangman.rb
|
38
41
|
- lib/teacher/teacher.rb
|
39
42
|
homepage:
|
40
43
|
licenses: []
|
@@ -54,11 +57,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
57
|
- !ruby/object:Gem::Version
|
55
58
|
version: '0'
|
56
59
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.1.2
|
58
61
|
signing_key:
|
59
62
|
specification_version: 4
|
60
63
|
summary: A gem for translation from hex, binary, text to morse and vice versa; it
|
61
|
-
additionally can teach you Morse, play
|
62
|
-
Morse and
|
63
|
-
only :( )
|
64
|
+
additionally can teach you Morse, play text to Morse (on linux requires SoX), translate
|
65
|
+
a file to Morse and it can blink in Morse.
|
64
66
|
test_files: []
|