chadet 1.0.5 → 1.1.3

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
  SHA1:
3
- metadata.gz: da359f21ff6008e3f8f75ce20cfdeb1b0b3727f9
4
- data.tar.gz: 5e66d5254bea5614627a62b9441bf88294278f04
3
+ metadata.gz: b8f115b8e360767d7e308b9172ded8d9687b09ed
4
+ data.tar.gz: 4319770537555e3053667cecf23a6e7e6ec81a89
5
5
  SHA512:
6
- metadata.gz: 451a4efdd388c6f9282b069ffebae43020a7543ae94cc6daa5565056daba4b44daf754989457bff6cc9342063bad51a6cf0d83d5778cccb62312b0da9aa8bacb
7
- data.tar.gz: 85bf6a1d6616cb76c388a186d1f2b6cf54f4d35ce64541d93fa4e0bafab90e21f81264d243cefbc427f7a538fb9818140f2cf213f84cfad3b7995acd02717841
6
+ metadata.gz: b8c1858a7e9f6e980c0b95c0db8d3e803d4582f1eb4b81e3401b717e2bdec44d9c62badd4e8d2d01c10816dbdf50a5ac4d8018b840414e56377ca3167d91826a
7
+ data.tar.gz: a219a784955692404b30c4a67fa3f89b8d647ea6a797385c07b8ea7800e8377064cc154aa2f14c1fc2ef21acf71e5c06c9ca7804bb1a694aad31f2d52f478774
@@ -1,7 +1,7 @@
1
- Copyright (c) 2015 Adrian Setyadi
2
-
3
1
  MIT License
4
2
 
3
+ Copyright (c) 2014-2015 Adrian Setyadi
4
+
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
7
7
  "Software"), to deal in the Software without restriction, including
@@ -20,3 +20,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/bin/chadet CHANGED
@@ -69,19 +69,25 @@ end
69
69
 
70
70
 
71
71
  def display saved_games
72
- puts " Game Saved at"
72
+ puts "---------------------------------------------"
73
+ puts " Game | Saved at"
74
+ puts "---------------------------------------------"
73
75
  saved_games.each do |game|
74
76
  time = DateTime.parse("20"+game.to_i(36).to_s)
75
- saved_at = time.strftime('%a, %b %d, %Y->%I:%M:%S %p')
76
- puts "#{game.code} #{saved_at}"
77
+ saved_at = time.strftime('%a, %b %d, %Y => %I:%M:%S %p')
78
+ puts "#{game.code} | #{saved_at}"
77
79
  end
80
+ puts "---------------------------------------------"
78
81
  end
79
82
 
80
83
  def load filename
81
- # move to bin directory
82
- Dir.chdir('bin')
84
+ # move to data directory
85
+ Dir.chdir(File.dirname(__FILE__))
86
+ Dir.chdir('..')
87
+ Dir.mkdir("data") unless Dir.exists?("data")
88
+ Dir.chdir("data")
83
89
  filename = filename + ".csv"
84
- if filename != "filename" && File.exists?(filename)
90
+ if filename != "file.csv" && File.exists?(filename)
85
91
 
86
92
  # @loaded = true
87
93
  # table_width = 15 + @num_of_chars + 2*@num_of_chars.to_s.length
@@ -108,13 +114,21 @@ end
108
114
  else
109
115
  # list all saved game
110
116
  saved_games = Dir.glob("*.csv").map { |x| x.sub! '.csv', '' }
111
- display saved_games
117
+ if saved_games.count > 0
118
+ display saved_games
119
+ else
120
+ puts "No saved game is found."
121
+ end
112
122
  end
113
123
  # move back to parent directory
114
124
  Dir.chdir('..')
115
125
  exit
116
126
  end
117
127
 
128
+ # Save original terminal rows and columns size
129
+ term_cols = `tput cols`.chomp
130
+ term_rows = `tput lines`.chomp
131
+
118
132
  # Specify new Hash to store the options
119
133
  options = {}
120
134
 
@@ -136,7 +150,9 @@ optparse = OptionParser.new do |opts|
136
150
  opts.on '-r', '--rules', 'How to play this game' do
