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
|
||||
def initialize
|
||||
@one, @two = Player.new(:one, name: 'Player One'),
|
||||
Player.new(:two, name: 'Player Two')
|
||||
def initialize(name_one = nil, name_two = nil)
|
||||
@one, @two = Player.new(:one),
|
||||
Player.new(:two)
|
||||
@one.name = name_one unless name_one.nil?
|
||||
@two.name = name_two unless name_two.nil?
|
||||
end
|
||||
|
||||
def add_point(colour)
|
||||
|
||||
@ -7,9 +7,8 @@ class Player
|
||||
counter :score
|
||||
counter :games
|
||||
|
||||
def initialize(id, attr = {})
|
||||
def initialize(id)
|
||||
@id = id
|
||||
self.name = attr[:name]
|
||||
end
|
||||
|
||||
def has_beaten(player)
|
||||
|
||||
@ -26,6 +26,14 @@ class Scoreboard < Sinatra::Base
|
||||
erb :index, locals: { scores: match.scores }
|
||||
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
|
||||
match.reset_scores
|
||||
match.reset_games
|
||||
@ -63,7 +71,7 @@ class Scoreboard < Sinatra::Base
|
||||
private
|
||||
|
||||
def match
|
||||
Match.new
|
||||
@match ||= Match.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user