diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ec38ea63e..00e9e52d9 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -49,7 +49,7 @@ class GamesController < ApplicationController @type = params[:type] challenge_path = @game_challenge.path # 用户选项 - @user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank? + #@user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank? # 默认打开文件 logger.info("repository id is #{@repository.try(:id)}, repository's shixun_id =#{@repository.try(:myshixun_id)} shixun_id =#{@repository.try(:shixun_id)}, project_id => #{@repository.try(:project_id)}") # 验证challenge文件名的合法性 @@ -297,52 +297,55 @@ class GamesController < ApplicationController # 选择题评测(选择题不需要重新评测) def evaluating_choice - @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 + + 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 end - else - correct = false - 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 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 + @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 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 + end + elsif shixun.status > 1 && @game.answer_open + score = -@game_challenge.score.to_i + tag_count = 0 else score = "+0" tag_count = 0 end - elsif shixun.status > 1 && @game.answer_open - score = -@game_challenge.score.to_i - tag_count = 0 - else - score = "+0" - tag_count = 0 + if @game.outputs.blank? + Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) + end + render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count} end - if @game.outputs.blank? - Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) - end - render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count} end diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb index 5089108df..18d76790f 100644 --- a/app/models/challenge_choose.rb +++ b/app/models/challenge_choose.rb @@ -1,6 +1,6 @@ class ChallengeChoose < ActiveRecord::Base # attr_accessible :title, :body - # type 1 单选, 2,多选 + # category 1 单选, 2,多选 # standard_answer 正确答案 answer: 答题的思路 default_scope :order => 'position' belongs_to :challenge diff --git a/app/views/games/_choice_question.html.erb b/app/views/games/_choice_question.html.erb index db509be63..41aa897ae 100644 --- a/app/views/games/_choice_question.html.erb +++ b/app/views/games/_choice_question.html.erb @@ -1,37 +1,106 @@ + +
+
+ +
+
+
+ <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> +

<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>

+
+ +
+ <% choose.challenge_questions.each_with_index do |question, i| %> +

+                
+
" onclick=""> + + <% if choose.category == 1 %> + + <% else %> + + + <% end %> +
+ <%= (question.position + 65).chr %>. +
+

<%= question.option_name %>

+
+
+
+
+ <% end %> + <% end %> +

+
+
+
+ +
+
+
+ +
+ <%= render :partial => 'games/game_choose_results' %> +
+
+ + + + +<% if false %>
-

" id="correct_tip"> - 正确 -

-

" id="error_tip"> - 错误 -

1.单选题

应在下列程序划线处填入的语句是()


         
- <% @game_challenge.challenge_questions.each_with_index do |question, i| %> -
" onclick="choice_answer('<%= @st %>', this)"> - - - - - -
- <%= (question.position + 65).chr %>. -
-

<%= question.option_name %>

-
-
-
+ <% @game_challenge.challenge_chooses.each do |choose| %> + <% choose.challenge_questions.each_with_index do |question, i| %> +
" onclick="choice_answer('<%= @st %>', this)"> + + + + + +
+ <%= (question.position + 65).chr %>. +
+

<%= question.option_name %>

+
+
+
+ <% end %> <% end %>

@@ -39,3 +108,4 @@
+<% end %> \ No newline at end of file diff --git a/app/views/games/_game_choose_results.html.erb b/app/views/games/_game_choose_results.html.erb new file mode 100644 index 000000000..a69854400 --- /dev/null +++ b/app/views/games/_game_choose_results.html.erb @@ -0,0 +1,44 @@ +<%= content_for(:header_tags) do %> + <%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %> +<% end %> + +
+
+
+
+
+
+

+ 3/5 +

+

+ 5/5 全部通过 +

+ <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> +
+
+ + 题目<%= index + 1 %> + + + +
+
+
    +
  • 正确选项:<%= choose.standard_answer %>
  • +
  • 你的选项:789
  • +
+
+
+ <% end %> +
+
+
+
+
\ No newline at end of file diff --git a/app/views/games/_game_show.html.erb b/app/views/games/_game_show.html.erb index 0daa13b4b..875f33c22 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -92,7 +92,7 @@ <% if @st != 0 %> <%= render :partial => "games/choice_question" %> - <% else %> + <% else %>
diff --git a/app/views/layouts/base_myshixun.html.erb b/app/views/layouts/base_myshixun.html.erb index 2b5e6831a..f633e36f4 100644 --- a/app/views/layouts/base_myshixun.html.erb +++ b/app/views/layouts/base_myshixun.html.erb @@ -9,7 +9,7 @@ <%= favicon %> <%= javascript_heads %> <%= heads_for_theme %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster' %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster', 'css/magic-check' %> <%= javascript_include_tag 'edu/application', 'edu/edu_tpi' %> <%= call_hook :view_layouts_base_html_head %> diff --git a/public/javascripts/edu/edu_tpi.js b/public/javascripts/edu/edu_tpi.js index d31ae9a57..51d48c332 100644 --- a/public/javascripts/edu/edu_tpi.js +++ b/public/javascripts/edu/edu_tpi.js @@ -143,11 +143,11 @@ function open_answer(game, myshixun){ // 选择题选择答案 function choice_answer(st, nThis){ - if(st == "1"){ + if(st == "2"){ //$(nThis).hasClass("card-check") ? $(nThis).removeClass("card-check") : $(nThis).addClass("card-check"); $(nThis).toggleClass("card-check"); $(nThis).toggleClass("color_white"); - } else if (st == "2"){ + } else if (st == "1"){ var choice = $(".color_white"); choice.removeClass("card-check"); choice.removeClass("color_white");