From 10599ab2e789ffb93a19f6aa3c100f533c460315 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 29 Oct 2023 11:32:06 -0400 Subject: generate, show, solve puzzles --- app/controllers/wittle/puzzles_controller.rb | 36 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index 09a2524..9599307 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -1,7 +1,41 @@ module Wittle class PuzzlesController < ApplicationController + def about + @normal_puzzle = Puzzle.normal.order(created_at: :desc).first + @hard_puzzle = Puzzle.hard.order(created_at: :desc).first + end + def index - @puzzle = WittleGenerator.new.generate_medium + #@puzzle = WittleGenerator.new.generate_medium + end + + def show + @puzzle = Puzzle.find(params[:id]) + @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id) + end + + def solve + @puzzle = Puzzle.find(params[:id]) + + raise ActiveRecord::RecordNotFound unless @puzzle.latest? + + if @puzzle.solved_data.nil? + @puzzle.solved_data = params[:solved] + @puzzle.save! + end + + session[:played_puzzles] ||= [] + session[:played_puzzles] << @puzzle.id + end + + def submit + @puzzle = Puzzle.find(params[:id]) + + raise ActiveRecord::RecordNotFound unless @puzzle.latest? + + @puzzle.scores.create!(name: params[:name], ip: request.ip) + + redirect_to @puzzle end end end -- cgit 1.4.1