2009-12-14 10:00:31 -05:00
|
|
|
# Examples from the Poignant Guide.
|
|
|
|
|
|
|
|
# ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
['toast', 'wine', 'cheese'].each (food) -> print food.capitalize()
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class LotteryTicket
|
|
|
|
# def picks; @picks; end
|
|
|
|
# def picks=(var); @picks = var; end
|
|
|
|
# def purchased; @purchased; end
|
|
|
|
# def purchased=(var); @purchased = var; end
|
|
|
|
# end
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
LotteryTicket =
|
|
|
|
get_picks: -> @picks
|
|
|
|
set_picks: (@picks) ->
|
|
|
|
get_purchased: -> @purchase
|
|
|
|
set_purchased: (@purchased) ->
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-24 20:04:28 -05:00
|
|
|
# class << LotteryDraw
|
|
|
|
# def play
|
|
|
|
# result = LotteryTicket.new_random
|
|
|
|
# winners = {}
|
|
|
|
# @@tickets.each do |buyer, ticket_list|
|
|
|
|
# ticket_list.each do |ticket|
|
|
|
|
# score = ticket.score( result )
|
|
|
|
# next if score.zero?
|
|
|
|
# winners[buyer] ||= []
|
|
|
|
# winners[buyer] << [ ticket, score ]
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# @@tickets.clear
|
|
|
|
# winners
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
LotteryDraw =
|
2010-01-26 10:52:05 -05:00
|
|
|
play: ->
|
2010-07-29 00:03:42 -04:00
|
|
|
result = LotteryTicket.new_random()
|
|
|
|
winners = {}
|
2010-01-26 10:52:05 -05:00
|
|
|
this.tickets.each (buyer, ticket_list) ->
|
|
|
|
ticket_list.each (ticket) ->
|
2010-07-29 00:03:42 -04:00
|
|
|
score = ticket.score result
|
2010-01-24 20:04:28 -05:00
|
|
|
return if score is 0
|
2010-07-29 21:23:49 -04:00
|
|
|
winners[buyer] or= []
|
2010-07-29 00:03:42 -04:00
|
|
|
winners[buyer].push [ticket, score]
|
|
|
|
this.tickets = {}
|
2010-01-24 20:04:28 -05:00
|
|
|
winners
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-14 10:00:31 -05:00
|
|
|
# module WishScanner
|
|
|
|
# def scan_for_a_wish
|
|
|
|
# wish = self.read.detect do |thought|
|
|
|
|
# thought.index( 'wish: ' ) == 0
|
|
|
|
# end
|
|
|
|
# wish.gsub( 'wish: ', '' )
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
WishScanner =
|
2010-01-26 10:52:05 -05:00
|
|
|
scan_for_a_wish: ->
|
2010-07-29 00:03:42 -04:00
|
|
|
wish = this.read().detect (thought) -> thought.index('wish: ') is 0
|
|
|
|
wish.replace 'wish: ', ''
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class Creature
|
|
|
|
#
|
|
|
|
# # This method applies a hit taken during a fight.
|
|
|
|
# def hit( damage )
|
|
|
|
# p_up = rand( charisma )
|
|
|
|
# if p_up % 9 == 7
|
|
|
|
# @life += p_up / 4
|
|
|
|
# puts "[#{ self.class } magick powers up #{ p_up }!]"
|
|
|
|
# end
|
|
|
|
# @life -= damage
|
|
|
|
# puts "[#{ self.class } has died.]" if @life <= 0
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# # This method takes one turn in a fight.
|
|
|
|
# def fight( enemy, weapon )
|
|
|
|
# if life <= 0
|
|
|
|
# puts "[#{ self.class } is too dead to fight!]"
|
|
|
|
# return
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# # Attack the opponent
|
|
|
|
# your_hit = rand( strength + weapon )
|
|
|
|
# puts "[You hit with #{ your_hit } points of damage!]"
|
|
|
|
# enemy.hit( your_hit )
|
|
|
|
#
|
|
|
|
# # Retaliation
|
|
|
|
# p enemy
|
|
|
|
# if enemy.life > 0
|
|
|
|
# enemy_hit = rand( enemy.strength + enemy.weapon )
|
|
|
|
# puts "[Your enemy hit with #{ enemy_hit } points of damage!]"
|
|
|
|
# self.hit( enemy_hit )
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# end
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
Creature =
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
# This method applies a hit taken during a fight.
|
2010-01-26 10:52:05 -05:00
|
|
|
hit: (damage) ->
|
2010-07-29 00:03:42 -04:00
|
|
|
p_up = Math.rand this.charisma
|
2009-12-14 10:00:31 -05:00
|
|
|
if p_up % 9 is 7
|
2009-12-25 10:31:51 -05:00
|
|
|
this.life += p_up / 4
|
2010-07-29 00:03:42 -04:00
|
|
|
puts "[" + this.name + " magick powers up " + p_up + "!]"
|
2009-12-25 10:31:51 -05:00
|
|
|
this.life -= damage
|
2010-07-29 00:03:42 -04:00
|
|
|
if this.life <= 0 then puts "[" + this.name + " has died.]"
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
# This method takes one turn in a fight.
|
2010-01-26 10:52:05 -05:00
|
|
|
fight: (enemy, weapon) ->
|
2010-07-29 00:03:42 -04:00
|
|
|
if this.life <= 0 then return puts "[" + this.name + "is too dead to fight!]"
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
# Attack the opponent.
|
2010-07-29 00:03:42 -04:00
|
|
|
your_hit = Math.rand this.strength + weapon
|
|
|
|
puts "[You hit with " + your_hit + "points of damage!]"
|
|
|
|
enemy.hit your_hit
|
2009-12-14 10:00:31 -05:00
|
|
|
|
|
|
|
# Retaliation.
|
2010-07-29 00:03:42 -04:00
|
|
|
puts enemy
|
2009-12-14 10:00:31 -05:00
|
|
|
if enemy.life > 0
|
2010-07-29 00:03:42 -04:00
|
|
|
enemy_hit = Math.rand enemy.strength + enemy.weapon
|
|
|
|
puts "[Your enemy hit with " + enemy_hit + "points of damage!]"
|
|
|
|
this.hit enemy_hit
|
2009-12-18 09:55:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Get evil idea and swap in code words
|
|
|
|
# print "Enter your new idea: "
|
|
|
|
# idea = gets
|
|
|
|
# code_words.each do |real, code|
|
|
|
|
# idea.gsub!( real, code )
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# # Save the jibberish to a new file
|
|
|
|
# print "File encoded. Please enter a name for this idea: "
|
|
|
|
# idea_name = gets.strip
|
|
|
|
# File::open( "idea-" + idea_name + ".txt", "w" ) do |f|
|
|
|
|
# f << idea
|
|
|
|
# end
|
|
|
|
|
|
|
|
# Get evil idea and swap in code words
|
2010-07-29 00:03:42 -04:00
|
|
|
print "Enter your new idea: "
|
|
|
|
idea = gets()
|
|
|
|
code_words.each (real, code) -> idea.replace(real, code)
|
2009-12-18 09:55:31 -05:00
|
|
|
|
|
|
|
# Save the jibberish to a new file
|
2010-07-29 00:03:42 -04:00
|
|
|
print "File encoded. Please enter a name for this idea: "
|
|
|
|
idea_name = gets().strip()
|
|
|
|
File.open "idea-" + idea_name + '.txt', 'w', (file) -> file.write idea
|
2009-12-18 09:55:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def wipe_mutterings_from( sentence )
|
|
|
|
# unless sentence.respond_to? :include?
|
|
|
|
# raise ArgumentError,
|
|
|
|
# "cannot wipe mutterings from a #{ sentence.class }"
|
|
|
|
# end
|
|
|
|
# while sentence.include? '('
|
|
|
|
# open = sentence.index( '(' )
|
|
|
|
# close = sentence.index( ')', open )
|
|
|
|
# sentence[open..close] = '' if close
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2010-07-29 00:03:42 -04:00
|
|
|
wipe_mutterings_from = (sentence) ->
|
|
|
|
throw new Error "cannot wipe mutterings" unless sentence.indexOf
|
2009-12-18 09:55:31 -05:00
|
|
|
while sentence.indexOf('(') >= 0
|
2010-07-29 00:03:42 -04:00
|
|
|
open = sentence.indexOf('(') - 1
|
|
|
|
close = sentence.indexOf(')') + 1
|
|
|
|
sentence = sentence[0..open] + sentence[close..sentence.length]
|
|
|
|
sentence
|