Files
ivy/doc/sample/Vehicle.im

45 lines
702 B
Plaintext
Raw Normal View History

2024-11-02 15:11:00 +00:00
package net.doorstuck.vehicles
protocol Vehicle
- startup
- shutdown
2025-11-07 10:07:44 +00:00
- nr-wheels
- nr-doors
2024-11-02 15:11:00 +00:00
- turn(direction:dir)
- accelerate(direction:dir)
- velocity
end
class Car <Vehicle>
- startup
2025-11-07 10:07:44 +00:00
self.engine-running = true
2024-11-02 15:11:00 +00:00
end
- shutdown
2025-11-07 10:07:44 +00:00
self.engine-running = false
2024-11-02 15:11:00 +00:00
end
2025-11-07 10:07:44 +00:00
- nr-wheels
2024-11-02 15:11:00 +00:00
^4
end
2025-11-07 10:07:44 +00:00
- nr-doors
2024-11-02 15:11:00 +00:00
^4
end
- turn(direction:dir)
2025-11-07 10:07:44 +00:00
self.current-direction = dir
2024-11-02 15:11:00 +00:00
end
- accelerate(direction:dir)
match dir
2025-11-07 10:07:44 +00:00
$forward => self.current-velocity += 1,
$backward => self.current-velocity -= 1,
2024-11-02 15:11:00 +00:00
end
end
2025-11-07 10:07:44 +00:00
- velocity
^self.current-velocity
2024-11-02 15:11:00 +00:00
end
end