Created
March 18, 2019 23:20
-
-
Save NimaBoscarino/57a402eecf03311acf520237d585005d 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
class Trainer | |
attr_reader :name | |
def initialize name | |
@name = name | |
end | |
end | |
# a description of what the heck a pokemon is... | |
class Pokemon | |
attr_reader :type | |
# attr_writer :name | |
attr_accessor :name, :health | |
def initialize name, health, trainer | |
@name = name | |
@health = health | |
@trainer = trainer | |
end | |
def attack opponent | |
puts "Attack opponent!" | |
end | |
def getTrainer | |
'The trainer is ' + @trainer.name | |
end | |
# Not by blastoise.description, but by Pokemon.description | |
def self.description | |
'Pokemon is a fun game for all ages!' | |
end | |
# def name= newName | |
# @name = newName | |
# end | |
end | |
class WaterType < Pokemon | |
def initialize name, health, trainer | |
super name, health, trainer | |
@type = 'water' | |
end | |
def attack opponent | |
if opponent.type == 'electric' | |
opponent.health = opponent.health - 10 | |
end | |
end | |
end | |
class ElectricType < Pokemon | |
def initialize name, health, trainer | |
super name, health, trainer | |
@type = 'electric' | |
end | |
def attack opponent | |
if opponent.type == 'water' | |
opponent.health = opponent.health - 20 | |
end | |
end | |
end | |
# There should be a water type and an electric type... | |
puts Pokemon.description | |
nima = Trainer.new 'Nima' | |
kanye = Trainer.new 'Kanye' | |
blastoise = WaterType.new 'Blastoise', 100, nima # GIVE THIS A NAME? | |
pikachu = ElectricType.new 'Pikachu', 36, kanye | |
puts blastoise.name | |
puts blastoise.health | |
puts pikachu.name | |
puts pikachu.health | |
puts blastoise.getTrainer | |
puts pikachu.getTrainer | |
puts blastoise.type | |
puts pikachu.type | |
blastoise.attack pikachu | |
puts 'New pikachu health ' + pikachu.health.to_s | |
pikachu.attack blastoise | |
puts 'New blastoise health ' + blastoise.health.to_s | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
pikachu.attack blastoise | |
puts 'New blastoise health ' + blastoise.health.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment