Skip to content

Instantly share code, notes, and snippets.

@thanhluu
Created April 29, 2016 14:13
Show Gist options
  • Save thanhluu/00634b0af3dd0bad5e9ba60db4f93805 to your computer and use it in GitHub Desktop.
Save thanhluu/00634b0af3dd0bad5e9ba60db4f93805 to your computer and use it in GitHub Desktop.
Bai Tap Class
class Point {
var x: Int
var y: Int
init(x: Int, y: Int){
self.x = x
self.y = y
}
}
class Machine {
var location: Point
init() {
self.location = Point(x: 0, y: 0)
}
func move(direction: String) {
print("Do nothing! I'm a machine!")
}
}
// Enter your code below
class Robot: Machine {
override init() {
super.init()
self.location = Point(x: 0, y: 0)
}
override func move(direction: String) {
switch direction {
case "Up": self.location.y = self.location.y + 1
case "Down": self.location.y = self.location.y - 1
case "Left": self.location.x = self.location.x - 1
case "Right": self.location.x = self.location.x + 1
default: print("Do nothing! I'm not move!")
}
}
}
var newRobot = Robot()
newRobot.location.y
newRobot.move("Up")
newRobot.location.y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment