vg_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9b282b64b932f3a174a30fcf47838e721f69d6f
4
+ data.tar.gz: 20ae43f5a778cd72b21a3e406088a36d69c4a0c3
5
+ SHA512:
6
+ metadata.gz: 42439b618db0e05e503103c2163f19134501b797495c996c5471a8a145d063827cba511eacf842df4a7683a212d6de9ab6251be13165f152adb2d1404a0d3c30
7
+ data.tar.gz: a84b738ae46b6ca269db74a27a15de081a01ca16c5df3bcc2a232717108b86e22c78e53d35a866c15919e82a8237fa1bc033d4eb427b01ed566fbb3da894ed23
@@ -0,0 +1,15 @@
1
+ module CheckingMethods
2
+ def moved_to_a_valid_square?
3
+ %w{▒ ╔ ═ ╗ ╝ ╚ ║}.none? { |character| current_square_on_map.include?(character) }
4
+ end
5
+
6
+ def win?
7
+ current_square_on_map == target
8
+ end
9
+
10
+ private
11
+
12
+ def current_square_on_map
13
+ map[current_square[0]][current_square[1]]
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module MoveMethods
2
+ def move_up
3
+ current_square[0] -= 1
4
+ end
5
+
6
+ def move_down
7
+ current_square[0] += 1
8
+ end
9
+
10
+ def move_left
11
+ current_square[1] -= 1
12
+ end
13
+
14
+ def move_right
15
+ current_square[1] += 1
16
+ end
17
+ end
@@ -0,0 +1,87 @@
1
+ module PlaceBlocks
2
+
3
+ def add_block(row,col,want_print=true,options={color: :purple})
4
+ block_placement("▒ ",row,col,want_print,options)
5
+ end
6
+
7
+ def remove_block(row,col,want_print=true,options={color: :purple})
8
+ block_placement("¤ ",row,col,want_print,options)
9
+ end
10
+
11
+ def add_many_blocks(block_array,want_print=true)
12
+ many_blocks_placement("▒ ", block_array, want_print)
13
+ end
14
+
15
+ def remove_many_blocks(block_array,want_print=true)
16
+ many_blocks_placement("¤ ", block_array, want_print)
17
+ end
18
+
19
+ #write method to report the custom settinges
20
+ def print_settings
21
+ @settings[:starting_player_location] = current_square
22
+ @settings[:blocks] = []
23
+ map.each_with_index do |row, row_i|
24
+ row.each_with_index do |col, col_i|
25
+ if col.include?("▒")
26
+ @settings[:blocks] << [row_i,col_i]
27
+ end
28
+ end
29
+ end
30
+
31
+ puts ""
32
+ puts ""
33
+ puts <<-set_report
34
+ Settings Report
35
+ ------------------------------------------
36
+
37
+ PASTE EVERYTHING BELOW INTO
38
+ THE SESSIONS OPTIONS
39
+ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
40
+
41
+
42
+ {
43
+ set_report
44
+ @settings.each.with_index do |pair, index|
45
+ if pair[0] == :map
46
+ puts " map: {"
47
+ puts " rows: #{pair[1][:rows]},"
48
+ puts " cols: #{pair[1][:cols]}"
49
+ line = " }"
50
+ line += "," if index != @settings.length - 1
51
+ puts line
52
+ else
53
+ line = " #{pair[0]}: #{pair[1]}"
54
+ line += "," if index != @settings.length - 1
55
+ puts line
56
+ end
57
+ end
58
+ puts "}"
59
+ puts ""
60
+ puts ""
61
+ puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
62
+ true
63
+ end
64
+
65
+ private
66
+
67
+ def block_update_print(character,row,col,color)
68
+ show_map = dup_map
69
+ show_map[row][col] = character.send(color)
70
+ print_map(show_map)
71
+ end
72
+
73
+ def block_placement(character,row,col,want_print,options)
74
+ map[row][col] = character
75
+ block_update_print(character,row,col,options[:color]) if want_print
76
+ options[:alt_map][row][col] = character.send(options[:color]) if options[:alt_map]
77
+ end
78
+
79
+ def many_blocks_placement(character, block_array, want_print)
80
+ block_array.each { |block| block_placement("▒ ",block[0],block[1],false,{color: :purple})}
81
+ if want_print
82
+ show_map = dup_map
83
+ block_array.each { |block| block_placement("▒ ",block[0],block[1], false, alt_map: show_map, color: :purple)}
84
+ print_map(show_map)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,39 @@
1
+ module UpdateMap
2
+ def reset_screen
3
+ print "\e[2J\e[H"
4
+ end
5
+
6
+ def reset_map
7
+ self.presenting_map = dup_map
8
+ end
9
+
10
+
11
+ def place_character(alt_map=nil)
12
+ if alt_map
13
+ alt_map[current_square[0]][current_square[1]] = character
14
+ else
15
+ presenting_map[current_square[0]][current_square[1]] = character
16
+ end
17
+ end
18
+
19
+ def print_map(map_array=nil)
20
+ (map_array || presenting_map).each { |row| puts row.join("") }
21
+ end
22
+
23
+ def update_and_print
24
+ reset_screen
25
+ reset_map
26
+ place_character
27
+ print_map
28
+ end
29
+
30
+ private
31
+ def deep_dup(array)
32
+ dup_array = array.dup
33
+ dup_array.map! { |element| element.dup }
34
+ end
35
+
36
+ def dup_map
37
+ map.dup.map! { |e| deep_dup(e) }
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module VgTools
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vg_tools.rb ADDED
@@ -0,0 +1,162 @@
1
+ require "vg_tools/version"
2
+ require 'helper_tools/move_methods'
3
+ require 'helper_tools/update_map'
4
+ require 'helper_tools/place_blocks'
5
+ require 'helper_tools/checking_methods'
6
+
7
+ class String
8
+ {red: 31, green: 32, yellow: 33, purple: 34, pink: 35, blue: 36, white: 37, black: 30}.each { |color, key| define_method("#{color}") { "\e[#{key}m#{self}\e[0m" }}
9
+ end
10
+
11
+
12
+ class Maze
13
+ include UpdateMap
14
+ include PlaceBlocks
15
+
16
+ attr_accessor :character,
17
+ :not_finished,
18
+ :current_square,
19
+ :target,
20
+ :error_message,
21
+ :map,
22
+ :target_location,
23
+ :winner,
24
+ :presenting_map
25
+
26
+ def initialize(options_hash={})
27
+ extend CheckingMethods unless options_hash[:checking_methods] == false
28
+ extend MoveMethods unless options_hash[:move_methods] == false
29
+ @character = options_hash[:character] || "🚶 "
30
+ @target = options_hash[:target] || "🍪 "
31
+ @current_square = options_hash[:starting_player_location] ? check_coordinates("player", options_hash[:starting_player_location],options_hash[:map]) : [1,1]
32
+ @target_location = options_hash[:target_location] ? check_coordinates("target", options_hash[:target_location],options_hash[:map]) : [7,11]
33
+ @map = build_map(options_hash[:map])
34
+ add_many_blocks(options_hash[:blocks],false) if options_hash[:blocks]
35
+ @not_finished = true
36
+ @error_message = @winner = false
37
+ @settings = options_hash
38
+ end
39
+
40
+ def self.session(options_hash={})
41
+ game_session = self.new(options_hash)
42
+ unless options_hash[:skip_intro]
43
+ dots = ""
44
+ 4.times do
45
+ game_session.reset_screen
46
+ puts "Starting New Session#{dots}"
47
+ sleep 0.6
48
+ dots += "."
49
+ end
50
+ game_session.reset_screen
51
+
52
+ puts <<-oview
53
+ Game Created
54
+ =========================================
55
+ Charater: #{game_session.character}
56
+ Starting Space:
57
+ Row: #{game_session.current_square[0]}
58
+ Col: #{game_session.current_square[1]}
59
+ Target: #{game_session.target}
60
+ Target Location:
61
+ Row: #{game_session.target_location[0]}
62
+ Col: #{game_session.target_location[1]}
63
+ =========================================
64
+ oview
65
+
66
+ game_session.reset_map
67
+ game_session.place_character
68
+ game_session.print_map
69
+ sleep 2
70
+ end
71
+ game_session
72
+ end
73
+
74
+ def play
75
+ # reset_screen;
76
+ start_time = Time.now.to_f
77
+ yield(self)
78
+ end_time = Time.now.to_f
79
+ time_difference = (end_time - start_time).round(3)
80
+ # minutes = time_difference / 60
81
+ # seconds = time_difference % 60
82
+ # total_time = ""
83
+ # total_time += "#{minutes} Minute" if minutes > 0
84
+ # total_time += "s" if minutes > 1
85
+ # total_time += ", " if minutes > 0 && seconds > 0
86
+ # total_time += "#{seconds} Second" if seconds > 0
87
+ # total_time += "s" if seconds > 1
88
+ puts "Total Time: #{time_difference}"
89
+ end
90
+
91
+ private
92
+
93
+ def build_map(map_options)
94
+ if map_options && map_options[:rows] > 0 && map_options[:cols] > 0
95
+ column_count = map_options[:cols]
96
+ row_count = map_options[:rows]
97
+ if current_square[0] <= row_count && current_square[1] <= column_count && target_location[0] <= row_count && target_location[1] <= column_count
98
+ map_array = []
99
+ map_array << ["╔═"] + ["══"] * column_count + ["╗"]
100
+ row_count.times { map_array << ["║ "] + ["¤ "] * column_count + ["║"] }
101
+ map_array << ["╚═"] + ["══"] * column_count + ["╝"]
102
+ else
103
+ reset_screen
104
+ puts <<-dmap_problem
105
+ There was a problem!
106
+
107
+ Map must be big enough to include show character and target.
108
+ dmap_problem
109
+ exit
110
+ end
111
+ else
112
+ map_array = [["╔═","══","══","══","══","══","══","══","══","══","══","══","══","╗"],
113
+ ["║ ","¤ ","▒ ","¤ ","¤ ","▒ ","¤ ","¤ ","¤ ","▒ ","¤ ","¤ ","¤ ","║"],
114
+ ["║ ","¤ ","▒ ","▒ ","¤ ","¤ ","¤ ","▒ ","¤ ","▒ ","¤ ","▒ ","¤ ","║"],
115
+ ["║ ","¤ ","▒ ","▒ ","▒ ","¤ ","▒ ","▒ ","¤ ","▒ ","¤ ","▒ ","¤ ","║"],
116
+ ["║ ","¤ ","¤ ","¤ ","¤ ","¤ ","▒ ","¤ ","¤ ","▒ ","¤ ","▒ ","¤ ","║"],
117
+ ["║ ","¤ ","▒ ","¤ ","▒ ","¤ ","¤ ","¤ ","▒ ","¤ ","¤ ","▒ ","¤ ","║"],
118
+ ["║ ","¤ ","▒ ","¤ ","▒ ","▒ ","▒ ","▒ ","▒ ","¤ ","▒ ","▒ ","¤ ","║"],
119
+ ["║ ","¤ ","▒ ","¤ ","¤ ","¤ ","¤ ","¤ ","¤ ","¤ ","▒ ","¤ ","¤ ","║"],
120
+ ["╚═","══","══","══","══","══","══","══","══","══","══","══","══","╝"]]
121
+
122
+ end
123
+ map_array[target_location[0]][target_location[1]] = target
124
+ map_array
125
+ end
126
+
127
+ def check_coordinates(subject, coord_array, map_options)
128
+ if map_options && map_options[:rows] > 0 && map_options[:cols] > 0
129
+ if map_options[:rows] >= coord_array[0] && coord_array[0] > 0 && map_options[:cols] >= coord_array[1] && coord_array[1] > 0
130
+ coord_array
131
+ else
132
+ reset_screen
133
+ puts <<-cmap_problem
134
+ There was a problem!
135
+
136
+ You are trying to place your #{subject} on row #{coord_array[0]}, column #{coord_array[1]}
137
+ Map size is currently: #{map_options[:rows]} Rows x #{map_options[:cols]} Columns
138
+
139
+ Please adjust your settings and try again
140
+ cmap_problem
141
+ exit
142
+ end
143
+ else
144
+ if 7 >= coord_array[0] && coord_array[0] > 0 && 12 >= coord_array[1] && coord_array[1] > 0
145
+ coord_array
146
+ else
147
+ reset_screen
148
+ puts <<-dmap_problem
149
+ There was a problem!
150
+
151
+ You are trying to place your #{subject} on row #{coord_array[0]}, column #{coord_array[1]}
152
+ The default map size is: 7 Rows x 12 Columns
153
+
154
+ Please adjust your settings and try again
155
+ dmap_problem
156
+ exit
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vg_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JackMarx
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem was developed to provide tools for beginner ruby students making
56
+ terminal based videogames and cultivating a taste for programming in the ruby language.
57
+ email:
58
+ - seriousfools@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/helper_tools/checking_methods.rb
64
+ - lib/helper_tools/move_methods.rb
65
+ - lib/helper_tools/place_blocks.rb
66
+ - lib/helper_tools/update_map.rb
67
+ - lib/vg_tools.rb
68
+ - lib/vg_tools/version.rb
69
+ homepage: https://github.com/acltc/vg_tools
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ - lib/helper_tools
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: To help teach programing terminal videogames in ruby
94
+ test_files: []