From 2c7e5d1f38b386ccb2001f88278da1ff59e7f85b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 14 Sep 2017 17:30:58 +0800 Subject: [PATCH] =?UTF-8?q?TPI=E5=8D=95=E9=80=89=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 72 ++++++++----------- app/models/challenge.rb | 21 ++++++ app/views/games/_choice_question.html.erb | 33 +++++---- app/views/games/_code_actions.html.erb | 60 ++++------------ app/views/games/_game_choose_results.html.erb | 43 +++++++---- app/views/games/_game_show.html.erb | 7 +- app/views/games/show.js.erb | 12 ++++ ..._modify_correct_type_for_choose_outputs.rb | 8 +++ 8 files changed, 134 insertions(+), 122 deletions(-) create mode 100644 db/migrate/20170914024926_modify_correct_type_for_choose_outputs.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 00e9e52d9..f2fdb4e22 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -296,55 +296,41 @@ class GamesController < ApplicationController end # 选择题评测(选择题不需要重新评测) + # score 获得金币数 tag_count 技能数 right用户是否全对 answer_right全部选择题的正确性 def evaluating_choice - - if false - @game_challenge = @game.challenge - user_answer = params[:answer] - correct = true - score = 0 - tag_count = 0 - if !user_answer.blank? - if user_answer.split("").count != @game_challenge.challenge_questions.where(:right_key => true).count - correct = false - else - user_answer.split("").each do |answer| - question = @game_challenge.challenge_questions.where(:position => answer.to_i).first - unless question.right_key - correct = false - break - end - end - end - else - correct = false + @game_challenge = @game.challenge + @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id) + @shixun = @myshixun.shixun + score = 0 + tag_count = 0 + @right = true + answer_right = [] + @game_challenge.challenge_chooses.each_with_index do |choose, index| + correct = (params[:answer][index] == choose.standard_answer) ? true : false + if choose.choose_outputs.blank? + ChooseOutputs.create(:challenge_choose_id => choose.id, :user_id => User.current.id, :answer => params[:answer][index], :correct => correct) end - @game.update_attributes(:status => 2, :end_time => Time.now) - had_done = @game.had_done - shixun = @myshixun.shixun - if shixun.status > 1 && !@game.answer_open + if @shixun.status > 1 && !@game.answer_open if correct - #User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score)) - reward_grade(@game.user, @game.id, 'Game', @game_challenge.score) - reward_experience(@game.user, @game.id, 'Game', @game_challenge.score) - @game.update_attribute(:final_score, @game_challenge.score) - score = @game_challenge.score - tag_count = @game_challenge.challenge_tags.count - else - score = "+0" - tag_count = 0 + score += choose.score + tag_count += choose.challenge_tags.count end - elsif shixun.status > 1 && @game.answer_open - score = -@game_challenge.score.to_i - tag_count = 0 - else - score = "+0" - tag_count = 0 + elsif @shixun.status > 1 && @game.answer_open + score -= choose.score end - if @game.outputs.blank? - Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) + unless correct + @right = false end - render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count} + answer_right << correct + end + @game.update_attributes(:status => 2, :end_time => Time.now) + @had_done = @game.had_done + reward_grade(@game.user, @game.id, 'Game', score) + reward_experience(@game.user, @game.id, 'Game', score) + @game.update_attribute(:final_score, score) + + respond_to do |format| + format.js{redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun, :choose => 1)} end end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 7efd0c6ba..128a64d8b 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -28,6 +28,27 @@ class Challenge < ActiveRecord::Base str end + def choose_correct_num + num = 0 + self.challenge_chooses.each do |choose| + outputs = ChooseOutputs.where(:challenge_choose_id => choose.id).first + if outputs.nil? + num = nil + else + num += (outputs.correct ? 1 : 0) + end + end + return num + end + + def choose_score + score = 0 + self.challenge_chooses.each do |choose| + score += choose.score + end + return score + end + def next_challenge challenge_count = Challenge.where(:shixun_id => self.shixun_id).count render_404 if self.position ==challenge_count diff --git a/app/views/games/_choice_question.html.erb b/app/views/games/_choice_question.html.erb index badbf1536..cebfd0a05 100644 --- a/app/views/games/_choice_question.html.erb +++ b/app/views/games/_choice_question.html.erb @@ -11,30 +11,30 @@
<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>
-<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>
+<% if choose.category == 1 %> - + name="answer[<%= index + 1 %>]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-radio ml5"> <% else %> - + name="answer[]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-checkbox ml5"> <% end %> - +
<% end %> -