更新经验值和金币值

This commit is contained in:
daiao 2017-07-28 20:01:34 +08:00
parent 1e0ba96f82
commit dbd3ed3f18
5 changed files with 7 additions and 5 deletions

View File

@ -284,10 +284,11 @@ class GamesController < ApplicationController
correct = false
end
@game.update_attributes(:status => 2, :end_time => Time.now)
User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score)) if correct
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}
render :json => {correct: correct, had_done: had_done, :grade => User.current.grade}
end

View File

@ -40,7 +40,6 @@
<a href="<%= new_shixun_challenge_path(@shixun, :st => 0) %>" class="shixun-task-btn task-btn-green fr">+编程任务</a>
<a href="<%= new_shixun_challenge_path(@shixun, :st => 1) %>" class="shixun-task-btn task-btn-green fr mr10">+多选任务</a>
<a href="<%= new_shixun_challenge_path(@shixun, :st => 2) %>" class="shixun-task-btn task-btn-green fr mr10">+单选任务</a>
<% end %>
</div>
</div>

View File

@ -1,12 +1,12 @@
<div class="-layout -stretch -fit -vertical centerH">
<div class="split-panel--second -layout -vertical -flex -relative -bg-black" id="answer">
<ul id="blacktab_nav">
<li id="codetab_nav_1" class="blacktab_hover" style="overflow-y: auto;" onclick="HoverLi_new(1);">
<li id="codetab_nav_1" class="blacktab_hover" onclick="HoverLi_new(1);">
<a href="javascript:void(0);" class="tab_type tab_color" >答题选项</a>
</li>
</ul>
<div class="cl"></div>
<div id="codotab_con_1">
<div id="codotab_con_1" style="overflow-y: auto;">
<div class="panel-header clearfix" id="top_repository" style="border-bottom:0">
<p class="mb10 color-light-green font-16 <%= @game.outputs.blank? || !@game.outputs.first.result ? "undis" : "" %>" id="correct_tip">
<i class="fa fa-check-circle font-16"></i> 正确

View File

@ -94,6 +94,7 @@
$("#code_test").remove();
if(data.correct){
$("#correct_tip").show();
$("#user_grade").html(data.grade);
if( data.had_done == 0 ) {
$("#code_estimate").html("<a href='<%= next_step_myshixun_game_path(@game, :myshixun_id => @myshixun) %>' class='task-btn task-btn-blue mr15 mt8' id='next_step' data-remote='true'>下一关</a>");
var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game=> @game, :myshixun => @myshixun, :had_done => 0}) %>";
@ -103,6 +104,7 @@
}
// 传递具体屏幕的宽高,实现不同浏览器与不同分辨率都能撑满屏幕
pop_box_new2(htmlvalue, window.innerWidth, window.innerHeight);
}else{
$("#error_tip").show();
$("#code_estimate").html("<a href='<%= next_step_myshixun_game_path(@game, :myshixun_id => @myshixun) %>' class='task-btn task-btn-blue mr15 mt8' id='next_step' data-remote='true'>下一关</a>");

View File

@ -6,7 +6,7 @@
<div class="-layout-h mr10 fr mt3 -header-right-box">
<div class="-header-right clearfix">
<img src="/images/task/coin.png" class="fl" width="30" height="30">
<span class="ml5 color-white fl"><%= User.current.grade %></span>
<span class="ml5 color-white fl" id="user_grade"><%= User.current.grade %></span>
</div>
<!--<div class="-header-right-info ">-->
<!--<font></font>-->