Skip to content

Instantly share code, notes, and snippets.

@metaperl
Created January 17, 2014 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaperl/8475149 to your computer and use it in GitHub Desktop.
Save metaperl/8475149 to your computer and use it in GitHub Desktop.
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