Created
May 1, 2016 14:28
-
-
Save thanhluu/65528763ba8db4a8e6c18fc8ef1344dd to your computer and use it in GitHub Desktop.
Bai Tap Enum
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 Point { | |
var x: Int | |
var y: Int | |
init(x: Int, y: Int){ | |
self.x = x | |
self.y = y | |
} | |
} | |
enum Direction { | |
case Left | |
case Right | |
case Up | |
case Down | |
} | |
class Robot { | |
var location: Point | |
init() { | |
self.location = Point(x: 0, y: 0) | |
} | |
func move(direction: Direction) { | |
// Enter your code below | |
switch direction { | |
case .Up: self.location.y++ | |
case .Down: self.location.y-- | |
case .Right: self.location.x++ | |
case .Left: self.location.x-- | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment