diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 61dcc454d..cc930f7b1 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -3,7 +3,7 @@ class GamesController < ApplicationController layout "base_myshixun" skip_before_filter :verify_authenticity_token, :only => [:file_update] before_filter :find_myshixun, :only => [:index] - before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status, :change_status, :answer] + before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status, :change_status, :answer, :minus_score] before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update] before_filter :allowd_manager before_filter :allowd_view, :only => [:show] @@ -69,23 +69,19 @@ class GamesController < ApplicationController @test_sets = test_set_static_data(test_sets) end - @consume_time = (@game.status == 2 ? game_spend_time(@game.open_time, @game.updated_at) : game_spend_time(@game.open_time, Time.now)) logger.info("#################################{@public_test_sets}") @test_sets_count = test_sets.count - @test_sets_hidden_count = test_sets.where(:is_public => false).count + @test_sets_hidden_count = test_sets.blank? ? 0 :test_sets.select{|test_set| test_set.is_public == false}.count + @test_sets_public_count = @test_sets_count - @test_sets_hidden_count + had_test = @game.outputs + @had_test_count = had_test.count + @had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count + @had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count + @had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count @final_score = @game.final_score.to_i - # @had_tested如果已评测过,output中至少会有一条记录 - @had_tested = Output.where(:game_id => @game.id).count - @had_passed_testsests = Output.where(:game_id => @game.id, :result => true).count - # 出错的测试用例序号 - error_position = Output.where(:game_id => @game.id, :result => false).last - @error_position = error_position.blank? ? 0 : error_position.try(:test_set_position).to_i - # @had_done 1 已通关 - (@myshixun.games.count == @game_challenge.position && @game.status ==2) ? @had_done = 1 : @had_done = 0 - # 异常结果 - + @had_done = (@myshixun.games.where(:status => 2).count == @shixun.game.count ? 1 : 0) + error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last @latest_output = error_position.try(:out_put).gsub("\r\n", "
") unless error_position.try(:out_put).blank? - # @latest_output = @game.latest_output.try(:expect_output) respond_to do |format| format.html format.js @@ -161,34 +157,64 @@ class GamesController < ApplicationController redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun) end + # @myshixun -status 1:完成实训 def game_status game_challenge = @game.challenge # @had_done 1 已通关 (@myshixun.games.count == game_challenge.position && @game.status ==2) ? had_done = 1 : had_done = 0 - # 下一关自动开启 - if had_done != 1 && @game.status == 2 - @game.next_game.update_attribute(:status, 0) + # 全部通关奖励1000分 + if had_done == 1 + reward_grade(@game.user, @game.id, @game.class, 1000) @myshixun.update_attribute(:status, 1) + else + # 通过当前一关 + if @game.status == 2 + @game.next_game.update_attribute(:status, 0) + reward_grade(@game.user, @game.id, @game.class, game_challenge.score) + end end test_sets = game_challenge.test_sets unless test_sets.blank? total_test_sets = test_set_static_data(test_sets) end - test_sets_count = test_sets.count - test_sets_hidden_count = test_sets.where(:is_public => false).count - final_score = @game.final_score.to_i - # @had_tested如果已评测过,output中至少会有一条记录 - had_tested = Output.where(:game_id => @game.id).count - had_passed_testsests = Output.where(:game_id => @game.id, :result => true).count - # 出错的测试用例序号 - error_position = Output.where(:game_id => @game.id, :result => false).last - static_error_position = error_position.blank? ? 0 : error_position.try(:test_set_position).to_i - consume_time = @game.status == 2 ? game_spend_time(@game.open_time, @game.updated_at) : game_spend_time(@game.open_time, Time.now) + + logger.info("#################################{@public_test_sets}") + @test_sets_count = test_sets.count + @test_sets_hidden_count = test_sets.blank? ? 0 :test_sets.select{|test_set| test_set.is_public == false}.count + @test_sets_public_count = @test_sets_count - @test_sets_hidden_count + had_test = @game.outputs + @had_test_count = had_test.count + @had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count + @had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count + @had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count + @final_score = @game.final_score.to_i + @had_done = (@myshixun.games.where(:status => 2).count == @myshixun.games.count ? 1 : 0) + error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last + @latest_output = error_position.try(:out_put).gsub("\r\n", "
") unless error_position.try(:out_put).blank? + # test_sets_count = test_sets.count + # test_sets_hidden_count = test_sets.where(:is_public => false).count + # final_score = @game.final_score.to_i + # # @had_tested如果已评测过,output中至少会有一条记录 + # had_tested = Output.where(:game_id => @game.id).count + # had_passed_testsests = Output.where(:game_id => @game.id, :result => true).count + # # 出错的测试用例序号 + # error_position = Output.where(:game_id => @game.id, :result => false).last + # static_error_position = error_position.blank? ? 0 : error_position.try(:test_set_position).to_i + # consume_time = @game.status == 2 ? game_spend_time(@game.open_time, @game.updated_at) : game_spend_time(@game.open_time, Time.now) # 异常结果 latest_output = error_position.try(:out_put).gsub("\r\n", "
").html_safe unless error_position.try(:out_put).blank? - render :json => {test_sets: total_test_sets, status: @game.status, had_done: had_done, latest_output: latest_output, error_position: static_error_position, - had_passed_testsests:had_passed_testsests, test_sets_count:test_sets_count, test_sets_hidden_count:test_sets_hidden_count, - final_score:final_score, had_tested:had_tested, consume_time: consume_time} + render :json => {test_sets: total_test_sets, + test_sets_count: @test_sets_count, + test_sets_hidden_count: @test_sets_hidden_count, + test_sets_public_count: @test_sets_public_count, + had_test_count: @had_test_count, + had_passed_testsests_error_count: @had_passed_testsests_error_count, + had_passed_testsests_hidden_count: @had_passed_testsests_hidden_count, + had_passed_testsests_public_count: @had_passed_testsests_public_count, + final_score: @final_score, + latest_output: @latest_output, + status: @game.status, + had_done: had_done} end def change_status @@ -216,21 +242,40 @@ class GamesController < ApplicationController # 如果已看过,下次可以免费查看 # viewed 1: 直接查看 2:弹框提示将要扣除积分,确定后显示内容 3:弹框提示分数不够 def answer + challenge = @game.challenge + user = User.current + @challenge_score = challenge.score.to_i + user_score = user.grade.to_i + @score = user_score - @challenge_score + # 已经开启过 + @answer = challenge.answer + if @game.answer_open + @viewed = 1 + else + if @score >= 0 + @viewed = 2 + else + @viewed = 3 + end + end + respond_to do |format| + format.js + end + end + + def minus_score challenge = @game.challenge user = User.current challenge_score = challenge.score.to_i user_score = user.grade.to_i @score = user_score - challenge_score - # 已经开启过 - if @game.answer_open - render :json => {:answer => challenge.answer, :viewed => 1} - else - if @score > 0 - user.update_column(:grade, @score) - render :json => {:answer => challenge.answer, :viewed => 2} - else - render :json => {:answer => false, :viewed => 3} - end + @answer = challenge.answer + + user.update_column(:grade, @score) + @game.update_column(:answer_open, true) + + respond_to do |format| + format.js end end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index d291ff729..fe64be14f 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -27,16 +27,14 @@ class MyshixunsController < ApplicationController output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first if output.nil? game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], - :actual_output => actual_output, :result => j_test_set['passed'].to_i) + :actual_output => actual_output, :result => j_test_set['passed'].to_i, :is_public => j_test_set['isPublic'].to_i) else - output.update_attributes(:code => status, :out_put => outPut, :actual_output => actual_output.force_encoding("utf-8"), :result => j_test_set['passed'].to_i) + output.update_attributes(:code => status, :out_put => outPut, :actual_output => actual_output, :result => j_test_set['passed'].to_i) end - end end if status == "0" - game.update_attribute(:status, 2) - game.update_attribute(:final_score, challenge.score) + game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now) else game.update_attribute(:status, 0) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 383651ffa..65bfb0a05 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,7 +37,7 @@ module ApplicationHelper def reward_grade(user, container_id, container_type, score) grade = Grade.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first unless grade.nil? - user.update_column(:grade, (500 + user.grade.to_i)) + user.update_column(:grade, (score.to_i + user.grade.to_i)) Grade.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score) end end diff --git a/app/models/game.rb b/app/models/game.rb index 0bed87484..79f4426fe 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,7 +1,7 @@ class Game < ActiveRecord::Base # stauts 0: can exe 1:doing 2:successed 3:locked default_scope :order => 'created_at desc' - attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier + attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier, :answer_open, :end_time belongs_to :myshixun,:touch=> true belongs_to :user belongs_to :challenge @@ -14,7 +14,6 @@ class Game < ActiveRecord::Base identifier end - def last_game challenge = self.challenge last_challenge_id = challenge.last_challenge diff --git a/app/views/challenges/_form.html.erb b/app/views/challenges/_form.html.erb index 62cb6a08e..ba39f7da9 100644 --- a/app/views/challenges/_form.html.erb +++ b/app/views/challenges/_form.html.erb @@ -104,11 +104,11 @@
  • - <%= f.text_field :path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件,如:app/controllers/welcome_controller.rb", :maxlength => "256" %> + <%= f.text_field :path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件,如:src/test/welcome.java", :maxlength => "256" %>
  • - <%= f.text_field :exec_path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "输入关卡需要执行的文件路径,如:app/controllers/welcome_controller.rb", :maxlength => "256" %> + <%= f.text_field :exec_path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "输入关卡需要执行的文件路径,如:src/test/main.java", :maxlength => "256" %>
  • diff --git a/app/views/games/_acquire_answer.html.erb b/app/views/games/_acquire_answer.html.erb new file mode 100644 index 000000000..a5043fabc --- /dev/null +++ b/app/views/games/_acquire_answer.html.erb @@ -0,0 +1,16 @@ +
    +
    +
    + +
    +
    +
    + \ No newline at end of file diff --git a/app/views/games/_code_actions.html.erb b/app/views/games/_code_actions.html.erb index a4d8d81f2..766956126 100644 --- a/app/views/games/_code_actions.html.erb +++ b/app/views/games/_code_actions.html.erb @@ -26,7 +26,7 @@ var consumeTime = 0; // 耗时 <% if @game.status == 2 %> startTime = (new Date("<%= consume_time(@game.open_time) %>")).getTime(); - endTime = (new Date("<%= consume_time(@game.updated_at) %>")).getTime(); + endTime = (new Date("<%= consume_time(@game.end_time) %>")).getTime(); consumeTime = parseInt(endTime - startTime); <% else %> startTime = (new Date("<%= consume_time(@game.open_time) %>")).getTime(); @@ -80,13 +80,22 @@ console.log( eval('[' + data.test_sets + ']')); var html = bt('t:exec_results_1',{ "test_sets": eval('[' + data.test_sets + ']'), - error_position: data.error_position, +// error_position: data.error_position, +// test_sets_count: data.test_sets_count, +// test_sets_hidden_count: data.test_sets_hidden_count, +// final_score: data.final_score, +// passed_teststest: data.had_passed_testsests, +// latest_output: data.latest_output, +// game_outputs_count: data.had_tested, + had_test_count: data.had_test_count, test_sets_count: data.test_sets_count, + had_passed_testsests_error_count: data.had_passed_testsests_error_count, test_sets_hidden_count: data.test_sets_hidden_count, + test_sets_public_count: data.test_sets_public_count, + had_passed_testsests_hidden_count: data.had_passed_testsests_hidden_count, + had_passed_testsests_public_count: data.had_passed_testsests_public_count, final_score: data.final_score, - passed_teststest: data.had_passed_testsests, - latest_output: data.latest_output, - game_outputs_count: data.had_tested + latest_output: data.latest_output }); console.log(html); $("#game_test_set_results").html(html); diff --git a/app/views/games/_game_answer_error_pop.html.erb b/app/views/games/_game_answer_error_pop.html.erb new file mode 100644 index 000000000..549cfb593 --- /dev/null +++ b/app/views/games/_game_answer_error_pop.html.erb @@ -0,0 +1,17 @@ +
    +
    +

    提示

    + +
    +
    +
    +
      +
    • + 333333333333333333333333333 +
    • +
    +
    +
    + \ No newline at end of file diff --git a/app/views/games/_game_answer_tip_pop.html.erb b/app/views/games/_game_answer_tip_pop.html.erb new file mode 100644 index 000000000..ff3fbfc8a --- /dev/null +++ b/app/views/games/_game_answer_tip_pop.html.erb @@ -0,0 +1,31 @@ +
    +
    +

    提示

    + +
    +
    +
    + <% if @viewed == 2 %> +
      +
    • + 将扣除<%= @challenge_score %>点积分
      是否确认查看答案 +
    • +
      + 取消 + 确定 +
      + <% else %> +
    • + 本操作需要扣除<%= @challenge_score %>点积分
      你的积分不够 +
    • + <% end %> +
    +
    +
    + \ No newline at end of file diff --git a/app/views/games/_game_results.html.erb b/app/views/games/_game_results.html.erb index 2b290c001..32c8e3ec8 100644 --- a/app/views/games/_game_results.html.erb +++ b/app/views/games/_game_results.html.erb @@ -18,10 +18,10 @@
    - - + +

    - / + /

    @@ -60,10 +60,10 @@

    - - + +

    - / + /

    @@ -74,8 +74,8 @@

      -
    • 通过情况:/
    • -
    • 隐藏测试:/
    • +
    • 公开测试:/
    • +
    • 隐藏测试:/
    • 经验值:+
    @@ -95,14 +95,17 @@ // console.log("<%#= @public_test_sets.join(',').html_safe %>"); var html = bt('t:exec_results_1',{ test_sets: [<%= @test_sets.html_safe unless @test_sets.blank? %>], -// hide_test_sets: [<%#= @private_test_sets.html_safe unless @private_test_sets.blank? %>], - error_position: '<%= @error_position %>', +// hide_test_sets: [<%#= @private_test_sets.html_safe unless @private_test_sets.blank? %>] + had_test_count: '<%= @had_test_count %>', test_sets_count: '<%= @test_sets_count %>', - test_sets_hidden_count: '<%= @test_sets_hidden_count %>', + had_passed_testsests_error_count: '<%= @had_passed_testsests_error_count %>', + test_sets_hidden_count : '<%= @test_sets_hidden_count %>', + test_sets_public_count: '<%= @test_sets_public_count %>', + had_passed_testsests_hidden_count: '<%= @had_passed_testsests_hidden_count %>', + had_passed_testsests_public_count: '<%= @had_passed_testsests_public_count %>', final_score: '<%= @final_score %>', - passed_teststest: '<%= @had_passed_testsests %>', - latest_output: '<%= @latest_output.html_safe unless @latest_output.blank? %>', - game_outputs_count: '<%= @had_tested %>' + had_done: '<%= @had_done %>', + latest_output: '<%= @latest_output %>' } ); $("#game_test_set_results").html(html); @@ -121,158 +124,4 @@ $("#test_case_"+id).toggle(); } } - - - - - - -<% if false %> - - - - -<% end %> \ No newline at end of file + \ 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 984e9d5bc..ca63de3dc 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -18,12 +18,13 @@
  • 预备知识
  • -
  • - <% if @game.answer_open %> +
  • + 参考答案 +
  • 经验值:<%= @game_challenge.score %> @@ -51,9 +52,8 @@
    - +
    -
    @@ -119,13 +119,7 @@ flowChart : true, // 默认不解析 sequenceDiagram : true // 默认不解析 }); - answer_md = editormd.markdownToHTML("game_answer_show", { - htmlDecode : "style,script,iframe", // you can filter tags decode - taskList : true, - tex : false, // 数学公式 - flowChart : true, // 默认不解析 - sequenceDiagram : true // 默认不解析 - }); + /* myCodeMirror.setSize("auto", "auto");//设置版本库codemirror的高度 $("#game_answer_show").find(".CodeMirror-scroll").css("margin-bottom", 0); $("#game_answer_show" ).children(".CodeMirror").css("line-height", 1.2); @@ -133,6 +127,11 @@ // 设置图片最大宽度不能超出边框 $('#task_pass_contents').find('img').css("max-width", "100%"); }); + $("#tab_nav_3").click(function(){ + $.ajax({ + url: '<%= answer_myshixun_game_path(@game, :myshixun_id => @myshixun) %>' + '.js' + }); + }); function error_correction_pop(){ var htmlvalue = "<%= escape_javascript(render :partial => 'games/send_error_pop') %>"; pop_box_new(htmlvalue,460,316); diff --git a/app/views/games/answer.js.erb b/app/views/games/answer.js.erb new file mode 100644 index 000000000..15f9926bb --- /dev/null +++ b/app/views/games/answer.js.erb @@ -0,0 +1,10 @@ +<% if @viewed == 1 %> + $("#tab_con_3").html('<%= j (render :partial => 'games/acquire_answer') %>'); + $("#tab_nav_1").removeClass('tab_hover'); + $("#tab_nav_2").removeClass('tab_hover'); + $("#tab_nav_3").addClass('tab_hover'); + $("#tab_con_3").show(); +<% else %> + var htmlvalue = "<%= escape_javascript(render :partial => 'game_answer_tip_pop') %>"; + pop_box_new(htmlvalue,460,300); +<% end %> \ No newline at end of file diff --git a/app/views/games/minus_score.js.erb b/app/views/games/minus_score.js.erb new file mode 100644 index 000000000..c9c8dd115 --- /dev/null +++ b/app/views/games/minus_score.js.erb @@ -0,0 +1,5 @@ +$("#tab_con_3").html('<%= j (render :partial => 'games/acquire_answer') %>'); +$("#tab_nav_1").removeClass('tab_hover'); +$("#tab_nav_2").removeClass('tab_hover'); +$("#tab_nav_3").addClass('tab_hover'); +$("#tab_con_3").show(); diff --git a/app/views/layouts/base_edu.html.erb b/app/views/layouts/base_edu.html.erb index 727cc1704..06c929c72 100644 --- a/app/views/layouts/base_edu.html.erb +++ b/app/views/layouts/base_edu.html.erb @@ -28,7 +28,7 @@
    diff --git a/app/views/layouts/base_myshixun.html.erb b/app/views/layouts/base_myshixun.html.erb index 34640f39c..3ea92ba82 100644 --- a/app/views/layouts/base_myshixun.html.erb +++ b/app/views/layouts/base_myshixun.html.erb @@ -58,12 +58,14 @@