Skip to content

Instantly share code, notes, and snippets.

@HDBandit
Created August 17, 2016 20:46
Show Gist options
  • Save HDBandit/8e060ec47f02c65caf061b658f9dc2b8 to your computer and use it in GitHub Desktop.
Save HDBandit/8e060ec47f02c65caf061b658f9dc2b8 to your computer and use it in GitHub Desktop.
import com.hdbandit.dsl.Speed._
object Robot {
def newRobot(initialXposition: Int = 0, initialYposition: Int = 0): Robot = new Robot(initialXposition, initialYposition)
}
class Robot(initialXposition: Int, initialYposition: Int) {
private var previousX = -1
private var previousY = -1
private var xPosition = initialXposition
private var yPosition = initialYposition
private var speed = 0.km_hour
def at(s: Speed): Robot = {
speed = Speed(s.value)
this
}
def towards(coordinate: (Int, Int)): Robot = {
previousX = xPosition
previousY = yPosition
xPosition = coordinate._1
yPosition = coordinate._2
println(s"Moving the robot from (x=$previousX, y=$previousY) to (x=$xPosition, y=$yPosition) with speed: $speed")
this
}
def go(): Unit = {
println(s"Moving the robot from (x=$previousX, y=$previousY) to (x=$xPosition, y=$yPosition) with speed: $speed")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment