Created
February 12, 2016 01:39
-
-
Save jasonnoble/75a380adfe3200e68cb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Player { | |
| var name:String | |
| var activeRound:Round | |
| init(name: String) { | |
| self.name = name | |
| self.activeRound = Round() | |
| } | |
| } | |
| class Round { | |
| var scores:[Int:HoleScore] | |
| init() { | |
| self.scores = [Int:HoleScore]() | |
| } | |
| func recordStrokes(strokes:Int, forHole hole:Int) -> Void { | |
| self.scores[hole] = HoleScore(strokes) | |
| } | |
| func isComplete() -> Bool { | |
| return scores.values.count == 18 | |
| } | |
| func totalScore() -> Int { | |
| var sum = 0 | |
| for score in scores.values { | |
| sum += score.strokeCount | |
| } | |
| return sum | |
| } | |
| } | |
| class HoleScore { | |
| var strokeCount:Int | |
| init(_ strokes:Int) { | |
| self.strokeCount = strokes | |
| } | |
| } | |
| let me = Player(name: "Brooks") | |
| me.activeRound.isComplete() | |
| me.activeRound.totalScore() | |
| me.activeRound.recordStrokes(4, forHole: 1) | |
| me.activeRound.totalScore() | |
| for holeNumber in 2...18 { | |
| me.activeRound.recordStrokes(5, forHole: holeNumber) | |
| } | |
| me.activeRound.totalScore() | |
| me.activeRound.isComplete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment