Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4631

Refactoring Pokemon type weekness

$
0
0

I made pokemon weekness finder by ruby. It takes a lot of words.Could you suggest bit nice and sophisticated to write this code?

The menu is as follows.

puts "Which type of Pokemon do you want to know weaknesses? Menu  1 Normal  2 Fire  3 Water  4 Electric  5 Grass  6 Ice  7 Fighting  8 Poison  9 Ground  10 Flying  11 Psychic  12 Bug  13 Rock  14 Ghost  15 Dragon  16 Dark  17 Steel  18 Fairy

I then obtain the user's response and print the weakness for their selection.

  type = gets.to_i  case type   when 1 #Normal    puts "Fighting"  when 2  #Fire    puts "Ground, Rock, Water"  when 3 #water    puts "Fire, Ground, Rock"  when 4 #Electric    puts "Ground"  when 5 #Grass    puts "Bug, Fire, Flying, Ice, Poison"  when 6 #Ice    puts "Fighting, Fire, Rock, Steel"  when 7 #Fighting    puts "Fairy, Flying, Psychic"  when 8 #Poison    puts "Ground, Psychic"  when 9 #Ground    puts "Grass, Ice, Water"  when 10 #Flying    puts "Electric, Ice, Rock"  when 11 #Psychic    puts "Bug, Dark, Ghost"  when 12 #Bug    puts "Fire, Flying, Rock"  when 13 #Rock    puts "Fighting, Grass, Ground, Steel, Water"  when 14 #Ghost    puts "Dark, Ghost"  when 15 #Dragon    puts "Dragon, Fairy, Ice"  when 16 #Dark    puts "Bug, Fairy, Fighting"  when 17 #Steel    puts "Fighting, Fire, Ground"  when 18 #Fairy    puts "Poison, Steel"  else    puts "Error"  end

Viewing all articles
Browse latest Browse all 4631

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>