Skip to content

Instantly share code, notes, and snippets.

@thanhluu
Created May 1, 2016 14:28
Show Gist options
  • Save thanhluu/65528763ba8db4a8e6c18fc8ef1344dd to your computer and use it in GitHub Desktop.
Save thanhluu/65528763ba8db4a8e6c18fc8ef1344dd to your computer and use it in GitHub Desktop.
Bai Tap Enum
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