Permalink
Browse files

player rests, monsters killed, rests taken, and items taken are all l…

…ogged and display on exit
  • Loading branch information...
michaelchadwick committed Jul 6, 2015
1 parent 4dfaf44 commit 775bdc38e2f968e07c5e299cca52615a596a7723
View
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'json', '~> 1.8.2'
spec.add_runtime_dependency 'colorize', '~> 0.7.7'
spec.add_runtime_dependency 'feep', '~> 0.1.3'
spec.add_runtime_dependency 'clocker', '~> 0.1.1'
spec.add_runtime_dependency 'clocker', '~> 0.1.2'
#spec.add_runtime_dependency 'hr', '~> 0.0.2'
#spec.add_runtime_dependency 'wordnik', '~> 4.12'
View
@@ -223,7 +223,12 @@ def monster_dead?
def monster_death
puts "You have defeated #{monster.name}!\n".colorize(:green)
# stats
world.player.monsters_killed += 1
if monster.is_boss
# end game boss!
if monster.name.eql?("Emerald")
Music::cue([
{:freq_or_note => 'G3', :duration => 50},
@@ -12,36 +12,42 @@ class Player < Creature
include PlayerLevels
attr_accessor :stam_cur, :stam_max, :cur_coords,
:god_mode, :beast_mode, :use_wordnik
:god_mode, :beast_mode, :use_wordnik,
:monsters_killed, :items_taken, :movements_made, :rests_taken
def initialize(options)
self.name = generate_name
self.description = options.fetch(:description)
self.use_wordnik = options.fetch(:use_wordnik)
self.face = generate_face(use_wordnik)
self.hands = generate_hands(use_wordnik)
self.mood = generate_mood(use_wordnik)
self.level = options.fetch(:level)
self.xp = options.fetch(:xp)
self.hp_cur = options.fetch(:hp_cur)
self.hp_max = options.fetch(:hp_max)
self.atk_lo = options.fetch(:atk_lo)
self.atk_hi = options.fetch(:atk_hi)
self.defense = options.fetch(:defense)
self.dexterity = options.fetch(:dexterity)
self.name = generate_name
self.description = options.fetch(:description)
self.use_wordnik = options.fetch(:use_wordnik)
self.face = generate_face(use_wordnik)
self.hands = generate_hands(use_wordnik)
self.mood = generate_mood(use_wordnik)
self.level = options.fetch(:level)
self.xp = options.fetch(:xp)
self.hp_cur = options.fetch(:hp_cur)
self.hp_max = options.fetch(:hp_max)
self.atk_lo = options.fetch(:atk_lo)
self.atk_hi = options.fetch(:atk_hi)
self.defense = options.fetch(:defense)
self.dexterity = options.fetch(:dexterity)
self.inventory = Inventory.new
self.rox = options.fetch(:rox)
self.inventory = Inventory.new
self.rox = options.fetch(:rox)
self.stam_cur = options.fetch(:stam_cur)
self.stam_max = options.fetch(:stam_max)
self.cur_coords = options.fetch(:cur_coords)
self.stam_cur = options.fetch(:stam_cur)
self.stam_max = options.fetch(:stam_max)
self.cur_coords = options.fetch(:cur_coords)
self.god_mode = options.fetch(:god_mode)
self.beast_mode = options.fetch(:beast_mode)
self.god_mode = options.fetch(:god_mode)
self.beast_mode = options.fetch(:beast_mode)
self.monsters_killed = 0
self.items_taken = 0
self.movements_made = 0
self.rests_taken = 0
end
def check_self(debug_mode = false, show_pic = true)
@@ -76,11 +82,11 @@ def check_self(debug_mode = false, show_pic = true)
self_text << "Current status - breathing, wearing clothing, and with a few other specific characteristics: face is #{self.face}, hands are #{self.hands}, and general mood is #{self.mood}.\n"
end
def rest(world)
cur_loc = world.location_by_coords(cur_coords)
if cur_loc.has_monster?
if cur_loc.should_spawn_monster?
chance_of_ambush = rand(0..100)
if chance_of_ambush < 25
@@ -89,16 +95,19 @@ def rest(world)
end
end
# stats
self.rests_taken += 1
hours = rand(1..23)
minutes = rand(1..59)
seconds = rand(1..59)
hours_text = hours == 1 ? "hour" : "hours"
mins_text = minutes == 1 ? "minute" : "minutes"
secs_text = seconds == 1 ? "second" : "seconds"
Animation::run({:phrase => '** Zzzzz **'})
if self.inventory.has_item?('tent') || world.location_by_coords(cur_coords).has_item?('tent')
self.hp_cur = self.hp_max
@@ -132,7 +141,7 @@ def modify_name
return "New name, '#{name}', accepted."
end
end
def list_inventory
inventory.list_contents
end
@@ -169,33 +178,36 @@ def go(locations, direction, sound)
direction_text = '<<<'
end
print_traveling_text(direction_text, sound)
# stats
self.movements_made += 1
end
def attack(world, monster)
battle = Battle.new({:world => world, :player => self, :monster => monster})
battle.start
end
def has_weapon_equipped?
self.inventory.weapon
end
def cur_weapon_name
if has_weapon_equipped?
return " with your #{inventory.weapon.name}"
else
return nil
end
end
def take_damage(dmg)
self.hp_cur = self.hp_cur - dmg.to_i
if hp_cur <= 0
player_death
end
end
def heal_damage(dmg)
self.hp_cur = self.hp_cur + dmg.to_i
if self.hp_cur > self.hp_max
@@ -211,7 +223,7 @@ def player_death
exit(0)
end
# TRAVEL
# TRAVEL
def print_traveling_text(direction_text, sound)
Animation::run({:oneline => false, :phrase => "* #{direction_text} *"})
if sound
@@ -254,7 +254,7 @@ def evaluate(input)
if param1.nil?
ERROR_TAKE_PARAM_MISSING
else
world.player.inventory.add_item(world.location_by_coords(world.player.cur_coords), param1)
world.player.inventory.add_item(world.location_by_coords(world.player.cur_coords), param1, world.player)
end
when 'use', 'u'
if param1.nil?
@@ -81,12 +81,16 @@ def unequip_item(item_name)
end
end
def add_item(cur_loc, item_name)
def add_item(cur_loc, item_name, player)
cur_loc.items.each do |i|
if i.name.eql?(item_name)
if i.takeable
items.push(i)
cur_loc.remove_item(item_name)
# stats
player.items_taken += 1
return "Added #{item_name} to your increasing collection of bits of tid."
else
return ERROR_ITEM_ADD_UNTAKEABLE
View
@@ -30,8 +30,22 @@ def start(initialCommand = nil)
clocker = Clocker.new
at_exit do
pl = world.player
duration = clocker.stop
puts "Gem Warrior played for #{duration[:secs]} secs and #{duration[:ms]} ms"
puts '######################################################################'
puts
print 'Gem Warrior'.colorize(:color => :white, :background => :black)
print " played for #{duration[:mins].to_s.colorize(:color => :white, :background => :black)} minutes, #{duration[:secs].to_s.colorize(:color => :white, :background => :black)} seconds, and #{duration[:ms].to_s.colorize(:color => :white, :background => :black)} milliseconds\n"
puts '----------------------------------------------------------------------'
print "Player killed #{pl.monsters_killed.to_s.colorize(:color => :white, :background => :black)} monster(s)"
print "\n".ljust(8)
print "picked up #{pl.items_taken.to_s.colorize(:color => :white, :background => :black)} item(s)"
print "\n".ljust(8)
print "traveled #{pl.movements_made.to_s.colorize(:color => :white, :background => :black)} time(s)"
print "\n".ljust(8)
print "rested #{pl.rests_taken.to_s.colorize(:color => :white, :background => :black)} time(s)"
puts
puts '######################################################################'
end
clocker.clock {

0 comments on commit 775bdc3

Please sign in to comment.