Class: Pokemoves::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pokemoves.rb

Instance Method Summary collapse

Instance Method Details

#check_learnability_of_moveObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pokemoves.rb', line 61

def check_learnability_of_move
  puts "Enter the name of a move!"
  move_name = gets.chomp
  until Move.find_or_create_by_pretty_name(move_name) != nil
    puts "It doesn't look like we have that move stored."
    puts "Try a different one."
    move_name = gets.chomp
  end
  current_move = Move.find_or_create_by_pretty_name(move_name)
  puts "Enter the name of a pokemon to see if they can learn #{current_move.pretty_name}"
  pokemon_name = gets.chomp
  until Pokemon.find_or_create_by_name(pokemon_name.downcase) != nil
    puts "It doesn't look like we have that pokemon stored."
    puts "Try a different one."
    pokemon_name = gets.chomp
  end
  until pokemon_name == "exit"
    current_pokemon = Pokemon.find_or_create_by_name(pokemon_name.downcase)
    if current_pokemon.can_learn_move?(current_move)
      puts "It looks like #{current_pokemon.name.capitalize} can learn #{current_move.pretty_name}."
    else
      puts "It looks like #{current_pokemon.name.capitalize} can't learn #{current_move.pretty_name}."
    end
    puts "Enter the name of another pokemon to see if they can learn #{current_move.pretty_name}."
    puts "Enter \"exit\" to continue to the main menu."
    pokemon_name = gets.chomp
    until Pokemon.find_or_create_by_name(pokemon_name.downcase) != nil || pokemon_name == "exit"
      puts "It doesn't look like we have that pokemon stored."
      puts "Try a different one, or enter \"exit\" to exit."
      pokemon_name = gets.chomp
    end
  end
end

#get_pokemon_move_listObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pokemoves.rb', line 29

def get_pokemon_move_list
  puts "Enter the name of a pokemon."
  pokemon_name = gets.chomp
  until Pokemon.find_or_create_by_name(pokemon_name.downcase) != nil
    puts "It doesn't look like we have that pokemon stored."
    puts "Try a different one."
    pokemon_name = gets.chomp
  end
  current_pokemon = Pokemon.find_or_create_by_name(pokemon_name.downcase)
  puts "Press enter to see a list of #{pokemon_name.capitalize}'s moves."
  gets
  counter = 1
  current_pokemon.get_moves.each{|move|
    puts "#{counter}. #{move.pretty_name}"
  counter += 1
  }
  puts "Enter the number of the move you'd like to know the type of."
  puts "To continue to the main menu, enter -1"
  num = gets.to_i
  until num <= 0
    if(num <= current_pokemon.get_moves.size)
      current_move = Move.find_or_create_by_name(current_pokemon.get_moves[num - 1].name)
      puts "The move #{current_move.pretty_name} is a #{current_move.type} type move."
    else
      puts "That number is not in the list of moves."
    end
    puts "Enter the number of the move you'd like to know the type of."
    puts "Enter -1 to continue to the main menu."
    num = gets.to_i
  end
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pokemoves.rb', line 8

def run
  puts "Welcome to Pokemoves!"
  input = 0
  until input == 3
    puts "Enter 1 to see a list of a pokemon's given moves."
    puts "Enter 2 to see if a certain move is learnable by a pokemon."
    puts "Enter 3 to exit."
    input = gets.to_i
    if input == 1
      get_pokemon_move_list

    elsif input == 2
      check_learnability_of_move
    else
      puts "That isn't a vailid choice." unless input == 3
    end

  end
  
end