mirror of
https://github.com/danbee/scoreboard
synced 2025-03-04 08:59:11 +00:00
Add new_game route with ability to set names.
This commit is contained in:
parent
34c2ceec43
commit
2d30fa3398
@ -1,7 +1,9 @@
|
|||||||
class Match
|
class Match
|
||||||
def initialize
|
def initialize(name_one = nil, name_two = nil)
|
||||||
@one, @two = Player.new(:one, name: 'Player One'),
|
@one, @two = Player.new(:one),
|
||||||
Player.new(:two, name: 'Player Two')
|
Player.new(:two)
|
||||||
|
@one.name = name_one unless name_one.nil?
|
||||||
|
@two.name = name_two unless name_two.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_point(colour)
|
def add_point(colour)
|
||||||
|
|||||||
@ -7,9 +7,8 @@ class Player
|
|||||||
counter :score
|
counter :score
|
||||||
counter :games
|
counter :games
|
||||||
|
|
||||||
def initialize(id, attr = {})
|
def initialize(id)
|
||||||
@id = id
|
@id = id
|
||||||
self.name = attr[:name]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_beaten(player)
|
def has_beaten(player)
|
||||||
|
|||||||
@ -26,6 +26,14 @@ class Scoreboard < Sinatra::Base
|
|||||||
erb :index, locals: { scores: match.scores }
|
erb :index, locals: { scores: match.scores }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
post '/new_game' do
|
||||||
|
@match = Match.new(params[:one], params[:two])
|
||||||
|
@match.reset_scores
|
||||||
|
@match.reset_games
|
||||||
|
push_scores
|
||||||
|
JSON match.scores
|
||||||
|
end
|
||||||
|
|
||||||
put '/reset_scores' do
|
put '/reset_scores' do
|
||||||
match.reset_scores
|
match.reset_scores
|
||||||
match.reset_games
|
match.reset_games
|
||||||
@ -63,7 +71,7 @@ class Scoreboard < Sinatra::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def match
|
def match
|
||||||
Match.new
|
@match ||= Match.new
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user