137
151
  Dir.chdir(File.dirname(__FILE__))
138
152
  Dir.chdir("../lib")
153
+ system("printf '\\033[8;#{term_rows};65t'")
139
154
  system('less -F -R Rules_Of_The_Game_▼_')
155
+ system("printf '\\033[8;#{term_rows};#{term_cols}t'")
140
156
  exit
141
157
  end
142
158
 
@@ -157,7 +173,9 @@ optparse = OptionParser.new do |opts|
157
173
 
158
174
  options[:load] = "file"
159
175
  opts.on '-l', '--load [SAVED GAME]', String, 'Load saved game' do |game|
160
- options[:load] = game
176
+ options[:load] = game unless game.nil?
177
+ load options[:load]
178
+ exit
161
179
  end
162
180
 
163
181
  opts.on '-h', '--help', 'Display this message' do
@@ -167,8 +185,18 @@ optparse = OptionParser.new do |opts|
167
185
  end
168
186
 
169
187
  opts.on '-v', '--version', 'Display the version and author of this game' do
170
- version = ("Chadet " + Chadet::VERSION).code + " is created by Adrian Setyadi"
188
+ version = ("Chadet " + Chadet::VERSION).code
171
189
  puts version
190
+
191
+ print "Show license? (y/n): "
192
+ show_license = gets.chomp
193
+ print "\r\e[1A \r"
194
+
195
+ if show_license == "y"
196
+ Dir.chdir(File.dirname(__FILE__))
197
+ Dir.chdir("..")
198
+ system('less LICENSE.txt')
199
+ end
172
200
  exit
173
201
  end
174
202
  end
@@ -176,7 +204,6 @@ end
176
204
  # Run parse! on the parser object
177
205
  optparse.parse!
178
206
 
179
- load options[:load] if options[:load] != "file"
180
207
  # Set of characters to play with
181
208
  chars_set = options[:characters]
182
209
  if chars_set.length < 2
@@ -201,7 +228,11 @@ num_of_chars = secret_obj.num_of_chars
201
228
 
202
229
  # Set the number to guess
203
230
  # system('clear')
204
- print `tput smcup`
231
+ system("tput smcup")
232
+ system("printf '\\033[8;#{term_rows};65t'")
233
+ # system("printf '\e[33m\e[44m\e[2J\e[1;1H'")
234
+
235
+ print "\r\e[1A"
205
236
  puts "The secret characters are: #{chars_to_guess}".blue if options[:test] == true
206
237
  play = Chadet::Play.new(secret_obj)
207
238
  play.header
@@ -252,37 +283,22 @@ end until go.guess == secret_obj.secret_chars
252
283
 
253
284
  play.end_game if go.guess_num > 0
254
285
 
255
- # Congratulate the player for finishing the game
256
- save = "Your game has been saved."
257
- quit = "Try it again!"
258
- lucky = "Wow! (˚o˚) Lucky guess."
259
- congratulate = "★·.·´¯`·.·★·.·´¯`·.·★\n ░G░O░O░D░ ░J░O░B░!░\n ★·.·´¯`·.·★·.·´¯`·.·★\n" \
260
- + " You did it in " + go.guess_num.to_s + " steps."
261
- a_bit_slow = "(-。ー;) Finally..\n But don't beat yourself up. Try it again!\n I know you "\
262
- + "can do better than " + go.guess_num.to_s + " guesses."
263
-
264
- # To decide what message to display after the game finished
265
- case go.guess_num
266
- when -2
267
- message = save
268
- when -1
269
- message = quit
270
- when 1
271
- message = lucky
272
- when 2..chars_set.length
273
- message = congratulate
274
- else
275
- message = a_bit_slow
276
- end
286
+ # Hide xterm cursor
287
+ system("tput civis -- invisible")
277
288
 
278
- if message == a_bit_slow
279
- puts "\n " + message.yellow
280
- else
281
- message.blink
282
- end
289
+ play.result go.guess_num
290
+ play.footer
291
+
292
+ # Catch any key being typed
293
+ system("stty raw -echo") #=> Raw mode, no echo
294
+ char = STDIN.getc
295
+ system("stty -raw echo") #=> Reset terminal mode
296
+
297
+ # Show xterm cursor as normal
298
+ system("tput cnorm -- normal")
283
299
 
