the_game 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ source "http://rubygems.org"
3
+ # Add dependencies required to use your gem here.
4
+ # Example:
5
+ # gem "activesupport", ">= 2.3.5"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+ rcov (0.9.11)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.4)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ the_game Copyright (C) 2012 Shigeki Kitajima
2
+
3
+ This program is free software: you can redistribute it and/or modify it under
4
+ the terms of the Creative Commons Public License 3.0 (BY-NC-SA). This program
5
+ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
6
+
7
+ <http://creativecommons.org/licenses/by-nc-sa/3.0/>
data/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = the_game
2
+
3
+ Description goes here.
4
+
5
+ == Installation
6
+
7
+ +the_game+ depends on +gosu+ and +chingu+.
8
+ See the installation guide. https://github.com/jlnr/gosu/wiki/_pages
9
+
10
+ == Contributing to the_game
11
+
12
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
13
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
14
+ * Fork the project
15
+ * Start a feature/bugfix branch
16
+ * Commit and push until you are happy with your contribution
17
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
18
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2012 Shigeki Kitajima. See LICENSE.txt for
23
+ further details.
24
+
data/bin/the_game ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'the_game'
3
+ TheGame::Game.new.start!
@@ -0,0 +1,48 @@
1
+ class TheGame::Command
2
+ class << self
3
+ def send(game, input)
4
+ input.lstrip!
5
+
6
+ # Allow interpolation in the form of $(command) => output of command
7
+ input.gsub!(/\$\((.*)\)/) { send($1.to_s) }
8
+
9
+ unless input.words.empty?
10
+ method = input.words.first.command_sanitize.downcase
11
+ args = input.remove_first_word
12
+
13
+ __send__("_#{method}", game, args)
14
+ end
15
+ end
16
+
17
+ def method_missing(m, g, a)
18
+ "#{m.to_s.command_sanitize}: unknown command"
19
+ end
20
+
21
+ def _args(g, a)
22
+ a.args.inspect
23
+ end
24
+
25
+ def _echo(g, a)
26
+ a
27
+ end
28
+
29
+ def _lol(g, a)
30
+ loop{41.upto(45){|i|print"\e[#{i}m#{" "*((rand*1.01)+1)}\e[0m"};sleep 0.001}
31
+ end
32
+
33
+ def _help(g, a)
34
+ o = "Commands available: ["
35
+ matching_commands = methods(false).select { |m| m.match(/^_/) }
36
+ o << matching_commands.map { |m| m.to_s.command_sanitize }.join(", ")
37
+ o << "]"
38
+ end
39
+
40
+ def _game(g, a)
41
+ g.inspect
42
+ end
43
+
44
+ def _quit(g, a)
45
+ exit
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ require 'readline'
2
+ class TheGame::Game
3
+ attr_accessor :name, :level
4
+
5
+ def initialize
6
+ @name ||= "anonymous"
7
+ @level ||= 1
8
+ end
9
+
10
+ def prompt
11
+ "\e[1;32m#{@name}:#{@level} \e[34m/ $\e[0m "
12
+ end
13
+
14
+ def start!
15
+ #TheGame.opts.parse!
16
+ puts "~ the_game.rb v#{TheGame::Version::STRING} ~\nuse `help` for available commands"
17
+
18
+ trap(:INT) { puts; exit }
19
+
20
+ loop do
21
+ puts TheGame::Command.send(self, ::Readline.readline(prompt, true))
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module TheGame
2
+ LICENSE = <<-ENDLICENSE
3
+ the_game.rb Copyright (C) 2012 Shigeki Kitajima
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the Creative Commons Public License 3.0 (BY-NC-SA). This program
7
+ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
8
+
9
+ <http://creativecommons.org/licenses/by-nc-sa/3.0/>
10
+ ENDLICENSE
11
+ LICENSE.gsub!(/^ +/,'')
12
+ LICENSE.freeze
13
+ end
@@ -0,0 +1,43 @@
1
+ class String
2
+ TRUE_WORDS = %w{t true yes y}
3
+ FALSE_WORDS = %w{f false no n}
4
+
5
+ def numeric?
6
+ !!Float(self) rescue false
7
+ end
8
+
9
+ def command_sanitize
10
+ sub(/^_+/, '')
11
+ end
12
+
13
+ def to_bool
14
+ TRUE_WORDS.include?(self) ? true : FALSE_WORDS.include?(self) ? false : nil
15
+ end
16
+
17
+ def bool?
18
+ !to_bool.nil?
19
+ end
20
+
21
+ def args
22
+ strip!
23
+
24
+ split(/\s/).map do |arg|
25
+ arg = arg.to_s
26
+ next if arg.empty?
27
+ arg.bool? ? arg.to_bool : arg.numeric? ? Float(arg) : arg
28
+ end
29
+ end
30
+
31
+ def args?
32
+ !args.empty?
33
+ end
34
+
35
+ def words
36
+ scan(/\S+/)
37
+ end
38
+
39
+ def remove_first_word
40
+ words = split(/\s/, 2)
41
+ words.length == 2 ? words.last : ''
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module TheGame
2
+ module Version
3
+ STRING = "0.0.1"
4
+ ARRAY = STRING.split('.')
5
+ MAJOR = ARRAY[0]
6
+ MINOR = ARRAY[1]
7
+ TEENY = ARRAY[2]
8
+ end
9
+ end
data/lib/the_game.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'the_game/version'
2
+ require 'the_game/license'
3
+ require 'the_game/string'
4
+ require 'the_game/game'
5
+ require 'the_game/command'
6
+
7
+ module TheGame
8
+ class << self
9
+ @inited = @game = @mode = @opts = nil
10
+
11
+ attr_accessor :mode, :opts
12
+
13
+ # Unless we already did this,
14
+ # store a new Game in @game.
15
+ def initialize!
16
+ unless @inited
17
+ @inited = true
18
+ @game = Game.new
19
+ end
20
+ end
21
+
22
+ # Get @@game or make it.
23
+ def game
24
+ @inited ? @game : initialize!
25
+ end
26
+
27
+ def start!
28
+ initialize!
29
+
30
+ case @mode
31
+ when :play then @game.start!
32
+ when :license then puts LICENSE
33
+ when :version then puts "the_game.rb v#{TheGame::VERSION}"
34
+ else puts @opts end
35
+ end
36
+ end
37
+ end
data/rakefile.rb ADDED
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ $: << File.expand_path("lib")
6
+ require 'the_game/version'
7
+
8
+ begin
9
+ Bundler.setup(:default, :development)
10
+ rescue Bundler::BundlerError => e
11
+ $stderr.puts e.message
12
+ $stderr.puts "Run `bundle install` to install missing gems"
13
+ exit e.status_code
14
+ end
15
+
16
+ require 'rake'
17
+
18
+ require 'jeweler'
19
+ Jeweler::Tasks.new do |gem|
20
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
21
+ gem.name = "the_game"
22
+ gem.homepage = "https://rubygems.org/gems/the_game"
23
+ gem.license = "CC 3.0 (BY-NC-SA)"
24
+ gem.summary = "It's the_game."
25
+ gem.description = "The Game."
26
+ gem.email = "shigeki.kitajima@gmail.com"
27
+ gem.authors = ["Shigeki Kitajima"]
28
+ gem.executables = ['the_game']
29
+ gem.version = TheGame::Version::STRING
30
+ # dependencies defined in Gemfile
31
+ end
32
+ Jeweler::RubygemsDotOrgTasks.new
33
+
34
+ require 'rake/testtask'
35
+ Rake::TestTask.new(:test) do |test|
36
+ test.libs << 'lib' << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+
41
+ require 'rcov/rcovtask'
42
+ Rcov::RcovTask.new do |test|
43
+ test.libs << 'test'
44
+ test.pattern = 'test/**/test_*.rb'
45
+ test.verbose = true
46
+ test.rcov_opts << '--exclude "gems/*"'
47
+ end
48
+
49
+ task :default => :test
50
+
51
+ require 'rdoc/task'
52
+ Rake::RDocTask.new do |rdoc|
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "the_game v#{TheGame::Version::STRING}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'the_game'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ class TestTheGame < Test::Unit::TestCase
4
+ should "exist" do
5
+ assert !!TheGame
6
+ assert !!TheGame::Game
7
+ assert !!TheGame::Command
8
+ assert !!TheGame::Version
9
+ assert !!TheGame::LICENSE
10
+ end
11
+ end
data/the_game.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile.rb, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "the_game"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Shigeki Kitajima"]
12
+ s.date = "2012-01-04"
13
+ s.description = "The Game."
14
+ s.email = "shigeki.kitajima@gmail.com"
15
+ s.executables = ["the_game"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "bin/the_game",
27
+ "lib/the_game.rb",
28
+ "lib/the_game/command.rb",
29
+ "lib/the_game/game.rb",
30
+ "lib/the_game/license.rb",
31
+ "lib/the_game/string.rb",
32
+ "lib/the_game/version.rb",
33
+ "rakefile.rb",
34
+ "test/helper.rb",
35
+ "test/test_the_game.rb",
36
+ "the_game.gemspec"
37
+ ]
38
+ s.homepage = "https://rubygems.org/gems/the_game"
39
+ s.licenses = ["CC 3.0 (BY-NC-SA)"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.13"
42
+ s.summary = "It's the_game."
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Shigeki Kitajima
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: &24707520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *24707520
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &24706520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *24706520
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &24705760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.6.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *24705760
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &24704460 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *24704460
58
+ description: The Game.
59
+ email: shigeki.kitajima@gmail.com
60
+ executables:
61
+ - the_game
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - bin/the_game
73
+ - lib/the_game.rb
74
+ - lib/the_game/command.rb
75
+ - lib/the_game/game.rb
76
+ - lib/the_game/license.rb
77
+ - lib/the_game/string.rb
78
+ - lib/the_game/version.rb
79
+ - rakefile.rb
80
+ - test/helper.rb
81
+ - test/test_the_game.rb
82
+ - the_game.gemspec
83
+ homepage: https://rubygems.org/gems/the_game
84
+ licenses:
85
+ - CC 3.0 (BY-NC-SA)
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -598662081971213311
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.13
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: It's the_game.
111
+ test_files: []