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