Changeset 187
- Timestamp:
- 11/18/04 10:12:13 (4 years ago)
- Location:
- branches/simplest-thing/acceptance
- Files:
-
- 2 modified
-
epic3.tests.rb (modified) (3 diffs)
-
lib/game.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simplest-thing/acceptance/epic3.tests.rb
r186 r187 1 1 #!/usr/bin/env ruby -w 2 2 3 BEGIN { 4 $basedir = File::dirname( File::dirname(__FILE__) ) 5 %w{acceptance/lib lib}.each do |dir| 6 $LOAD_PATH.unshift File::join( $basedir, dir ) 7 end 8 } 9 3 10 require 'test/unit' 4 $: << File.dirname(__FILE__)5 11 require 'game' 6 12 … … 8 14 9 15 def setup 10 Game.reset11 16 @game = Game.preset 12 17 end 13 18 14 19 def teardown 15 @game .close20 @game = nil 16 21 end 17 22 … … 23 28 def test_010_hit 24 29 data = "" 25 data = @game.gets until data.include?( PROMPT ) 30 @game.play {|player| 31 data = player.gets until data.include?( PROMPT ) 26 32 27 # - if i type "hit Punchbag", "hit orc", or "hit punchbag", i am told 28 # "You smack the orc." 29 @game.puts( HIT1 ) 30 assert @game.gets.include?( SMACK ), 31 "Hitting Punchbag did not work." 32 @game.gets # prompt 33 @game.puts( HIT2 ) 34 assert @game.gets.include?( SMACK ), 35 "Hitting Punchbag did not work." 36 @game.gets # prompt 37 @game.puts( HIT3 ) 38 assert @game.gets.include?( SMACK ), 39 "Hitting Punchbag did not work." 40 @game.gets # prompt 41 33 # - if i type "hit Punchbag", "hit orc", or "hit punchbag", i am told 34 # "You smack the orc." 35 player.puts( HIT1 ) 36 assert player.gets.include?( SMACK ), 37 "Hitting Punchbag did not work." 38 player.gets # prompt 39 player.puts( HIT2 ) 40 assert player.gets.include?( SMACK ), 41 "Hitting Punchbag did not work." 42 player.gets # prompt 43 player.puts( HIT3 ) 44 assert player.gets.include?( SMACK ), 45 "Hitting Punchbag did not work." 46 player.gets # prompt 42 47 43 # - after typing 'hit orc' over and over, i eventually want to be 44 # told "The orc collapses into unconsciousness." 45 limit = 10 46 unconscious = false 47 limit.times do 48 @game.puts( HIT1 ) 49 if @game.gets.include?( UNCONSCIOUS ) 50 unconscious = true 51 break 52 end 53 @game.gets # prompt 54 end 55 assert unconscious, 56 "The orc did not fall unconscious, even after #{limit} hits." 48 49 # - after typing 'hit orc' over and over, i eventually want to be 50 # told "The orc collapses into unconsciousness." 51 limit = 10 52 unconscious = false 53 limit.times do 54 player.puts( HIT1 ) 55 if player.gets.include?( UNCONSCIOUS ) 56 unconscious = true 57 break 58 end 59 player.gets # prompt 60 end 61 assert unconscious, 62 "The orc did not fall unconscious, even after #{limit} hits." 63 } 57 64 end 58 65 -
branches/simplest-thing/acceptance/lib/game.rb
r185 r187 10 10 require "textui" 11 11 require "character" 12 require "forwardable" 12 13 13 14 DESCRIPTION = <<END … … 51 52 include TextUI 52 53 53 def initialize54 IO::popen("-", IO::NONBLOCK | IO::RDWR) {|io|54 class Player 55 extend Forwardable 55 56 56 if io # Parent 57 @io = io 58 else # Child 59 Game.play 60 end 61 } 62 end 57 def initialize( io ) 58 @io = io 59 end 63 60 64 attr :io61 def_delegators :@io, :puts, :gets, :read, :close, :closed? 65 62 66 def puts(line) 67 @io.puts(line) 68 end 63 end # class Game::Player 69 64 70 def gets71 @io.gets72 end73 74 def read75 @io.read76 end77 78 def close79 if select([],[@io],[],1)80 self.puts(RACE)81 end82 if select([],[@io],[],1)83 self.puts(NAME)84 end85 if select([],[@io],[],1)86 self.puts(QUIT)87 end88 if select([@io],[],[],1)89 self.read90 end91 @io.close92 end93 65 94 66 def Game.preset 95 Game.reset96 game = Game.new97 game.close98 returnGame.new67 Character.reset 68 character = Character.new(RACE, NAME) 69 character.save 70 Game.new 99 71 end 100 72 … … 104 76 end 105 77 106 def Game.play 107 message <<END 78 79 def initialize 80 @character = Character::load 81 end 82 83 attr_accessor :character 84 85 def play 86 IO::popen("-", IO::RDWR) {|io| 87 if io # Parent 88 player = Game::Player::new(io) 89 yield( player ) 90 else # Child 91 self.run 92 end 93 } 94 end 95 96 def run 97 message <<-END 108 98 You are in the formless void known as FaerieMUD 1.0. 109 99
