45 lines
702 B
Plaintext
45 lines
702 B
Plaintext
package net.doorstuck.vehicles
|
|
|
|
protocol Vehicle
|
|
- startup
|
|
- shutdown
|
|
- nr-wheels
|
|
- nr-doors
|
|
- turn(direction:dir)
|
|
- accelerate(direction:dir)
|
|
- velocity
|
|
end
|
|
|
|
class Car <Vehicle>
|
|
- startup
|
|
self.engine-running = true
|
|
end
|
|
|
|
- shutdown
|
|
self.engine-running = false
|
|
end
|
|
|
|
- nr-wheels
|
|
^4
|
|
end
|
|
|
|
- nr-doors
|
|
^4
|
|
end
|
|
|
|
- turn(direction:dir)
|
|
self.current-direction = dir
|
|
end
|
|
|
|
- accelerate(direction:dir)
|
|
match dir
|
|
$forward => self.current-velocity += 1,
|
|
$backward => self.current-velocity -= 1,
|
|
end
|
|
end
|
|
|
|
- velocity
|
|
^self.current-velocity
|
|
end
|
|
end
|