Permalink
Browse files

polish calc_team scoring

  • Loading branch information...
1 parent b614566 commit 6d512a0f9de7cd4abc636adbc6dfe69cdea69e98 @geraldb geraldb committed Jun 24, 2012
@@ -0,0 +1,43 @@
+class Db::CalcGamesController < Db::BaseController
+
+ # GET /calc_games/new
+ def new
+ @game = CalcGame.new
+ end
+
+ # POST /calc_games
+ def create
+ @game = CalcGame.new(params[:calc_game])
+
+ if @game.save
+ redirect_to games_path(), :notice => 'Spiel erfolgreich gespeichert.'
+ else
+ render :action => 'new'
+ end
+ end
+
+ # GET /calc_games/1/edit
+ def edit
+ @game = CalcGame.find(params[:id])
+ end
+
+ # PUT /calc_games/1
+ def update
+ @game = CalcGame.find(params[:id])
+
+ if @game.update_attributes(params[:calc_game])
+ redirect_to games_path(), :notice => 'Spiel erfolgreich gespeichert.'
+ else
+ render :action => 'edit'
+ end
+ end
+
+ # DELETE /calc_games/1
+ def destroy
+ @game = CalcGame.find(params[:id])
+ @game.destroy
+
+ redirect_to games_path()
+ end
+
+end # class CalcGamesController
View
@@ -34,5 +34,39 @@ class CalcTip < Tip
def do_after_initialize
self.calc = true # make sure calc flag is true
end
+
+ ## note: use different calc forumula
+ # check for matching teams first
+ # before checking scoring
+
+ def calc_points
+ pts = 0
+
+ ## step 1: teams must match for any points (scoring)
-end # class CalcTip
+ if (complete? &&
+ game.team1_id == calc_team1_id &&
+ game.team2_id == calc_team2_id)
+
+ if(((game.score1 == game.score2) && (score1 == score2)) ||
+ ((game.score1 > game.score2) && (score1 > score2)) ||
+ ((game.score1 < game.score2) && (score1 < score2)))
+ pts += 1
+ end
+
+ # tordifferenz richtig? todo: auch fuer unentschieden???
+ if((game.score1-game.score2) == (score1-score2))
+ ## nb: for now now points for tordifferenz
+ ### pts +=1
+ end
+
+ # ergebnis richtig?
+ if game.score1 == score1 && game.score2 == score2
+ pts += 2
+ end
+ end
+ pts
+ end
+
+
+end # class CalcTip
View
@@ -164,7 +164,12 @@ def bingo_text
else
pts = calc_points()
if pts == 0
- "× Leider, nein. Richtiger Tipp #{game.toto12x}." # return 1,2,X from game
+ if game.calc? && (game.team1_id != calc_team1_id || game.team2_id != calc_team2_id )
+ ## sorry, wrong teams - show team1 n team2 tags
+ "× Leider, nein. Richtige Spielpaarung (#{game.team1.tag}) - (#{game.team2.tag})."
+ else
+ "× Leider, nein. Richtiger Tipp #{game.toto12x}." # return 1,2,X from game
+ end
elsif pts == 1
'♣ 1 Pkt - Ja!'
elsif pts == 2
@@ -0,0 +1,73 @@
+
+<%= form_for(@game) do |f| %>
+ <% if @game.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@game.errors.count, "error") %> prohibited this game from being saved:</h2>
+
+ <ul>
+ <% @game.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <table>
+ <tr>
+ <td><%= f.label :round_id, 'Runde:' %></td>
+ <td>(<%= f.object.round_id %>)</td>
+ <td><%= f.select :round_id, ([[ '- Runde wählen -', nil ]] + Round.all.map { |rec| [ "#{rec.event.title} / #{rec.title}", rec.id ] }) %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :pos, 'Lfd#:' %></td>
+ <td></td>
+ <td><%= f.text_field :pos, size: '3' %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :team1_id, 'Team 1:' %></td>
+ <td>(<%= f.object.team1_id %>)</td>
+ <td><%= f.select :team1_id, options_from_collection_for_select( Team.all, :id, :title, f.object.team1_id) %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :score1, 'Tore 1:' %></td>
+ <td></td>
+ <td><%= f.text_field :score1, size: '3' %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :score2, 'Tore 2:' %></td>
+ <td></td>
+ <td><%= f.text_field :score2, size: '3' %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :team2_id, 'Team 2:' %></td>
+ <td>(<%= f.object.team2_id %>)</td>
+ <td><%= f.select :team2_id, options_from_collection_for_select( Team.all, :id, :title, f.object.team2_id) %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :locked, 'Locked Flag:' %></td>
+ <td></td>
+ <td>
+ <%= f.radio_button :locked, 'true' %><%= f.label :locked_true, 'Ja' %>
+ <%= f.radio_button :locked, 'false' %><%= f.label :locked_false, 'Nein' %>
+ </td>
+ </tr>
+ <tr>
+ <td><%= f.label :knockout, 'Knockout Flag:' %></td>
+ <td></td>
+ <td>
+ <%= f.radio_button :knockout, 'true' %><%= f.label :knockout_true, 'Ja' %>
+ <%= f.radio_button :knockout, 'false' %><%= f.label :knockout_false, 'Nein' %>
+ </td>
+ </tr>
+ <tr>
+ <td><%= f.label :play_at, 'Datum:' %></td>
+ <td></td>
+ <td><%= f.text_field :play_at %></td>
+ </tr>
+ </table>
+
+ <div class="actions">
+ <%= f.submit 'Speichern', :class => 'btn-primary' %>
+ <%= link_to 'Zurück', games_path(), :class => 'btn' %>
+ </div>
+<% end %>
@@ -0,0 +1,3 @@
+<h1>Spiel (Calc) Bearbeiten</h1>
+
+<%= render 'form' %>
@@ -0,0 +1,3 @@
+<h1>Neues Spiel (Calc)</h1>
+
+<%= render 'form' %>
@@ -33,7 +33,7 @@
</td>
<td><%= game.play_at %></td>
<td><%= game.play_at.utc %></td>
- <td><%= link_to 'Bearbeiten', edit_game_path( game ), :class => 'btn' %></td>
+ <td><%= link_to 'Bearbeiten', game.calc? ? edit_calc_game_path(game) : edit_game_path( game ), :class => 'btn' %></td>
</tr>
<% end %><!-- games.each -->
<% end %><!-- rounds.each -->
View
@@ -62,6 +62,7 @@
scope :module => 'db' do
resources :rounds
resources :games
+ resources :calc_games
resources :teams
resources :events do

0 comments on commit 6d512a0

Please sign in to comment.