Skip to content

@metaperl /gist:8475149
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class TennisGame(names : Array[String]) {
require(names.length == 2)
val player = Array[TennisPlayer] = names.map(n => new TennisPlayer(n))
def _score = player.map(p => p.point.count)
def score = {
scores = _score.sort
if scores[0] == scores[1] and scores[0] >= 3 "deuce"
else if scores[0] > 4 {
if scores[0] - scores[1] >= 2 describeVictory
else describeAdvantage
}
else simpleScore
def _winPoint(playerId) = player[playerId].winPoint
}
object PlayerScores(val player) {
}
class TennisPlayer(_name: String) {
name = _name
point = new TennisPoint()
def winPoint = point.increase
}
class TennisPoint {
count = 0
name = count match {
case 0 => "love"
case 1 => "fifteen"
case 2 => "thirty"
case 3 => "forty"
}
def increase = ++count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.