Created
April 29, 2016 14:13
-
-
Save thanhluu/00634b0af3dd0bad5e9ba60db4f93805 to your computer and use it in GitHub Desktop.
Bai Tap Class
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 | |
} | |
} | |
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