Created
January 17, 2014 15:20
-
-
Save metaperl/8475149 to your computer and use it in GitHub Desktop.
so far solution of tennis problem - http://technologyconversations.wordpress.com/2014/01/16/scala-tutorial-through-katas-tennis-game-easy/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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