mirror of
https://github.com/danbee/scoreboard
synced 2025-03-04 08:59:11 +00:00
Add game logic.
This commit is contained in:
parent
174242f824
commit
5661ed25c9
@ -7,6 +7,15 @@ class Match
|
|||||||
|
|
||||||
def add_point(player)
|
def add_point(player)
|
||||||
@players[player].add_point
|
@players[player].add_point
|
||||||
|
if @players[:one].has_beaten(@players[:two])
|
||||||
|
@players[:one].reset_score
|
||||||
|
@players[:two].reset_score
|
||||||
|
@players[:one].add_game
|
||||||
|
elsif @players[:two].has_beaten(@players[:one])
|
||||||
|
@players[:one].reset_score
|
||||||
|
@players[:two].reset_score
|
||||||
|
@players[:two].add_game
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def scores
|
def scores
|
||||||
|
|||||||
@ -14,10 +14,18 @@ class Player
|
|||||||
@score += 1
|
@score += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_game
|
||||||
|
@games += 1
|
||||||
|
end
|
||||||
|
|
||||||
def undo_point
|
def undo_point
|
||||||
@score -= 1
|
@score -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_score
|
||||||
|
@score = 0
|
||||||
|
end
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
{ score: @score, games: @games }
|
{ score: @score, games: @games }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -22,6 +22,11 @@ class ScoreBoard < Sinatra::Base
|
|||||||
two: @@match.players[:two] }
|
two: @@match.players[:two] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
put '/reset_scores' do
|
||||||
|
@@match = Match.new(Player.new, Player.new)
|
||||||
|
push_scores
|
||||||
|
end
|
||||||
|
|
||||||
put '/player1_scores' do
|
put '/player1_scores' do
|
||||||
@@match.add_point(:one)
|
@@match.add_point(:one)
|
||||||
push_scores
|
push_scores
|
||||||
|
|||||||
@ -37,6 +37,12 @@
|
|||||||
#player2-score .score { left: 5rem; }
|
#player2-score .score { left: 5rem; }
|
||||||
#player1-score .games { left: 5rem; }
|
#player1-score .games { left: 5rem; }
|
||||||
#player2-score .games { right: 5rem; }
|
#player2-score .games { right: 5rem; }
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0; left: 0; right: 0;
|
||||||
|
height: 2rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="//js.pusher.com/2.2/pusher.min.js"></script>
|
<script src="//js.pusher.com/2.2/pusher.min.js"></script>
|
||||||
@ -57,15 +63,14 @@
|
|||||||
$('#player2-score .games').text(data.two.games);
|
$('#player2-score .games').text(data.two.games);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset = function () {
|
resetScores = function () {
|
||||||
resetScores();
|
$.ajax({method: 'PUT',
|
||||||
resetGames();
|
url: '/reset_scores',
|
||||||
updateScores();
|
data: ''});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
updateScores(scores);
|
$('#reset').on('click', resetScores);
|
||||||
$('#reset').on('click', reset);
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user