Changeset 185
- Timestamp:
- 11/18/04 09:05:44 (4 years ago)
- Location:
- branches/simplest-thing/acceptance
- Files:
-
- 1 removed
- 1 moved
-
epic3.tests.rb (deleted)
-
lib/game.rb (moved) (moved from branches/simplest-thing/acceptance/epic3.rb) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simplest-thing/acceptance/lib/game.rb
r184 r185 1 1 #!/usr/bin/evn ruby 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 10 require "textui" 11 require "character" 2 12 3 13 DESCRIPTION = <<END … … 5 15 6 16 END 7 PROMPT = "FaerieMUD>"8 NEW_CHAR = "Starting a new character."17 PROMPT = "FaerieMUD>" 18 NEW_CHAR = "Starting a new character." 9 19 10 20 RACE_CHOOSE = "Please choose from dwarf, human, pixie" 11 RACE = "dwarf"12 CHOSEN = "Your character is a %s."13 INVALID = "Invalid species."21 RACE = "dwarf" 22 CHOSEN = "Your character is a %s." 23 INVALID = "Invalid species." 14 24 15 ASK_NAME = "What is your character's name?"#"16 PUNCHBAG = "Punchbag"25 ASK_NAME = "What is your character's name?" #" 26 PUNCHBAG = "Punchbag" 17 27 NO_PUNCHBAG = "You may not be named 'Punchbag'." 18 NAME = "Bob"28 NAME = "Bob" 19 29 20 RESUME = "Resuming play as %s, the %s." % [NAME, RACE]30 RESUME = "Resuming play as %s, the %s." % [NAME, RACE] 21 31 22 LOOK = "look"23 SEE_WHAT = %q[You are locked in the formless void with an ugly orc.He says, "Hi, I'm Punchbag".]24 WHOAMI = "who am I?"25 WHOAMME = "me?"26 IAM = "You are %s." % NAME27 OTHER = "meow"28 OTHER_WHAT = "The formless void stares vacantly back at you. The orc's stare is more hungry than vacant."32 LOOK = "look" 33 SEE_WHAT = %q[You are locked in the formless void with an ugly orc. He says, "Hi, I'm Punchbag".] 34 WHOAMI = "who am I?" 35 WHOAMME = "me?" 36 IAM = "You are %s." % NAME 37 OTHER = "meow" 38 OTHER_WHAT = "The formless void stares vacantly back at you. The orc's stare is more hungry than vacant." 29 39 30 QUIT = "quit"31 GOODBYE = "Goodbye."40 QUIT = "quit" 41 GOODBYE = "Goodbye." 32 42 33 HIT1 = "hit Punchbag"34 HIT2 = "hit punchbag"35 HIT3 = "hit orc"36 SMACK = "You smack the orc."43 HIT1 = "hit Punchbag" 44 HIT2 = "hit punchbag" 45 HIT3 = "hit orc" 46 SMACK = "You smack the orc." 37 47 UNCONSCIOUS = "The orc collapses into unconsciousness." 38 48 49 39 50 class Game 51 include TextUI 40 52 41 def initialize 42 @io = IO::popen('ruby bin/faeriemud.rb', IO::NONBLOCK | IO::RDWR) 43 end 53 def initialize 54 IO::popen("-", IO::NONBLOCK | IO::RDWR) {|io| 44 55 45 attr :io 56 if io # Parent 57 @io = io 58 else # Child 59 Game.play 60 end 61 } 62 end 46 63 47 def puts(line) 48 @io.puts(line) 49 end 64 attr :io 50 65 51 def gets 52 @io.gets 53 end66 def puts(line) 67 @io.puts(line) 68 end 54 69 55 def read56 @io.read 57 end70 def gets 71 @io.gets 72 end 58 73 59 def close 60 if select([],[@io],[],1) 61 self.puts(RACE) 62 end 63 if select([],[@io],[],1) 64 self.puts(NAME) 65 end 66 if select([],[@io],[],1) 67 self.puts(QUIT) 68 end 69 if select([@io],[],[],1) 70 self.read 71 end 72 @io.close 73 end 74 def read 75 @io.read 76 end 74 77 75 def Game.preset 76 Game.reset 77 game = Game.new 78 game.close 79 return Game.new 80 end 78 def close 79 if select([],[@io],[],1) 80 self.puts(RACE) 81 end 82 if select([],[@io],[],1) 83 self.puts(NAME) 84 end 85 if select([],[@io],[],1) 86 self.puts(QUIT) 87 end 88 if select([@io],[],[],1) 89 self.read 90 end 91 @io.close 92 end 81 93 82 def Game.reset 83 `ruby bin/faeriemud.rb --reset` 84 end 94 def Game.preset 95 Game.reset 96 game = Game.new 97 game.close 98 return Game.new 99 end 85 100 101 def Game.reset 102 Character.reset 103 $stderr.puts "Game reset." 104 end 105 106 def Game.play 107 message <<END 108 You are in the formless void known as FaerieMUD 1.0. 109 110 END 111 112 character = Character.load 113 114 if character 115 message "Resuming play as %s, the %s." % [character.name, character.race] 116 else 117 message "Starting a new character." 118 race = prompt( "Please choose from dwarf, human, pixie", 119 "Invalid species." ) {|s| 120 %w[dwarf human pixie].include?( s ) 121 } 122 message "Your character is a %s." % race 123 name = prompt( "What is your character's name?", #" 124 "You may not be named 'Punchbag'." ) {|n| 125 ! %w[Punchbag].include?( n ) 126 } 127 character = Character.new(race, name) 128 character.save 129 end 130 131 playing = true 132 orc = 10 133 while playing 134 command = prompt( "FaerieMUD>" ) 135 case command 136 when "who am I?", "me?" #" 137 message "You are %s." % character.name 138 when "look" 139 message %q[You are locked in the formless void with an ugly orc. He says, "Hi, I'm Punchbag".] 140 when %r{hit ([pP]unchbag|orc)} 141 if orc > 0 142 message "You smack the orc." 143 orc -= 1 144 else 145 message "The orc collapses into unconsciousness." 146 end 147 when "quit" 148 message "Goodbye." 149 playing = false 150 else 151 message "The formless void stares vacantly back at you. The orc's stare is more hungry than vacant." 152 end 153 end 154 155 end 86 156 end
