-2

テキストベースの Ruby ゲームを作成しようとしていますが、コードで .includes を使用できない理由がわかりません。方法。

これらは私が得ているエラーです:

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>'

if move == "run" メソッドを使用すると問題なく動作しますが、インクルードするとどうなりますか? このエラーがポップアップします。== を実行できるのに .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

どんな助けでも大歓迎です。ありがとうございました。

4

1 に答える 1

1

あなたincludes?のコードにあります。メソッドはinclude?(no 's')

于 2013-07-09T03:40:43.813 に答える