284
- print "\n"
285
- print "(GAME OVER)".code
300
+ # End alternate screen
301
+ system("tput rmcup")
286
302
 
287
- sleep 1
288
- print `tput rmcup`
303
+ # Resize terminal window back to before the game was started
304
+ system("printf '\\033[8;#{term_rows};#{term_cols}t'")
@@ -6,7 +6,7 @@ require 'chadet/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "chadet"
8
8
  spec.version = Chadet::VERSION
9
- spec.date = "2015-08-05"
9
+ spec.date = "2015-08-20"
10
10
 
11
11
  spec.authors = ["Adrian Setyadi"]
12
12
  spec.email = ["a.styd@yahoo.com"]
@@ -16,17 +16,56 @@ module Chadet
16
16
  end
17
17
 
18
18
  def header
19
- puts "==========================================================\n" \
20
- + " Chadet (Characters Detective) ".code + "\n" \
21
- + "==========================================================\n" \
22
- + "To see more options, type " + "chadet --help".code + " in the terminal.\n"\
23
- + "To quit this game at any time, type " + "quit".code + "\n"
24
- puts ",¸¸,ø¤º°``°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸"
19
+ puts "=================================================================\n" \
20
+ + " Chadet (Characters Detective) ".code + "\n" \
21
+ + "=================================================================\n" \
22
+ + "Requires "+"bash".code + " and " + "xterm".code + " to run properly. "\
23
+ + "In the terminal, \ntype " + "chadet --help".code + " for more options and "\
24
+ + "chadet --rules".code + " to see\nthe rules of the game. "\
25
+ + "To quit this game, type " + "quit".code + ".\n"
26
+ puts "°º¤ø,¸¸,ø¤°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°``°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤°"
27
+ end
28
+
29
+ def footer
30
+ #Show Game Over footer at the end of the game
31
+ print "\n"
32
+ print "==========================(GAME OVER)==========================".code
33
+ end
34
+
35
+ def result guess_num
36
+ # Congratulate the player for finishing the game
37
+ save = "Your game has been saved."
38
+ quit = "Try it again!"
39
+ lucky = "Wow! (˚o˚) Lucky guess."
40
+ congratulate = "★·.·´¯`·.·★·.·´¯`·.·★\n ░G░O░O░D░ ░J░O░B░!░\n ★·.·´¯`·.·★·.·´¯`·.·★\n" \
41
+ + " You did it in " + guess_num.to_s + " steps."
42
+ a_bit_slow = "(-。ー;) Finally..\n But don't beat yourself up. Try it again!\n I know you "\
43
+ + "can do better than " + guess_num.to_s + " guesses."
44
+
45
+ # To decide what message to display after the game finished
46
+ case guess_num
47
+ when -2
48
+ message = save
49
+ when -1
50
+ message = quit
51
+ when 1
52
+ message = lucky
53
+ when 2..@chars_set.length
54
+ message = congratulate
55
+ else
56
+ message = a_bit_slow
57
+ end
58
+
59
+ if message == a_bit_slow
60
+ puts "\n " + message.yellow
61
+ else
62
+ message.blink
63
+ end
25
64
  end
26
65
 
27
66
  def chars_to_use
28
67
  @chars_set.length >= 17 ? box_width = @chars_set.length + 2 : box_width = 19
29
- end_pos = 58
68
+ end_pos = 65
30
69
  start_pos = end_pos - box_width
31
70
  puts " "*start_pos + "+" + "-"*(box_width-2) + "+" + "\n"\
32
71
  + " "*start_pos + "|Set of characters" + " "*(box_width - 19) + "|\n" \
@@ -1,3 +1,3 @@
1
1
  module Chadet
2
- VERSION = "1.0.5"
3
- end
2
+ VERSION = "1.1.3"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chadet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Characters Detective: A command line game of guessing random characters
14
14
  intelligently. Computer will generate a random set of characters. The default number