dexter_plusplus 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,184 @@
1
+ class Pokemon
2
+
3
+ extend Findable
4
+
5
+ attr_accessor :name, :moves, :abilities, :base_stats, :height, :weight, :generation, :types, :url, :id, :data
6
+ @@all = []
7
+ @@tag = "pokemon"
8
+ @@limit = 807
9
+
10
+ #do not load any pokemon outside of these id #'s
11
+ CONST_GENERATIONS = [151, 251, 386, 493, 649, 721, 807]
12
+
13
+ def initialize(name, url)
14
+ self.name = name
15
+ self.url = url
16
+ self.data = JSON.parse(RestClient.get(url))
17
+ self.moves = []
18
+ self.abilities = []
19
+ self.types = []
20
+ self.base_stats = []
21
+ self.set_attributes
22
+ @@all << self
23
+ end
24
+
25
+ def self.all
26
+ @@all
27
+ end
28
+
29
+ def tag
30
+ @@tag
31
+ end
32
+
33
+ def self.tag
34
+ @@tag
35
+ end
36
+
37
+ def self.limit
38
+ @@limit
39
+ end
40
+
41
+ def set_attributes
42
+ self.set_moves
43
+ self.set_abilities
44
+ self.set_types
45
+ self.set_id
46
+ self.set_generation
47
+ self.set_height
48
+ self.set_weight
49
+ self.set_base_stats
50
+ end
51
+
52
+ def set_moves
53
+ move_array = Move.find_from_array(self.data["moves"].first(4))
54
+ move_array.each{|move| self.add_move(move)}
55
+ end
56
+
57
+ def set_abilities
58
+ ability_array = Ability.find_from_array(self.data["abilities"])
59
+ ability_array.each{|ability| self.add_ability(ability)}
60
+ end
61
+
62
+ def set_types
63
+ type_array = Type.find_from_array(self.data["types"])
64
+ type_array.each{|type| self.add_type(type)}
65
+ end
66
+
67
+ def set_id
68
+ self.id = self.data["id"]
69
+ end
70
+
71
+ def set_height
72
+ self.height = self.data["height"]
73
+ end
74
+
75
+ def set_weight
76
+ self.weight = self.data["weight"]
77
+ end
78
+
79
+
80
+ #set generation by using id number (make constants with generation numbers)
81
+ def set_generation
82
+ i = 0
83
+ while i < CONST_GENERATIONS.size && self.generation.nil?
84
+ if self.id > CONST_GENERATIONS[i]
85
+ i += 1
86
+ else
87
+ self.generation = i + 1
88
+ end
89
+ end
90
+ end
91
+
92
+ def set_base_stats
93
+ stats = self.data["stats"]
94
+ stats.each do |stat|
95
+ self.base_stats << "#{stat["stat"]["name"]}: #{stat["base_stat"]}"
96
+ end
97
+ end
98
+
99
+ def add_move(move)
100
+ self.moves << move
101
+ if !move.pokemon_with_move.include?(self)
102
+ move.add_pokemon(self)
103
+ end
104
+ end
105
+
106
+ def add_ability(ability)
107
+ self.abilities << ability
108
+ if !ability.pokemon_with_ability.include?(self)
109
+ ability.add_pokemon(self)
110
+ end
111
+ end
112
+
113
+ def add_type(type)
114
+ self.types << type
115
+ if !type.pokemon_with_type.include?(self)
116
+ type.add_pokemon(self)
117
+ end
118
+ end
119
+
120
+ def print_all
121
+ puts "---------------------------------------------------------"
122
+ puts " Dexter++ : Pokemon ".light_yellow
123
+ puts "---------------------------------------------------------"
124
+ self.print_name
125
+ puts ""
126
+ self.print_generation
127
+ self.print_weight_and_height
128
+ puts ""
129
+ self.print_types
130
+ puts ""
131
+ self.print_abilities
132
+ puts ""
133
+ self.print_moves
134
+ puts ""
135
+ self.print_base_stats
136
+ puts "---------------------------------------------------------"
137
+ end
138
+
139
+ def self.print_all
140
+ self.all.each{|pokemon| pokemon.print_all}
141
+ end
142
+
143
+ def print_name
144
+ puts "Name: #{self.name.capitalize.light_yellow}"
145
+ end
146
+
147
+ def get_colored_name
148
+ self.name.capitlize.light_yellow
149
+ end
150
+
151
+ def print_types
152
+ output = "\tTypes:\n"
153
+ self.types.each_with_index{|type, index| output += "\t\t#{index + 1}: #{type.print_name(type.name)}\n"}
154
+ puts output
155
+ end
156
+
157
+ def print_abilities
158
+ output = "\tAbilities:\n"
159
+ self.abilities.each_with_index{|ability, index| output += "\t\t#{index + 1}: #{ability.get_colored_name}\n"}
160
+ puts output
161
+ end
162
+
163
+ def print_moves
164
+ output = "\tMoves:\n"
165
+ self.moves.each_with_index{|move, index| output += "\t\t#{index + 1}: #{move.get_colored_name}\n"}
166
+ puts output
167
+ end
168
+
169
+ def print_base_stats
170
+ output = "\tBase Stats:\n"
171
+ self.base_stats.each{|stat| output += "\t\t#{stat.capitalize}\n"}
172
+ puts output
173
+ end
174
+
175
+ def print_weight_and_height
176
+ puts "\tHeight: #{self.height}"
177
+ puts "\tWeight: #{self.weight}"
178
+ end
179
+
180
+ def print_generation
181
+ puts "\tGeneration: #{self.generation}"
182
+ end
183
+
184
+ end
@@ -0,0 +1,182 @@
1
+ class PokemonMenu
2
+
3
+ attr_accessor :cli
4
+
5
+ def initialize(cli)
6
+ self.cli = cli
7
+ end
8
+
9
+ def main_menu
10
+ puts"\n\n"
11
+ input = self.cli.prompt.select("What Pokemon information would you like to get?", cycle: true) do |menu|
12
+ menu.choice 'Get a list of Pokemon.', 1
13
+ menu.choice 'Search for Pokemon by name', 2
14
+ menu.choice 'Search for Pokemon by Type', 3
15
+ menu.choice 'Search for Pokemon by Ability', 4
16
+ menu.choice 'Search for Pokemon by Generation', 5
17
+ menu.choice 'Get information from a random Pokemon', 6
18
+ menu.choice 'Return to main menu'.light_green, 7
19
+ menu.choice 'Exit Dexter++'.light_red, 8
20
+ end
21
+ case input
22
+ when 1
23
+ self.list_pokemon
24
+ when 2
25
+ self.search_by_name
26
+ when 3
27
+ self.search_by_type
28
+ when 4
29
+ self.search_by_ability
30
+ when 5
31
+ self.search_by_generation
32
+ when 6
33
+ self.get_random
34
+ when 7
35
+ self.cli.main_menu
36
+ when 8
37
+ self.cli.exit_program
38
+ end
39
+ end
40
+
41
+ def list_pokemon
42
+ puts "\n\nHow many Pokemon would you like to list?"
43
+ input = gets.strip.to_i
44
+ until input.between?(1, Pokemon.limit)
45
+ if input <= 0
46
+ puts"\nThat is not enough Pokemon! Try a bigger number"
47
+ input = gets.strip.to_i
48
+ else
49
+ puts "\nThats way too many Pokemon! Try a smaller number."
50
+ input = gets.strip.to_i
51
+ end
52
+ end
53
+ puts "\n\nAwesome! Let me load that for you."
54
+ options = Pokemon.find_with_offset_and_limit(rand(0...Pokemon.limit), input)
55
+ self.display_pokemon_options(options)
56
+ end
57
+
58
+ def search_by_name
59
+ puts "\n\nWhat Pokemon would you like to search for?"
60
+ input = gets.strip.downcase
61
+ puts "\n\nAwesome! Let me load that for you."
62
+ pokemon = API.get_pokemon_by_name(input)
63
+ pokemon.print_all
64
+ puts"\n\n"
65
+ self.display_more_options(pokemon)
66
+ end
67
+
68
+ def search_by_type(type = nil)
69
+ if type
70
+ puts "\n\nAwesome! Let me load that for you."
71
+ puts "\n\n"
72
+ options = Pokemon.find_list_by_type(type.name)
73
+ self.display_pokemon_options(options)
74
+ else
75
+ puts "\n\n"
76
+ options = ["Normal","Flying","Poison","Ground",
77
+ "Rock","Bug","Ghost","Steel","Fire",
78
+ "Water","Grass","Electric","Psychic",
79
+ "Ice","Dragon","Dark","Fairy","Unknown",
80
+ "Shadow","Return to main menu".light_green, "Exit Dexter++".light_red]
81
+
82
+ input = self.cli.prompt.select("Select a type to search for.", options, cycle: true)
83
+ end
84
+
85
+ case input
86
+ when "Return to main menu".light_green
87
+ self.cli.main_menu
88
+ when "Exit Dexter++".light_red
89
+ self.cli.exit_program
90
+ else
91
+ puts "\n\nAwesome! Let me load that for you."
92
+ puts "\n\n"
93
+ options = Pokemon.find_list_by_type(input.downcase)
94
+ self.display_pokemon_options(options)
95
+ end
96
+ end
97
+
98
+ def search_by_ability(ability = nil)
99
+ if ability
100
+ puts "\n\nAwesome! Let me load that for you."
101
+ puts "\n\n"
102
+ options = API.get_pokemon_list_by_ability(ability.name)
103
+ self.display_pokemon_options(options)
104
+ else
105
+ puts "\n\nWhat Ability would you like your Pokemon to have?"
106
+ input = gets.strip.downcase
107
+ puts "\n\nAwesome! Let me load that for you."
108
+ puts "\n\n"
109
+ options = API.get_pokemon_list_by_ability(input)
110
+ self.display_pokemon_options(options)
111
+ end
112
+ end
113
+
114
+ def search_by_generation
115
+ puts "\n\nWhat Generation of Pokemon would you like to list?"
116
+ puts "\n\n"
117
+ input = self.generation_menu
118
+ puts "\n\nAwesome! Let me load that for you."
119
+ options = API.get_pokemon_list_by_generation(input)
120
+ self.display_pokemon_options(options)
121
+ end
122
+
123
+ def get_random
124
+ pokemon = API.get_random_pokemon
125
+ pokemon.print_all
126
+ puts"\n\n"
127
+ self.display_more_options(pokemon)
128
+ end
129
+
130
+ def generation_menu
131
+ choices = [1,2,3,4,5,6,7,"Back"]
132
+ self.cli.prompt.select("Select a generation to search for.", choices, cycle: true)
133
+ end
134
+
135
+ def display_pokemon_options(options)
136
+ puts "\n\n"
137
+ options.unshift("Exit Dexter++".light_red)
138
+ options.unshift("Go back to main menu".light_green)
139
+ choice = self.cli.get_menu_from_array(options)
140
+ if choice == "Exit Dexter++".light_red
141
+ self.cli.exit_program
142
+ elsif choice == "Go back to main menu".light_green
143
+ self.cli.main_menu
144
+ else pokemon = API.get_pokemon_by_name(choice.downcase)
145
+ pokemon.print_all
146
+ puts"\n\n"
147
+ self.display_more_options(pokemon)
148
+ end
149
+ end
150
+
151
+ def display_more_options(pokemon)
152
+ puts "\n\n"
153
+ input = self.cli.prompt.select("What information about #{pokemon.name.capitalize} would you like to see?", cycle: true) do |menu|
154
+ menu.choice 'Type information.', 1
155
+ menu.choice 'Moves information', 2
156
+ menu.choice 'Abilities information', 3
157
+ menu.choice 'Go back to main menu'.light_green, 4
158
+ menu.choice 'Exit Dexter++'.light_red, 5
159
+ end
160
+
161
+ case input
162
+ when 1
163
+ pokemon.types.each{|type| type.print_all}
164
+ puts "\n\n"
165
+ self.display_more_options(pokemon)
166
+ when 2
167
+ pokemon.moves.each{|move| move.print_all}
168
+ puts "\n\n"
169
+ self.display_more_options(pokemon)
170
+ when 3
171
+ pokemon.abilities.each {|ability| ability.print_all}
172
+ puts "\n\n"
173
+ self.display_more_options(pokemon)
174
+ when 4
175
+ self.cli.main_menu
176
+ when 5
177
+ self.cli.exit_program
178
+ end
179
+ end
180
+
181
+
182
+ end
@@ -0,0 +1,183 @@
1
+ class Type
2
+ extend Findable
3
+
4
+ attr_accessor :name, :id, :moves, :pokemon_with_type, :damage_relations, :data, :url
5
+ @@all = []
6
+ @@tag = "type"
7
+ @@limit = 20
8
+
9
+ def initialize(name, url)
10
+ self.name = name
11
+ self.url = url
12
+ self.data = JSON.parse(RestClient.get(url))
13
+ self.moves = []
14
+ self.pokemon_with_type = []
15
+ self.damage_relations = {}
16
+ self.set_attributes
17
+ @@all << self
18
+ end
19
+
20
+ def set_attributes
21
+ self.id = self.data["id"]
22
+ self.set_damage_relations
23
+ end
24
+
25
+ def self.all
26
+ @@all
27
+ end
28
+
29
+ def self.tag
30
+ @@tag
31
+ end
32
+
33
+ def self.limit
34
+ @@limit
35
+ end
36
+
37
+ def tag
38
+ @@tag
39
+ end
40
+
41
+ def add_pokemon(pokemon)
42
+ self.pokemon_with_type << pokemon
43
+ end
44
+
45
+ def add_move(move)
46
+ if !self.moves.include?(move)
47
+ self.moves << move
48
+ end
49
+ end
50
+
51
+ def set_damage_relations
52
+ self.damage_relations["double_damage_to"] = self.get_double_damage_to
53
+ self.damage_relations["double_damage_from"] = self.get_double_damage_from
54
+ self.damage_relations["half_damage_to"] = self.get_half_damage_to
55
+ self.damage_relations["half_damage_from"] = self.get_half_damage_from
56
+ self.damage_relations["no_damage_to"] = self.get_no_damage_to
57
+ self.damage_relations["no_damage_from"] = self.get_no_damage_from
58
+ end
59
+
60
+ def get_double_damage_to
61
+ output = []
62
+ types = self.data["damage_relations"]["double_damage_to"]
63
+ types.each{|type| output << type["name"]}
64
+ output
65
+ end
66
+
67
+ def get_double_damage_from
68
+ output = []
69
+ types = self.data["damage_relations"]["double_damage_from"]
70
+ types.each{|type| output << type["name"]}
71
+ output
72
+ end
73
+
74
+ def get_half_damage_to
75
+ output = []
76
+ types = self.data["damage_relations"]["half_damage_to"]
77
+ types.each{|type| output << type["name"]}
78
+ output
79
+ end
80
+
81
+ def get_half_damage_from
82
+ output = []
83
+ types = self.data["damage_relations"]["half_damage_from"]
84
+ types.each{|type| output << type["name"]}
85
+ output
86
+ end
87
+
88
+ def get_no_damage_to
89
+ output = []
90
+ types = self.data["damage_relations"]["no_damage_to"]
91
+ types.each{|type| output << type["name"]}
92
+ output
93
+ end
94
+
95
+ def get_no_damage_from
96
+ output = []
97
+ types = self.data["damage_relations"]["no_damage_from"]
98
+ types.each{|type| output << type["name"]}
99
+ output
100
+ end
101
+
102
+ def print_all
103
+ puts "---------------------------------------------------------"
104
+ puts " Dexter++ : Type ".light_magenta
105
+ puts "---------------------------------------------------------"
106
+ puts "Name: #{self.print_name(self.name)}"
107
+ puts ""
108
+ self.print_damage_relations
109
+ puts "---------------------------------------------------------"
110
+ end
111
+
112
+ def self.print_all
113
+ self.all.each{|type| type.print_all}
114
+ end
115
+
116
+ def print_name(name)
117
+ case name
118
+ when "normal"
119
+ name.capitalize.light_black.on_white
120
+ when "fighting"
121
+ name.capitalize.light_red.on_black
122
+ when "flying"
123
+ name.capitalize.light_white.on_magenta
124
+ when "poison"
125
+ name.capitalize.light_green.on_magenta
126
+ when "ground"
127
+ name.capitalize.yellow.on_light_white
128
+ when "bug"
129
+ name.capitalize.light_white.on_green
130
+ when "rock"
131
+ name.capitalize.red.on_yellow
132
+ when "ghost"
133
+ name.capitalize.black.on_light_magenta
134
+ when "steel"
135
+ name.capitalize.light_white.on_light_black
136
+ when "fire"
137
+ name.capitalize.black.on_light_red
138
+ when "water"
139
+ name.capitalize.blue.on_light_blue
140
+ when "grass"
141
+ name.capitalize.green.on_light_cyan
142
+ when "electric"
143
+ name.capitalize.black.on_light_yellow
144
+ when "psychic"
145
+ name.capitalize.light_magenta.on_magenta
146
+ when "ice"
147
+ name.capitalize.light_white.on_cyan
148
+ when "dragon"
149
+ name.capitalize.light_white.on_light_red
150
+ when "dark"
151
+ name.capitalize.light_white.on_black
152
+ when "fairy"
153
+ name.capitalize.light_magenta.on_light_white
154
+ when "unkown"
155
+ name.capitalize.black.on_cyan
156
+ when "shadow"
157
+ name.capitalize.light_magenta.on_light_black
158
+ else
159
+ name.capitalize
160
+ end
161
+ end
162
+
163
+ def print_damage_relations
164
+ puts "Damage Relations:"
165
+ puts "\tDouble damage to:"
166
+ self.damage_relations["double_damage_to"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
167
+ puts ""
168
+ puts "\tDouble damage from:"
169
+ self.damage_relations["double_damage_from"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
170
+ puts ""
171
+ puts "\tHalf damage to:"
172
+ self.damage_relations["half_damage_to"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
173
+ puts ""
174
+ puts "\tHalf damage from:"
175
+ self.damage_relations["half_damage_from"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
176
+ puts ""
177
+ puts "\tNo damage to:"
178
+ self.damage_relations["no_damage_to"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
179
+ puts ""
180
+ puts "\tNo damage from:"
181
+ self.damage_relations["no_damage_from"].each_with_index{|name, index| puts "\t\t\t#{index + 1}: #{self.print_name(name)}"}
182
+ end
183
+ end