Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Created September 10, 2018 23:11
Show Gist options
  • Save NimaBoscarino/ced9ca9071dbfb7ce1395909b138453b to your computer and use it in GitHub Desktop.
Save NimaBoscarino/ced9ca9071dbfb7ce1395909b138453b to your computer and use it in GitHub Desktop.
Pokemon OOP
class Pokemon
attr_reader :type, :hp
attr_accessor :name
def initialize
@type = nil
@hp = 10
@name = nil
@@message = "Pokemon is a fun game"
end
def tackle enemy
puts "#{@name} did 4 hp damage to #{enemy.name}"
enemy.decreaseHP 4
end
def decreaseHP num
@hp = @hp - num
if (@hp < -3)
puts "STOP HE'S ALREADY DEAD"
end
end
def self.message
@@message
end
end
class GrassPokemon < Pokemon
def initialize
super
@type = 'grass'
end
end
class WaterPokemon < Pokemon
end
class FirePokemon < Pokemon
end
class Bulbasaur < GrassPokemon
# implement some attacks
# initialize
# - set the initial HP
def vineWhip
puts "#{@name} did 9 hp damage"
end
end
class Squirtle < GrassPokemon
# implement some attacks
# initialize
# - set the initial HP
end
class Charmeleon < FirePokemon
# implement some attacks
# initialize
# - set the initial HP
end
kanye = Bulbasaur.new
jayz = Bulbasaur.new
skepta = Charmeleon.new
kanye.name = "Kanye West"
jayz.name = "Jay Z"
skepta.name = "Skepta"
kanye.tackle skepta
puts skepta.hp
jayz.tackle skepta
puts skepta.hp
kanye.tackle skepta
puts skepta.hp
jayz.tackle skepta
puts skepta.hp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment