목차

이전 항목

11. Fixing the leak

다음 항목

13. Conclusion

현재 문서

주의사항

해당 문서는 중요 변경 작업 중에 있습니다. 일부 문서에 텍스트가 빠져있거나, 불어로 플레이스홀더(placeholder) 자리차지만 되어 있을 수 있습니다.

12. Putting it all together!

You now know how to fix Reeborg. So, you have to do it. In your library, define a new class of robots, using the following outline as a model:

class RepairedRobot(UsedRobot):

    def __init__(self, x=1, y=1, orientation='e', tokens=0, leaky=False):
        pass

    def turn_right(self):
        pass

    def turn_around(self):
        pass

    def is_facing_south(self):
        pass

    def is_facing_east(self):
        pass

    def is_facing_west(self):
        pass

    def face_south(self):
        pass

    def face_east(self):
        pass

    def face_north(self):
        pass

    def face_west(self):
        pass

    def left_is_clear(self):
        pass

Then, you can test your code by running the following program which will make use of the code you wrote in your library.

World("Empty")
from test_repair import test

test()

The result should look like the image below. Pay close attention to the details of the trace left by the oil leak and make sure your result looks identical.

image0

12.1. Congratulations!

I assume that you did manage to reproduce the image above. If so, you have made much progress in understanding Object-Oriented Programming using Python and are ready to move on to another tutorial.