次のソースコードが動作するよう、すごろくゲームを開発せよ。
game = Game.new
game.setBoard(Board.new("public/board.csv"))
game.addPlayer(Player.new("Taro"))
game.addPlayer(Player.new("Jiro"))
game.setDice(Dice.new)
game.start()
$ rails new r-sugoroku
config/application.rb
module RSugoroku
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib)
end
end
$ rails g controller home index
config/routes.rb
root 'home#index'
上記のメインロジックをhome_controllerに書くことで、 http://localhost:3000/ にアクセスしたときに実行される
app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
game = Game.new
game.setBoard(Board.new("public/board.csv"))
game.addPlayer(Player.new("Taro"))
game.addPlayer(Player.new("Jiro"))
game.setDice(Dice.new)
game.start()
end
end
libディレクトリにクラスを作成していく