Mattias Bodlund 1 month ago
parent
commit
08b04aa8e4
3 changed files with 33 additions and 2 deletions
  1. +15
    -2
      app/controllers/stages_controller.rb
  2. +17
    -0
      app/views/stages/score.html.erb
  3. +1
    -0
      config/routes.rb

+ 15
- 2
app/controllers/stages_controller.rb View File

@ -5,7 +5,7 @@ class StagesController < ApplicationController
before_action :require_player! before_action :require_player!
before_action :check_stage_access, expect: [ :game_over ] 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 ] before_action :set_outcome, only: [ :reveal, :pick, :result ]
@ -23,6 +23,12 @@ class StagesController < ApplicationController
end end
# GET
def score
@node = Node.at_depth(1).score.viewable&.first
end
# POST # POST
def flip def flip
outcome = rand < 0.5 ? "chance" : "choice" outcome = rand < 0.5 ? "chance" : "choice"
@ -84,7 +90,13 @@ class StagesController < ApplicationController
def next def next
if player_can_proceed? if player_can_proceed?
current_player.update(current_stage: stage_index + 1) 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 else
# redirect_to root_path # redirect_to root_path
not_found not_found
@ -145,6 +157,7 @@ class StagesController < ApplicationController
private private


+ 17
- 0
app/views/stages/score.html.erb View File

@ -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
%>
<article>
<% @node.attachments.each do |attachment| %>
<%= attachment.body.html_safe %>
<% end %>
<div class="action-container">
<%= button_to t("go_again"), go_again_path(), method: :post %>
</div>
</article>

+ 1
- 0
config/routes.rb View File

@ -72,6 +72,7 @@ Rails.application.routes.draw do
end end
get "game_over", to: "stages#game_over" get "game_over", to: "stages#game_over"
get "score", to: "stages#score"
get "", to: "languages#show" get "", to: "languages#show"
# get "*url", to: "site#page", constraints: lambda { |req| req.path.exclude?("storage") } # get "*url", to: "site#page", constraints: lambda { |req| req.path.exclude?("storage") }


Loading…
Cancel
Save