the_game 0.0.6 → 0.1.a
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/bin/the_game +1 -1
- data/lib/the_game/cli.rb +6 -3
- data/lib/the_game/command.rb +19 -28
- data/lib/the_game/exception.rb +1 -0
- data/lib/the_game/game.rb +29 -26
- data/lib/the_game/helpers/exception.rb +5 -0
- data/lib/the_game/helpers/import.rb +10 -1
- data/lib/the_game/helpers.rb +15 -4
- data/lib/the_game/item.rb +7 -0
- data/lib/the_game/license.rb +0 -2
- data/lib/the_game/version.rb +6 -3
- data/lib/the_game.rb +2 -0
- metadata +17 -14
data/README.rdoc
CHANGED
data/bin/the_game
CHANGED
data/lib/the_game/cli.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
|
-
#
|
3
|
+
# TheGame::CLI is the_game's command-line interface.
|
4
|
+
#
|
5
|
+
# The executable +the_game+ calls this method. Here is the source of +the_game+:
|
6
|
+
# :include:bin/the_game
|
4
7
|
module TheGame::CLI
|
5
8
|
class << self
|
6
9
|
def start!(args = ARGV)
|
7
10
|
@game = TheGame::Game.new
|
8
|
-
@game_mode =
|
11
|
+
@game_mode = nil
|
9
12
|
|
10
13
|
opts = OptionParser.new(args) do |opts|
|
11
14
|
opts.banner = "Usage: the_game [options] [mode]"
|
@@ -27,7 +30,7 @@ module TheGame::CLI
|
|
27
30
|
when :play then @game.start!
|
28
31
|
when :license then puts TheGame::LICENSE
|
29
32
|
when :version then puts "the_game v#{TheGame::Version::STRING}"
|
30
|
-
else puts opts end
|
33
|
+
else puts opts end # Display help message
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
data/lib/the_game/command.rb
CHANGED
@@ -17,13 +17,15 @@ class TheGame::Command
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def method_missing(m, g, a)
|
21
|
-
|
20
|
+
def method_missing(m, g, a); "#{m.to_s.command_sanitize}: command not found"; end
|
21
|
+
|
22
|
+
def available_methods
|
23
|
+
methods(false).select{ |m| m.match(/^_/) }.map{ |m| m.to_s.command_sanitize }
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
26
|
+
def _raise(g, a); raise FuntimeError, a; end
|
27
|
+
|
28
|
+
def _args(g, a); a.args.inspect; end
|
27
29
|
|
28
30
|
def _echo(g, a); a; end
|
29
31
|
|
@@ -33,8 +35,7 @@ class TheGame::Command
|
|
33
35
|
"Usage: set [key] [value]"
|
34
36
|
else
|
35
37
|
key = a.words.first.to_s.downcase
|
36
|
-
|
37
|
-
r == true ? "#{key.capitalize} set to #{value.inspect}" : r
|
38
|
+
pretty_rescue("#{key.capitalize} set to #{value.inspect}") { g.set(key, value) }
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -55,30 +56,20 @@ class TheGame::Command
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
def _help(g, a)
|
59
|
-
commands = methods(false).select{|m|m.match(/^_/)}.map{|m|m.to_s.command_sanitize}
|
60
|
-
|
61
|
-
"Commands available: [ #{commands.join(', ')} ]"
|
62
|
-
end
|
59
|
+
def _help(g, a); "Commands available: [ #{available_methods.join(', ')} ]"; end
|
63
60
|
|
64
|
-
def _version(g, a)
|
65
|
-
TheGame::Version::STRING
|
66
|
-
end
|
61
|
+
def _version(g, a); "the_game v#{TheGame::Version::STRING}"; end
|
67
62
|
|
68
|
-
def _license(g, a)
|
69
|
-
TheGame::LICENSE
|
70
|
-
end
|
63
|
+
def _license(g, a); TheGame::LICENSE; end
|
71
64
|
|
72
|
-
def _game(g, a)
|
73
|
-
g.inspect
|
74
|
-
end
|
65
|
+
def _game(g, a); g.inspect; end
|
75
66
|
|
76
|
-
def _save(g, a)
|
77
|
-
g.save
|
78
|
-
end
|
67
|
+
def _save(g, a); pretty_rescue { g.save; "Game saved." }; end
|
79
68
|
|
80
|
-
def
|
81
|
-
|
82
|
-
end
|
69
|
+
def _read_savefile(g, a); pretty_rescue { g.read_savefile }; end
|
70
|
+
|
71
|
+
def _load(g, a); pretty_rescue { g.load; "Game loaded." }; end
|
72
|
+
|
73
|
+
def _quit(g, a); exit; end
|
83
74
|
end
|
84
|
-
end
|
75
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class FuntimeError < StandardError; end
|
data/lib/the_game/game.rb
CHANGED
@@ -8,6 +8,7 @@ class TheGame::Game
|
|
8
8
|
def initialize
|
9
9
|
TheGame.initialize!
|
10
10
|
@created_at = Time.now
|
11
|
+
@saved_at = Time.now
|
11
12
|
@name = "anonymous"
|
12
13
|
@level = 1
|
13
14
|
end
|
@@ -15,36 +16,34 @@ class TheGame::Game
|
|
15
16
|
def yaml_dump
|
16
17
|
YAML.dump({
|
17
18
|
'created_at' => @created_at,
|
19
|
+
'saved_at' => @saved_at,
|
18
20
|
'name' => @name,
|
19
|
-
'level' => @level
|
20
|
-
'config' => {},
|
21
|
-
'the_game' => {
|
22
|
-
'version' => TheGame::Version::STRING
|
23
|
-
}
|
21
|
+
'level' => @level
|
24
22
|
})
|
25
23
|
end
|
24
|
+
|
25
|
+
def load(savefile = TheGame::SAVEFILE_PATH)
|
26
|
+
yaml = YAML.load(read_savefile(savefile))
|
27
|
+
@created_at = yaml['created_at']
|
28
|
+
@saved_at = yaml['saved_at']
|
29
|
+
@name = yaml['name']
|
30
|
+
@level = yaml['level']
|
31
|
+
end
|
26
32
|
|
27
33
|
def save(savefile = TheGame::SAVEFILE_PATH)
|
28
|
-
|
29
|
-
|
30
|
-
Zlib::GzipWriter.open(savefile, Zlib::BEST_COMPRESSION) { |gz| gz << yaml_dump }
|
31
|
-
rescue => e
|
32
|
-
r = e
|
33
|
-
end
|
34
|
-
r || "Game saved."
|
34
|
+
@saved_at = Time.now
|
35
|
+
Zlib::GzipWriter.open(savefile, Zlib::BEST_COMPRESSION) { |gz| gz << yaml_dump }
|
35
36
|
end
|
36
|
-
|
37
|
-
|
37
|
+
|
38
|
+
def read_savefile(savefile = TheGame::SAVEFILE_PATH)
|
39
|
+
Zlib::GzipReader.open(savefile) { |gz| gz.read }
|
40
|
+
end
|
41
|
+
|
38
42
|
def set(key, value)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else raise ArgumentError, "Cannot set #{key}!" end
|
44
|
-
rescue Exception => e
|
45
|
-
return e
|
46
|
-
end
|
47
|
-
true
|
43
|
+
case key.downcase.to_sym
|
44
|
+
when :name then @name = value
|
45
|
+
when :level then @level = value
|
46
|
+
else raise ArgumentError, "Cannot set #{key}!" end
|
48
47
|
end
|
49
48
|
|
50
49
|
# Names are green,
|
@@ -55,14 +54,18 @@ class TheGame::Game
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def start!
|
58
|
-
#TheGame.opts.parse!
|
59
57
|
puts "~ the_game.rb v#{TheGame::Version::STRING} ~\nuse `help` for available commands"
|
60
58
|
|
61
59
|
trap(:INT) { puts; exit }
|
62
60
|
|
63
61
|
loop do
|
64
|
-
|
62
|
+
input = ::Readline.readline(prompt, true)
|
63
|
+
output = begin
|
64
|
+
TheGame::Command.send(self, input)
|
65
|
+
rescue => e
|
66
|
+
e.pp
|
67
|
+
end
|
65
68
|
puts output unless output.blank?
|
66
69
|
end
|
67
70
|
end
|
68
|
-
end
|
71
|
+
end
|
@@ -1,4 +1,9 @@
|
|
1
1
|
require 'the_game/helpers'
|
2
|
+
require 'the_game/helpers/string'
|
3
|
+
require 'the_game/helpers/object'
|
4
|
+
require 'the_game/helpers/exception'
|
5
|
+
|
6
|
+
include TheGame::Helpers
|
2
7
|
|
3
8
|
class String #:nodoc:
|
4
9
|
include TheGame::Helpers::StringHelpers
|
@@ -6,4 +11,8 @@ end
|
|
6
11
|
|
7
12
|
class Object #:nodoc:
|
8
13
|
include TheGame::Helpers::ObjectHelpers
|
9
|
-
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Exception #:nodoc:
|
17
|
+
include TheGame::Helpers::ExceptionHelpers
|
18
|
+
end
|
data/lib/the_game/helpers.rb
CHANGED
@@ -2,7 +2,18 @@
|
|
2
2
|
# require 'the_game/helpers/import'
|
3
3
|
# will bring include these helpers within their respective classes.
|
4
4
|
|
5
|
-
module TheGame::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module TheGame::Helpers
|
6
|
+
def pretty_rescue(default_value = false, &b)
|
7
|
+
return_value = default_value
|
8
|
+
begin
|
9
|
+
return_value = yield if block_given?
|
10
|
+
rescue => error
|
11
|
+
return_value = error.pp
|
12
|
+
end
|
13
|
+
if default_value
|
14
|
+
return_value || default_value
|
15
|
+
else
|
16
|
+
return_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/the_game/license.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module TheGame
|
2
2
|
LICENSE = "the_game Copyright (C) 2012 Shigeki Kitajima
|
3
|
-
|
4
3
|
<http://shigeki.99k.org/the_game/>
|
5
4
|
|
6
5
|
This program is open source: you can redistribute it and/or modify it under the
|
7
6
|
terms of the MIT License. This program is distributed in the hope that it will
|
8
7
|
be useful, but WITHOUT ANY WARRANTY.
|
9
|
-
|
10
8
|
<http://opensource.org/licenses/MIT/>"
|
11
9
|
end
|
data/lib/the_game/version.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
|
1
|
+
if RUBY_VERSION < "1.9"
|
2
|
+
puts "Sorry, the_game only works with ruby >= 1.9 right now."
|
3
|
+
exit
|
4
|
+
end
|
2
5
|
|
3
6
|
module TheGame
|
4
7
|
module Version
|
5
|
-
STRING = "0.
|
8
|
+
STRING = "0.1.a"
|
6
9
|
ARRAY = STRING.split('.')
|
7
10
|
MAJOR = ARRAY[0]
|
8
11
|
MINOR = ARRAY[1]
|
9
12
|
BUILD = ARRAY[2]
|
10
13
|
end
|
11
|
-
end
|
14
|
+
end
|
data/lib/the_game.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.a
|
5
|
+
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Shigeki Kitajima
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &15848100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15848100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &15847620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15847620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &15847140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15847140
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &15846660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *15846660
|
58
58
|
description: the_game is a text-based game written in Ruby, but it doesn't do much
|
59
59
|
right now.
|
60
60
|
email: shigeki.kitajima@gmail.com
|
@@ -71,11 +71,14 @@ files:
|
|
71
71
|
- lib/the_game.rb
|
72
72
|
- lib/the_game/cli.rb
|
73
73
|
- lib/the_game/command.rb
|
74
|
+
- lib/the_game/exception.rb
|
74
75
|
- lib/the_game/game.rb
|
75
76
|
- lib/the_game/helpers.rb
|
77
|
+
- lib/the_game/helpers/exception.rb
|
76
78
|
- lib/the_game/helpers/import.rb
|
77
79
|
- lib/the_game/helpers/object.rb
|
78
80
|
- lib/the_game/helpers/string.rb
|
81
|
+
- lib/the_game/item.rb
|
79
82
|
- lib/the_game/license.rb
|
80
83
|
- lib/the_game/version.rb
|
81
84
|
homepage: http://shigeki.99k.org/the_game/
|
@@ -93,13 +96,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
segments:
|
95
98
|
- 0
|
96
|
-
hash:
|
99
|
+
hash: 901862298871238973
|
97
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
101
|
none: false
|
99
102
|
requirements:
|
100
|
-
- - ! '
|
103
|
+
- - ! '>'
|
101
104
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
105
|
+
version: 1.3.1
|
103
106
|
requirements: []
|
104
107
|
rubyforge_project:
|
105
108
|
rubygems_version: 1.8.13
|