[email protected] writes:
>
> OK so I did a took time of and read the pykkar code through. abd I found that
> there is a third class i have to implement.
[...]
> So I have come up with this code
> from pykkar import *
>
> create_world("""
> ########
> # #
> # v#
> # #
> # #
> # #
> ########
> """)
>
> class world_täiend(World):
> def left(self):
> world.excecute("left")
>
> class pykkar_täiend(Pykkar):
> def left(self):
> self._world.excecute("left")
>
> class _WorldProper_täiend(_WorldProper):
> def _cmd_right(self):
Should that not be _cmd_left?
> headings = (N,E,S,W)
> cur_tile = self._get_current_tile()
>
> cur_heading_index = headings.index(cur_tile.pykkar_heading)
> new_heading_index = (cur_heading_index - 1) % 4
> cur_tile.pykkar_heading = headings[new_heading_index]
>
> self._update_pykkar_image(cur_tile)
>
>
> left()
>
> When I run my code I get this error.
> Traceback (most recent call last):
> File "C:\Users\MarkoPC\Desktop\python\pykkar_test.py", line 21, in <module>
> class _WorldProper_täiend(_WorldProper):
> NameError: name '_WorldProper' is not defined
from import * doesn't import names that start with underscore (_). So therefore
_WorldProper is not defined.
from import * is considered bad practice anyway. It is better just to import
the things you need.
from pykkar import World, Pykkar, _WorldProper
I have looked a bit in this pykkar.py and I think it is badly structured for
extension. The three classes are too strongly connected and it is difficult to
get three subclasses connected in the proper way without duplicating code. But
anyway you will have to do that when you create your world.
--
Piet van Oostrum <[email protected]>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
--
https://mail.python.org/mailman/listinfo/python-list