turtle_in_the_sand 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +125 -0
- data/LICENSE.txt +20 -0
- data/README.md +16 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/turtle_game +18 -0
- data/lib/turtle_game.rb +5 -0
- data/lib/turtle_game/cli.rb +33 -0
- data/lib/turtle_game/command.rb +121 -0
- data/lib/turtle_game/commands/.gitkeep +1 -0
- data/lib/turtle_game/commands/turtle.rb +40 -0
- data/lib/turtle_game/game.rb +68 -0
- data/lib/turtle_game/templates/.gitkeep +1 -0
- data/lib/turtle_game/templates/turtle/.gitkeep +1 -0
- data/lib/turtle_game/version.rb +3 -0
- data/turtle_game.gemspec +49 -0
- metadata +389 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a14abd9c4dc660a1b17fc754d1c4512aec9a1ec58994a579ca8f1d046f8cc85
|
4
|
+
data.tar.gz: 33f75eb1f8ff628949934418d78486b21d560a6ffb487f9039c77d3873c76716
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31c656af21915db3d7bc8645130015cd412b8d4c7f993220e7a723c92a407ce7317f166275987763bc830a2d0f60f2249160d19a3a0770824465f6c33a0f81ae
|
7
|
+
data.tar.gz: cf9a07a571b8bf30d4627c7dbf910ef1f2088b2eb4828d208f072729192bc9af28c89b0aadbab11f4dff892ed0616961a33d2c23c7a42915e845e7451fd49dcf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at danielsteele@hotmail.co.uk. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
turtle_in_the_sand (0.1.0)
|
5
|
+
pastel (~> 0.7.2)
|
6
|
+
thor (~> 0.19.4)
|
7
|
+
tty-color (~> 0.4.2)
|
8
|
+
tty-command (~> 0.7.0)
|
9
|
+
tty-cursor (~> 0.5.0)
|
10
|
+
tty-editor (~> 0.3.0)
|
11
|
+
tty-file (~> 0.5.0)
|
12
|
+
tty-font (~> 0.2.0)
|
13
|
+
tty-markdown (~> 0.3.0)
|
14
|
+
tty-pager (~> 0.11.0)
|
15
|
+
tty-platform (~> 0.1.0)
|
16
|
+
tty-progressbar (~> 0.13.0)
|
17
|
+
tty-prompt (~> 0.14.0)
|
18
|
+
tty-reader (~> 0.2.0)
|
19
|
+
tty-screen (~> 0.6.4)
|
20
|
+
tty-spinner (~> 0.8.0)
|
21
|
+
tty-table (~> 0.10.0)
|
22
|
+
tty-tree (~> 0.1.0)
|
23
|
+
tty-which (~> 0.3.0)
|
24
|
+
|
25
|
+
GEM
|
26
|
+
remote: https://rubygems.org/
|
27
|
+
specs:
|
28
|
+
coderay (1.1.2)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
equatable (0.5.0)
|
31
|
+
hitimes (1.2.6)
|
32
|
+
kramdown (1.16.2)
|
33
|
+
method_source (0.9.0)
|
34
|
+
necromancer (0.4.0)
|
35
|
+
pastel (0.7.2)
|
36
|
+
equatable (~> 0.5.0)
|
37
|
+
tty-color (~> 0.4.0)
|
38
|
+
pry (0.11.3)
|
39
|
+
coderay (~> 1.1.0)
|
40
|
+
method_source (~> 0.9.0)
|
41
|
+
rake (10.5.0)
|
42
|
+
rouge (3.1.1)
|
43
|
+
rspec (3.7.0)
|
44
|
+
rspec-core (~> 3.7.0)
|
45
|
+
rspec-expectations (~> 3.7.0)
|
46
|
+
rspec-mocks (~> 3.7.0)
|
47
|
+
rspec-core (3.7.1)
|
48
|
+
rspec-support (~> 3.7.0)
|
49
|
+
rspec-expectations (3.7.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.7.0)
|
52
|
+
rspec-mocks (3.7.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.7.0)
|
55
|
+
rspec-support (3.7.1)
|
56
|
+
strings (0.1.1)
|
57
|
+
unicode-display_width (~> 1.3.0)
|
58
|
+
unicode_utils (~> 1.4.0)
|
59
|
+
thor (0.19.4)
|
60
|
+
timers (4.1.2)
|
61
|
+
hitimes
|
62
|
+
tty-color (0.4.2)
|
63
|
+
tty-command (0.7.0)
|
64
|
+
pastel (~> 0.7.0)
|
65
|
+
tty-cursor (0.5.0)
|
66
|
+
tty-editor (0.3.0)
|
67
|
+
tty-prompt (~> 0.14.0)
|
68
|
+
tty-which (~> 0.3.0)
|
69
|
+
tty-file (0.5.0)
|
70
|
+
diff-lcs (~> 1.3.0)
|
71
|
+
pastel (~> 0.7.2)
|
72
|
+
tty-prompt (~> 0.14.0)
|
73
|
+
tty-font (0.2.0)
|
74
|
+
tty-markdown (0.3.0)
|
75
|
+
kramdown (~> 1.16.2)
|
76
|
+
pastel (~> 0.7.2)
|
77
|
+
rouge (~> 3.1.0)
|
78
|
+
strings (~> 0.1.0)
|
79
|
+
tty-color (~> 0.4.2)
|
80
|
+
tty-screen (~> 0.6.4)
|
81
|
+
tty-pager (0.11.0)
|
82
|
+
strings (~> 0.1.0)
|
83
|
+
tty-screen (~> 0.6.4)
|
84
|
+
tty-which (~> 0.3.0)
|
85
|
+
tty-platform (0.1.0)
|
86
|
+
tty-progressbar (0.13.0)
|
87
|
+
tty-cursor (~> 0.5.0)
|
88
|
+
tty-screen (~> 0.6.0)
|
89
|
+
tty-prompt (0.14.0)
|
90
|
+
necromancer (~> 0.4.0)
|
91
|
+
pastel (~> 0.7.0)
|
92
|
+
timers (~> 4.1.2)
|
93
|
+
tty-cursor (~> 0.5.0)
|
94
|
+
tty-reader (~> 0.2.0)
|
95
|
+
tty-reader (0.2.0)
|
96
|
+
tty-cursor (~> 0.5.0)
|
97
|
+
tty-screen (~> 0.6.4)
|
98
|
+
wisper (~> 2.0.0)
|
99
|
+
tty-screen (0.6.4)
|
100
|
+
tty-spinner (0.8.0)
|
101
|
+
tty-cursor (>= 0.5.0)
|
102
|
+
tty-table (0.10.0)
|
103
|
+
equatable (~> 0.5.0)
|
104
|
+
necromancer (~> 0.4.0)
|
105
|
+
pastel (~> 0.7.2)
|
106
|
+
strings (~> 0.1.0)
|
107
|
+
tty-screen (~> 0.6.4)
|
108
|
+
tty-tree (0.1.0)
|
109
|
+
tty-which (0.3.0)
|
110
|
+
unicode-display_width (1.3.0)
|
111
|
+
unicode_utils (1.4.0)
|
112
|
+
wisper (2.0.0)
|
113
|
+
|
114
|
+
PLATFORMS
|
115
|
+
ruby
|
116
|
+
|
117
|
+
DEPENDENCIES
|
118
|
+
bundler (~> 1.16)
|
119
|
+
pry
|
120
|
+
rake (~> 10.0)
|
121
|
+
rspec (~> 3.0)
|
122
|
+
turtle_in_the_sand!
|
123
|
+
|
124
|
+
BUNDLED WITH
|
125
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Daniel Steele
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# The turtle
|
2
|
+
|
3
|
+
Cos reasons
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
```
|
7
|
+
gem install turtle_in_the_sand
|
8
|
+
```
|
9
|
+
|
10
|
+
### Usage
|
11
|
+
```
|
12
|
+
turtle_game turtle
|
13
|
+
```
|
14
|
+
|
15
|
+
By default it will grab your entire terminal size.
|
16
|
+
Otherwise, you can pass an optional int to set the screen size, eg `turtle_game turtle 20`
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "turtle_game"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/turtle_game
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
5
|
+
$:.unshift(lib_path) if !$:.include?(lib_path)
|
6
|
+
require 'turtle_game/cli'
|
7
|
+
|
8
|
+
Signal.trap('INT') do
|
9
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
TurtleGame::CLI.start
|
15
|
+
rescue TurtleGame::CLI::Error => err
|
16
|
+
puts "ERROR: #{err.message}"
|
17
|
+
exit 1
|
18
|
+
end
|
data/lib/turtle_game.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module TurtleGame
|
6
|
+
# Handle the application command line parsing
|
7
|
+
# and the dispatch to various command objects
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class CLI < Thor
|
11
|
+
# Error raised by this runner
|
12
|
+
Error = Class.new(StandardError)
|
13
|
+
|
14
|
+
desc 'version', 'turtle_game version'
|
15
|
+
def version
|
16
|
+
require_relative 'version'
|
17
|
+
puts "v#{TurtleGame::VERSION}"
|
18
|
+
end
|
19
|
+
map %w(--version -v) => :version
|
20
|
+
|
21
|
+
desc 'turtle [WIDTH]', 'Start the game with an optional board width modifier'
|
22
|
+
method_option :help, aliases: '-h', type: :boolean,
|
23
|
+
desc: 'Display usage information'
|
24
|
+
def turtle(width = nil)
|
25
|
+
if options[:help]
|
26
|
+
invoke :help, ['turtle']
|
27
|
+
else
|
28
|
+
require_relative 'commands/turtle'
|
29
|
+
TurtleGame::Commands::Turtle.new(width, options).execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module TurtleGame
|
6
|
+
class Command
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :command, :run
|
10
|
+
|
11
|
+
# Execute this command
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
def execute(*)
|
15
|
+
raise(
|
16
|
+
NotImplementedError,
|
17
|
+
"#{self.class}##{__method__} must be implemented"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The external commands runner
|
22
|
+
#
|
23
|
+
# @see http://www.rubydoc.info/gems/tty-command
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
def command(**options)
|
27
|
+
require 'tty-command'
|
28
|
+
TTY::Command.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# The cursor movement
|
32
|
+
#
|
33
|
+
# @see http://www.rubydoc.info/gems/tty-cursor
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
def cursor
|
37
|
+
require 'tty-cursor'
|
38
|
+
TTY::Cursor
|
39
|
+
end
|
40
|
+
|
41
|
+
# Open a file or text in the user's preferred editor
|
42
|
+
#
|
43
|
+
# @see http://www.rubydoc.info/gems/tty-editor
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def editor
|
47
|
+
require 'tty-editor'
|
48
|
+
TTY::Editor
|
49
|
+
end
|
50
|
+
|
51
|
+
# File manipulation utility methods
|
52
|
+
#
|
53
|
+
# @see http://www.rubydoc.info/gems/tty-file
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def generator
|
57
|
+
require 'tty-file'
|
58
|
+
TTY::File
|
59
|
+
end
|
60
|
+
|
61
|
+
# Terminal output paging
|
62
|
+
#
|
63
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def pager(**options)
|
67
|
+
require 'tty-pager'
|
68
|
+
TTY::Pager.new(options)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Terminal platform and OS properties
|
72
|
+
#
|
73
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
74
|
+
#
|
75
|
+
# @api public
|
76
|
+
def platform
|
77
|
+
require 'tty-platform'
|
78
|
+
TTY::Platform.new
|
79
|
+
end
|
80
|
+
|
81
|
+
# The interactive prompt
|
82
|
+
#
|
83
|
+
# @see http://www.rubydoc.info/gems/tty-prompt
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def prompt(**options)
|
87
|
+
require 'tty-prompt'
|
88
|
+
TTY::Prompt.new(options)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get terminal screen properties
|
92
|
+
#
|
93
|
+
# @see http://www.rubydoc.info/gems/tty-screen
|
94
|
+
#
|
95
|
+
# @api public
|
96
|
+
def screen
|
97
|
+
require 'tty-screen'
|
98
|
+
TTY::Screen
|
99
|
+
end
|
100
|
+
|
101
|
+
# The unix which utility
|
102
|
+
#
|
103
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
def which(*args)
|
107
|
+
require 'tty-which'
|
108
|
+
TTY::Which.which(*args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Check if executable exists
|
112
|
+
#
|
113
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
114
|
+
#
|
115
|
+
# @api public
|
116
|
+
def exec_exist?(*args)
|
117
|
+
require 'tty-which'
|
118
|
+
TTY::Which.exist?(*args)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require_relative '../game'
|
5
|
+
require 'tty-reader'
|
6
|
+
require 'pry'
|
7
|
+
module TurtleGame
|
8
|
+
module Commands
|
9
|
+
class Turtle < TurtleGame::Command
|
10
|
+
attr_accessor :move_input
|
11
|
+
|
12
|
+
def initialize(width, options)
|
13
|
+
@width = width
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(input: $stdin, output: $stdout)
|
18
|
+
put_instructions(output)
|
19
|
+
game = TurtleGame::Game.new(@width, output)
|
20
|
+
loop do
|
21
|
+
move_input = TTY::Reader.new.read_char
|
22
|
+
break if move_input == 'x'
|
23
|
+
game.move(move_input)
|
24
|
+
end
|
25
|
+
output.puts 'Thanks for playing'
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def put_instructions(output)
|
31
|
+
output.puts <<~INSTRUCTIONS
|
32
|
+
|
33
|
+
Use WASD to move your tutle
|
34
|
+
Use X to exit
|
35
|
+
|
36
|
+
INSTRUCTIONS
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module TurtleGame
|
2
|
+
class Game
|
3
|
+
|
4
|
+
MOVESET = { 'w' => :up, 'a' => :left, 's' => :down, 'd' => :right }.freeze
|
5
|
+
INDEX_MODIFIERS = { up: [-1, 0], left: [0, -1], down: [1, 0], right: [0, 1] }
|
6
|
+
|
7
|
+
attr_accessor :move_history, :current_move, :matrix, :output
|
8
|
+
|
9
|
+
def initialize(width = nil, output)
|
10
|
+
@width = width
|
11
|
+
@output = output
|
12
|
+
@move_history = []
|
13
|
+
@matrix = fetch_dimensions
|
14
|
+
end
|
15
|
+
|
16
|
+
def move(direction)
|
17
|
+
move_history << parse_direction(direction)
|
18
|
+
flush
|
19
|
+
build_matrix
|
20
|
+
output.puts stringify_matrix
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def stringify_matrix
|
26
|
+
output = []
|
27
|
+
matrix.each_with_index do |y_axis, index|
|
28
|
+
matrix[index].each { |x_value| output << x_value }
|
29
|
+
output << "\n"
|
30
|
+
end
|
31
|
+
output.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_direction(input)
|
35
|
+
MOVESET[input.strip.downcase]
|
36
|
+
end
|
37
|
+
|
38
|
+
def flush
|
39
|
+
$stdout.flush
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_matrix
|
43
|
+
last_move = [0, 0]
|
44
|
+
move_history.each_with_index do |move, i|
|
45
|
+
index_modifiers = INDEX_MODIFIERS[move]
|
46
|
+
last_move = last_move.zip(index_modifiers).map(&:sum)
|
47
|
+
matrix[last_move[0]][last_move[1]] = last_move?(i) ? '🐢' : '#'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def last_move?(i)
|
52
|
+
move_history.length == i + 1
|
53
|
+
end
|
54
|
+
|
55
|
+
def fetch_screen_size
|
56
|
+
dimensions = TTY::Screen.size
|
57
|
+
Array.new(dimensions[0]) { ' ' }.map { Array.new(dimensions[1]) { ' ' } }
|
58
|
+
end
|
59
|
+
|
60
|
+
def fetch_dimensions
|
61
|
+
if @width
|
62
|
+
Array.new(width) { ' ' }.map { Array.new(width) { ' ' } }
|
63
|
+
else
|
64
|
+
fetch_screen_size
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/turtle_game.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "turtle_game/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "turtle_in_the_sand"
|
8
|
+
spec.license = "MIT"
|
9
|
+
spec.version = TurtleGame::VERSION
|
10
|
+
spec.authors = ["Daniel Steele"]
|
11
|
+
spec.email = ["danielsteele@hotmail.co.uk"]
|
12
|
+
|
13
|
+
spec.summary = %q{A turtle is leaving a trail in the sand}
|
14
|
+
spec.description = %q{a command line experient}
|
15
|
+
spec.homepage = "https://github.com/dansteele/turtle-game"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
|
25
|
+
spec.add_dependency "tty-reader", "~> 0.2.0"
|
26
|
+
spec.add_dependency "tty-color", "~> 0.4.2"
|
27
|
+
spec.add_dependency "tty-command", "~> 0.7.0"
|
28
|
+
spec.add_dependency "tty-cursor", "~> 0.5.0"
|
29
|
+
spec.add_dependency "tty-editor", "~> 0.3.0"
|
30
|
+
spec.add_dependency "tty-file", "~> 0.5.0"
|
31
|
+
spec.add_dependency "tty-font", "~> 0.2.0"
|
32
|
+
spec.add_dependency "tty-markdown", "~> 0.3.0"
|
33
|
+
spec.add_dependency "tty-pager", "~> 0.11.0"
|
34
|
+
spec.add_dependency "tty-platform", "~> 0.1.0"
|
35
|
+
spec.add_dependency "tty-progressbar", "~> 0.13.0"
|
36
|
+
spec.add_dependency "tty-prompt", "~> 0.14.0"
|
37
|
+
spec.add_dependency "tty-screen", "~> 0.6.4"
|
38
|
+
spec.add_dependency "tty-spinner", "~> 0.8.0"
|
39
|
+
spec.add_dependency "tty-table", "~> 0.10.0"
|
40
|
+
spec.add_dependency "tty-tree", "~> 0.1.0"
|
41
|
+
spec.add_dependency "tty-which", "~> 0.3.0"
|
42
|
+
spec.add_dependency "pastel", "~> 0.7.2"
|
43
|
+
spec.add_dependency "thor", "~> 0.19.4"
|
44
|
+
|
45
|
+
spec.add_development_dependency "pry"
|
46
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
47
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
48
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,389 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turtle_in_the_sand
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Steele
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tty-reader
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tty-color
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-command
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-cursor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-editor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tty-file
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-font
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: tty-markdown
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.3.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.3.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: tty-pager
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.11.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.11.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: tty-platform
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.1.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.1.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: tty-progressbar
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.13.0
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.13.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: tty-prompt
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.14.0
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.14.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: tty-screen
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.6.4
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.6.4
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: tty-spinner
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 0.8.0
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.8.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: tty-table
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 0.10.0
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.10.0
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: tty-tree
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 0.1.0
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 0.1.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: tty-which
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - "~>"
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: 0.3.0
|
244
|
+
type: :runtime
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 0.3.0
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: pastel
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: 0.7.2
|
258
|
+
type: :runtime
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: 0.7.2
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: thor
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 0.19.4
|
272
|
+
type: :runtime
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: 0.19.4
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: pry
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - ">="
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
286
|
+
type: :development
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - ">="
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0'
|
293
|
+
- !ruby/object:Gem::Dependency
|
294
|
+
name: bundler
|
295
|
+
requirement: !ruby/object:Gem::Requirement
|
296
|
+
requirements:
|
297
|
+
- - "~>"
|
298
|
+
- !ruby/object:Gem::Version
|
299
|
+
version: '1.16'
|
300
|
+
type: :development
|
301
|
+
prerelease: false
|
302
|
+
version_requirements: !ruby/object:Gem::Requirement
|
303
|
+
requirements:
|
304
|
+
- - "~>"
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
version: '1.16'
|
307
|
+
- !ruby/object:Gem::Dependency
|
308
|
+
name: rake
|
309
|
+
requirement: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - "~>"
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '10.0'
|
314
|
+
type: :development
|
315
|
+
prerelease: false
|
316
|
+
version_requirements: !ruby/object:Gem::Requirement
|
317
|
+
requirements:
|
318
|
+
- - "~>"
|
319
|
+
- !ruby/object:Gem::Version
|
320
|
+
version: '10.0'
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: rspec
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - "~>"
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: '3.0'
|
328
|
+
type: :development
|
329
|
+
prerelease: false
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
331
|
+
requirements:
|
332
|
+
- - "~>"
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: '3.0'
|
335
|
+
description: a command line experient
|
336
|
+
email:
|
337
|
+
- danielsteele@hotmail.co.uk
|
338
|
+
executables:
|
339
|
+
- turtle_game
|
340
|
+
extensions: []
|
341
|
+
extra_rdoc_files: []
|
342
|
+
files:
|
343
|
+
- ".gitignore"
|
344
|
+
- ".rspec"
|
345
|
+
- ".travis.yml"
|
346
|
+
- CODE_OF_CONDUCT.md
|
347
|
+
- Gemfile
|
348
|
+
- Gemfile.lock
|
349
|
+
- LICENSE.txt
|
350
|
+
- README.md
|
351
|
+
- Rakefile
|
352
|
+
- bin/console
|
353
|
+
- bin/setup
|
354
|
+
- exe/turtle_game
|
355
|
+
- lib/turtle_game.rb
|
356
|
+
- lib/turtle_game/cli.rb
|
357
|
+
- lib/turtle_game/command.rb
|
358
|
+
- lib/turtle_game/commands/.gitkeep
|
359
|
+
- lib/turtle_game/commands/turtle.rb
|
360
|
+
- lib/turtle_game/game.rb
|
361
|
+
- lib/turtle_game/templates/.gitkeep
|
362
|
+
- lib/turtle_game/templates/turtle/.gitkeep
|
363
|
+
- lib/turtle_game/version.rb
|
364
|
+
- turtle_game.gemspec
|
365
|
+
homepage: https://github.com/dansteele/turtle-game
|
366
|
+
licenses:
|
367
|
+
- MIT
|
368
|
+
metadata: {}
|
369
|
+
post_install_message:
|
370
|
+
rdoc_options: []
|
371
|
+
require_paths:
|
372
|
+
- lib
|
373
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
374
|
+
requirements:
|
375
|
+
- - ">="
|
376
|
+
- !ruby/object:Gem::Version
|
377
|
+
version: '0'
|
378
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
379
|
+
requirements:
|
380
|
+
- - ">="
|
381
|
+
- !ruby/object:Gem::Version
|
382
|
+
version: '0'
|
383
|
+
requirements: []
|
384
|
+
rubyforge_project:
|
385
|
+
rubygems_version: 2.7.3
|
386
|
+
signing_key:
|
387
|
+
specification_version: 4
|
388
|
+
summary: A turtle is leaving a trail in the sand
|
389
|
+
test_files: []
|