Created
June 10, 2019 23:26
-
-
Save NimaBoscarino/2c0c09dea6f11146d2dcbb38350705e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the blueprint for THIS thing | |
class Pokemon | |
attr_reader :species, :health | |
attr_accessor :name | |
def initialize species, name | |
# Save the species, save the name | |
@species = species | |
@name = name | |
@health = 100 | |
end | |
def sound | |
puts 'GRAAAAWRRR' | |
end | |
def sayName | |
puts 'I AM ' + @name | |
end | |
def attack enemy | |
puts 'BAH! ATTACK!' | |
enemy.damage Random.rand(10) | |
puts @name + ' attacked ' + enemy.name + '!!' | |
puts enemy.name + ' is now at ' + enemy.health.to_s | |
end | |
def damage hitPoints | |
@health = @health - hitPoints | |
end | |
# def name= name | |
# puts 'I guess you want a new name' | |
# puts 'Your new name will be ' + name | |
# @name = name | |
# end | |
private | |
def woopwoop | |
puts 'woopwoop' | |
end | |
end | |
class ElectricPokemon < Pokemon | |
def initialize species, name | |
@type = 'Electric' | |
super species, name | |
end | |
# SUPER is always a reference to the SAME method, but in the parent class | |
def attack enemy | |
puts 'BZZAAAAP!!!! ⚡️' | |
super enemy | |
end | |
end | |
class WaterPokemon < Pokemon | |
def initialize species, name | |
@type = 'Water' | |
super species, name | |
end | |
def attack enemy | |
puts 'WAVE WAVE WAVE 🌊' | |
super enemy | |
end | |
end | |
lilZap = ElectricPokemon.new "Pikachu", "Lil Zap" | |
squirtleBud = WaterPokemon.new "Squirtle", "Squirtle Bud" | |
puts lilZap | |
puts squirtleBud | |
# lilZap.sayName | |
# squirtleBud.sayName | |
puts lilZap.name | |
puts lilZap.species | |
lilZap.name = "Big Zap" | |
puts lilZap.name | |
until lilZap.health < 1 or squirtleBud.health < 1 | |
lilZap.attack squirtleBud | |
# NonOOP: attack(lilZap, squirtleBud) | |
squirtleBud.attack lilZap | |
end | |
puts 'Final' | |
puts 'LILZAP ' + lilZap.health.to_s | |
puts 'SQUIRTLEBUD ' + squirtleBud.health.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment