2013-07-09 2 views
-2

텍스트 기반 루비 게임을 쓰려고하는데, 내 코드가 .includes를 사용하지 못하는 이유를 알아낼 수 없습니까? 방법. 내가 포함 않을 때.include를 사용하지 않으시겠습니까? (루비 게임 작성 시도)

game.rb:31:in `home': undefined method `includes?' for "run":String (NoMethodError) 
    from game.rb:20:in `call' 
    from game.rb:20:in `play' 
    from game.rb:69:in `<main>' 

내가 그것을 잘 작동하는 경우 이동 == "실행"방법을 사용하는 경우 만 :

이러한 오류 내가 갖는입니까? 이 오류가 나타납니다. 나는 그것이 왜 나를 할 수 있는지 모르겠다. ==하지만 .includes가 아닌가?

이 내 주요 game.rb 코드 :

require './levels' 
include Levels 

class Game 
    def initialize(start) 
    @quips = [ 
     "You died. Noob.", 
     "Nice job, you lost.", 
     "Looooooserrrrr." 
     ] 
    @start = start 
    end 

    def play 
    next_room = @start 

    while true 
     puts "\n---------" 
     room = method(next_room) 
     next_room = room.call 
    end 
    end 

    def home 
    home_text 

    puts " Do you run out to see what's going on or stay inside and hope the problem goes away?" 

    prompt; move = gets.chomp 

    if move.includes? "run" 
     return :town 
    else 
     die("Your house catches on fire and collapses on you.") 
    end 
    end 
end 

a_game = Game.new(:home).play 

내 다른 파일 levels.rb은 이것이다 : 어떤 도움에 감사드립니다

module Levels 

    def prompt 
     puts 
     print " > " 
    end 

    def die(why) 
     puts 
     puts " #{why} #{@quips[rand(@quips.length)]}" 
     Process.exit(1) 
    end 

    def bad_input 
     puts <<-TEXT 
     Learn to follow instructions! 
     TEXT 
     return :die 
    end 

    def home_text 
     puts <<-TEXT 
     You wake up to the smell of smoke in your room. Jolting up from your bed, you 
     look around the room and see a heavy cloud of smoke covering your ceiling. There 
     are piercing sounds of screaming outside, coupled with terrorizing roars and howls. 

     TEXT 
    end 
end 

. 고맙습니다.

답변

1

코드에 includes?이 있습니다. 방법은 include? (아니요 ')입니다.

+0

아! 감사! –