Last active
December 15, 2015 00:09
-
-
Save ewilliam/5171037 to your computer and use it in GitHub Desktop.
Initialize prob
This file contains 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 Herbivore < Player | |
before_save :set_values | |
def set_values | |
self.xp = 0 | |
self.max_xp = 50 | |
self.hp = 5 | |
self.max_hp = 5 | |
self.ap = 3 | |
self.max_ap = 3 | |
self.lvl = 1 | |
end | |
end | |
class Carnivore < Player | |
after_initialize :set_values | |
def set_values | |
self.xp = 0 | |
self.max_xp = 50 | |
self.hp = 3 | |
self.max_hp = 3 | |
self.ap = 5 | |
self.max_ap = 5 | |
self.lvl = 1 | |
end | |
end | |
class Omnivore < Player | |
def initialize(attibutes = {}) | |
super | |
self.xp = 0 | |
self.max_xp = 50 | |
self.hp = 4 | |
self.max_hp = 4 | |
self.ap = 4 | |
self.max_ap = 4 | |
self.lvl = 1 | |
end | |
end | |
class Player < User | |
end | |
# == Schema Information | |
# | |
# Table name: users | |
# | |
# id :integer not null, primary key | |
# name :string(255) | |
# email :string(255) | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# password_digest :string(255) | |
# remember_token :string(255) | |
# admin :boolean default(FALSE) | |
# lvl :integer default(1) | |
# xp :integer default(0) | |
# max_xp :integer default(1) | |
# hp :integer default(0) | |
# max_hp :integer default(1) | |
# ap :integer default(0) | |
# max_ap :integer default(1) | |
# type :string(255) | |
# | |
class User < ActiveRecord::Base | |
attr_accessible :name, :email, :password, :password_confirmation, :lvl, :xp, :hp, :ap, :max_xp, :max_hp, :max_ap, :type | |
has_secure_password | |
before_save { email.downcase! } | |
before_save :create_remember_token | |
validates :name, presence: true, length: { maximum: 50 } | |
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, | |
uniqueness: { case_sensitive: false } | |
# validates :password, presence: true, length: { minimum: 6 } | |
# validates :password_confirmation, presence: true | |
# For Single Table Inheritance | |
def self.inherited(child) | |
child.instance_eval do | |
def model_name | |
User.model_name | |
end | |
end | |
super | |
end | |
def self.select_options | |
descendants.map{ |c| c.to_s }.sort | |
end | |
private | |
def create_remember_token | |
self.remember_token = SecureRandom.urlsafe_base64 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment