class implementation

markotaht at gmail.com markotaht at gmail.com
Tue Oct 8 04:20:00 EDT 2013


I cant just subclassing doesent work. It seem the init method of the source class also calls out another class. And the problem is, i can subclass the other class to with the required function but the end result is that it doesent work, since the source class cant accsess the subclass functions. 

The source code is pykkar. 

https://courses.cs.ut.ee/all/MTAT.03.100/2012_fall/uploads/opik/_downloads/pykkar.py

I want to add it a new ability called left(). I cant manipulate the source class, cause then my comp will be the only one where the program runs.

class pykkar_l(Pykkar):
    def left(self):
        self._world.execute("left")

    def _cmd_left(self):
        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)

class world_l(World):
    def left(self):
        self._world.execute("left")

These are my subclasses. For it to work. Class World, must obtain the method from subclass world_l



More information about the Python-list mailing list