diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb index 3216ad7..7753610 100644 --- a/app/controllers/stages_controller.rb +++ b/app/controllers/stages_controller.rb @@ -5,7 +5,7 @@ class StagesController < ApplicationController before_action :require_player! before_action :check_stage_access, expect: [ :game_over ] - before_action :set_stage, expect: [ :game_over ] + before_action :set_stage, expect: [ :game_over, :score ] before_action :set_outcome, only: [ :reveal, :pick, :result ] @@ -23,6 +23,12 @@ class StagesController < ApplicationController end + # GET + def score + @node = Node.at_depth(1).score.viewable&.first + end + + # POST def flip outcome = rand < 0.5 ? "chance" : "choice" @@ -84,7 +90,13 @@ class StagesController < ApplicationController def next if player_can_proceed? current_player.update(current_stage: stage_index + 1) - redirect_to stage_path(id: current_player.current_stage) + # Game done + if Node.at_depth(1).stage.count < current_player.current_stage + redirect_to action: "score" and return + # Next stage + else + redirect_to stage_path(id: current_player.current_stage) and return + end else # redirect_to root_path not_found @@ -145,6 +157,7 @@ class StagesController < ApplicationController + private diff --git a/app/views/stages/score.html.erb b/app/views/stages/score.html.erb new file mode 100644 index 0000000..2accfaa --- /dev/null +++ b/app/views/stages/score.html.erb @@ -0,0 +1,17 @@ +<%- + content_for :title, @node.page_title.blank? ? @node.title : @node.page_title + content_for :meta_description, @node.page_description + + content_for :debug, current_player.inspect +%> + +
+ + <% @node.attachments.each do |attachment| %> + <%= attachment.body.html_safe %> + <% end %> + +
+ <%= button_to t("go_again"), go_again_path(), method: :post %> +
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e46fbf2..39f8041 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,6 +72,7 @@ Rails.application.routes.draw do end get "game_over", to: "stages#game_over" + get "score", to: "stages#score" get "", to: "languages#show" # get "*url", to: "site#page", constraints: lambda { |req| req.path.exclude?("storage") }