読者です 読者をやめる 読者になる 読者になる

ゲームを書いてみる

Ruby
scene = 'opening'
   while true
    case scene
    when 'opening'
      puts '3本の分かれ道があります。どの道を進みますか。'
      puts "  1 左の道"
      puts "  2 真ん中の道"
      puts "  3 右の道"
      input_value = gets
      case input_value.to_i
       when 1
       scene = 'left'
       when 2
        scene = 'center'
       when 3
        scene = 'right'
       end
       when 'left'
       puts 'あらっ'
       sleep 1
       puts '落とし穴に落ちてしまいました。'
       puts '〜 GAME OVER 〜'
    exit # プログラムを終了
    when 'center'
       puts '真ん中の道をまっすぐ歩いていくと……'
        sleep 1
        puts '宝箱をみつけました!'
        puts "  1 そのままにしておく"
        puts "  2 あける"
         input_value = gets
         case input_value.to_i
       when 1
        scene = 'leave'
       when 2
       scene = 'ending'
       end
       when 'right'
        puts 'しばらく歩き続けるともとの場所にもどってしまいました。'
        sleep 1
       scene = 'opening'
       when 'leave'
        puts '宝箱には見向きもせずお家に帰りました。'
     puts 'GAME OVER'
    exit # プログラムを終了
    when 'ending'
      puts '宝箱をあけてみた!'
      sleep 1
       puts 'まばゆい光があふれだす……'
     sleep 1
      puts '呪文「biganki」を手に入れた!'
       sleep 2
     puts 'CONGRATULATIONS!'
     sleep 2
    puts 'ゲームおしまい'
     sleep 2
     puts 'プログラム おしまい'
      sleep 2
       puts 'END'
     exit # プログラムを終了
   end
  end

ぐはっ。
うーんうーんうーん…

moomin:ProgrammingRuby tomomi$ ruby game.rb
game.rb:23: Invalid char `\343' in expression
game.rb:23: Invalid char `\200' in expression
game.rb:23: Invalid char `\200' in expression
game.rb:23: Invalid char `\343' in expression
game.rb:23: Invalid char `\200' in expression
game.rb:23: Invalid char `\200' in expression
game.rb:24: Invalid char `\343' in expression
game.rb:24: Invalid char `\200' in expression
game.rb:24: Invalid char `\200' in expression
game.rb:43: Invalid char `\343' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:43: Invalid char `\343' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:43: Invalid char `\343' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:43: Invalid char `\200' in expression
game.rb:44: Invalid char `\343' in expression
game.rb:44: Invalid char `\200' in expression
game.rb:44: Invalid char `\200' in expression
game.rb:44: Invalid char `\343' in expression
game.rb:44: Invalid char `\200' in expression
game.rb:44: Invalid char `\200' in expression
game.rb:45: Invalid char `\343' in expression
game.rb:45: Invalid char `\200' in expression
game.rb:45: Invalid char `\200' in expression
game.rb:46: Invalid char `\343' in expression
game.rb:46: Invalid char `\200' in expression
game.rb:46: Invalid char `\200' in expression
game.rb:47: Invalid char `\343' in expression
game.rb:47: Invalid char `\200' in expression
game.rb:47: Invalid char `\200' in expression
game.rb:47: Invalid char `\343' in expression
game.rb:47: Invalid char `\200' in expression
game.rb:47: Invalid char `\200' in expression
game.rb:48: Invalid char `\343' in expression
game.rb:48: Invalid char `\200' in expression
game.rb:48: Invalid char `\200' in expression
game.rb:48: Invalid char `\343' in expression
game.rb:48: Invalid char `\200' in expression
game.rb:48: Invalid char `\200' in expression
game.rb:49: Invalid char `\343' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:49: Invalid char `\343' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:49: Invalid char `\343' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:49: Invalid char `\200' in expression
game.rb:50: Invalid char `\343' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:50: Invalid char `\343' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:50: Invalid char `\343' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:50: Invalid char `\200' in expression
game.rb:51: Invalid char `\343' in expression
game.rb:51: Invalid char `\200' in expression
game.rb:51: Invalid char `\200' in expression
game.rb:51: Invalid char `\343' in expression
game.rb:51: Invalid char `\200' in expression
game.rb:51: Invalid char `\200' in expression
game.rb:52: Invalid char `\343' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:52: Invalid char `\343' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:52: Invalid char `\343' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:52: Invalid char `\200' in expression
game.rb:53: Invalid char `\343' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:53: Invalid char `\343' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:53: Invalid char `\343' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:53: Invalid char `\200' in expression
game.rb:54: Invalid char `\343' in expression
game.rb:54: Invalid char `\200' in expression
game.rb:54: Invalid char `\200' in expression
game.rb:54: Invalid char `\343' in expression
game.rb:54: Invalid char `\200' in expression
game.rb:54: Invalid char `\200' in expression
game.rb:55: Invalid char `\343' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:55: Invalid char `\343' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:55: Invalid char `\343' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:55: Invalid char `\200' in expression
game.rb:56: Invalid char `\343' in expression
game.rb:56: Invalid char `\200' in expression
game.rb:56: Invalid char `\200' in expression
game.rb:56: Invalid char `\343' in expression
game.rb:56: Invalid char `\200' in expression
game.rb:56: Invalid char `\200' in expression
game.rb:57: Invalid char `\343' in expression
game.rb:57: Invalid char `\200' in expression
game.rb:57: Invalid char `\200' in expression
moomin:ProgrammingRuby tomomi$ 

ひとつずつ解いていきます。。