Permalink
Browse files

Update wizards.yml to have correct(ish) titles and add linebreaks. Al…

…low the game engine to render an "event" whenever ElRogue occupys the same spaces as a wizard.
  • Loading branch information...
1 parent 1c8847d commit d99d483b3e7c81fb1e920fb5cb06c78717d0e492 @h-lame committed Feb 13, 2012
@@ -3,3 +3,4 @@ source "http://rubygems.org"
gem 'colored'
gem 'trollop'
gem 'highline'
+gem 'artii'
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ artii (1.0.3)
colored (1.2)
highline (1.6.11)
trollop (1.16.2)
@@ -9,6 +10,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ artii
colored
highline
trollop
@@ -10,4 +10,5 @@
require './lib/rogue/game_engine'
require './lib/rogue/creature'
require './lib/rogue/el_rogue'
-require './lib/rogue/wizard'
+require './lib/rogue/wizard'
+require './lib/rogue/event'
@@ -13,5 +13,9 @@ def move_to(x, y)
@x = x
@y = y
end
+
+ def on_top_of?(creature)
+ (creature.x == @x) && (creature.y == @y)
+ end
end
end
@@ -0,0 +1,46 @@
+require 'artii'
+
+module Rogue
+ class Event
+ attr_reader :wizard, :width, :height
+ def initialize(wizard, width, height)
+ @wizard = wizard
+ @width = width
+ @height = height
+ end
+
+ def render!
+ name_font = Artii::Figlet::Font.new("#{Artii::FONTPATH}/#{Artii::Base.new({}).all_fonts['doom']}")
+ talk_font = Artii::Figlet::Font.new("#{Artii::FONTPATH}/#{Artii::Base.new({}).all_fonts['straight']}")
+ name_text = Artii::Figlet::Typesetter.new(name_font)[@wizard.name]
+
+ talk_texts = @wizard.talk.lines.map { |l| Artii::Figlet::Typesetter.new(talk_font, smush: false)[l.chomp] }
+ rendered = "\e[2J\e[f"
+
+ text_height = name_text.lines.count + talk_texts.map{ |t| t.lines.count }.inject(:+) + 4
+ ((height - text_height) / 2).times { rendered += "\n" }
+
+ rendered += center("You found a WIZARD called:")
+ rendered += "\n"
+ rendered += center(name_text, :green)
+ rendered += "\n"
+ rendered += center("who wants to talk to you about:")
+ rendered += "\n"
+ rendered += "\n"
+ talk_texts.each do |talk_text|
+ rendered += center(talk_text, :red)
+ rendered += "\n"
+ end
+
+ puts rendered
+ end
+
+ protected
+ def center(rendered_text, color = :white)
+ text_width = rendered_text.lines.first.chomp.length
+ pad = ((width - text_width) / 2)
+ pad = 0 if pad < 0
+ rendered_text.lines.inject("") { |t, l| t += "#{(" "*pad)}#{l.send(color)}" }
+ end
+ end
+end
@@ -20,7 +20,7 @@ def generator
end
def choose_world!
- chosen = false
+ chosen = 'n'
until chosen == 'y'
w = make_world
renderer.render!(w)
@@ -42,6 +42,7 @@ def run!
end
def tick!
+ check_for_events!
@renderer.render! @world, @el_rogue, *@wizards
print "Where to? [wasd/q]: "
dir = direction_from_keypress(get_character)
@@ -53,6 +54,14 @@ def tick!
end
end
+ def display_all_wizards!
+ tmp_space = Space.new(3,3,0,0)
+ wizards = File.open(options[:wizards_file]) { |f| YAML::load(f) }
+ wizards.map do |handle, details|
+ display_event(Wizard.new(tmp_space, handle, details))
+ end
+ end
+
protected
def direction_from_keypress(keypress)
key = keypress.chr.downcase
@@ -70,6 +79,22 @@ def direction_from_keypress(keypress)
end
end
+ def check_for_events!
+ found = @wizards.detect {|w| @el_rogue.on_top_of?(w) }
+ if found
+ @wizards.delete(found)
+ @defeated << found
+ display_event(found)
+ print "Continue [Y]: "
+ while get_character.chr.downcase != 'y' do
+ end
+ end
+ end
+
+ def display_event(wizard)
+ Event.new(wizard, options[:width], options[:height]).render!
+ end
+
def make_world
generator.generate!(options[:max_worlds])
end
@@ -85,6 +110,7 @@ def initialize_wizards!(in_rooms)
in_rooms.delete(w_room)
Wizard.new(w_room, handle, details)
end
+ @defeated = []
end
end
end
@@ -9,11 +9,11 @@ def initialize(room, handle, details)
end
def name
- @details[:name]
+ @details['name']
end
def talk
- @details[:talk]
+ @details['talk']
end
end
end
@@ -4,25 +4,25 @@ jcoglan:
talk: A History of Websockets
codescrum:
name: Jairo Diaz
- talk: Tech interns” - How to get more qualified interns into Ruby.
+ talk: Tech interns
stueccles:
name: Stuart Eccles
- talk: Conan the deployer - capistrano extensions focussing on AWS
+ talk: Conan the deployer
rlivsey:
name: Richard Livsey
- talk: Something on MonogoDB or something on removing authentication from your models (separation of concerns)
+ talk: Breaking up is hard to do
hmarr:
name: Harry Marr
- talk: Custom documentation generators (example)
+ talk: Custom documentation generators
andrewmcdonough:
name: Andrew McDonough
talk: Ruby Poetry
chrismdp:
name: Chris Parsons
- talk: The crowd-sourced talk. One slot at these evenings is given over to someone prepared to do a talk on something that the mailing list suggests, Chris is bravely wearing that mantle this time.
+ talk: The crowd-sourced talk.
knaveofdiamonds:
name: Roland Swingler
- talk: Reading tea leaves - predict the future with ruby!
+ talk: "Reading tea leaves\npredict the future with ruby!"
botanicus:
- name: Jakub Šťastný
- talk: SockJS - a websocket emulation library
+ name: Jakub Stastny
+ talk: "SockJS\na websocket emulation library"

0 comments on commit d99d483

Please sign in to comment.