Example #1
0
 def login(self):
     " События, когда пользователь заходит в онлайн "
     log_debug(self.name + " login")
     self.session["channel"] = None
     msg, p = self.get_welcome_message()
     Chat.announce(msg, p)
     msg_online = self.get_other_online_message()
     self.private_message(msg_online)
     Loc.enter(self)
Example #2
0
 def logout(self):
     " События, когда пользователь выходит из онлайна "
     log_debug(self.name + " logout")
     f = self.fighter()
     if f != None:
         f.slowpoke = True
         self.leave_fight()
     Loc.leave(self)
     Chat.unsubscribe(self.name)
Example #3
0
    def fall(self):
        # empty-below: return first matching or None next(filter(), None)
        # for each COL: top piece, check if it needs processing,
        # cols = for each x, range(0,sizey)
        # col = [Loc(x,y) for y in range(0,sizey)]
        # pieces = reversed(loc for loc in loc if self[loc] is not blank)
        # for P in pieces: below = loc.modified(1,1); if below is blank OR opposing: move below

        mkcol = lambda x: [Loc(x, y) for y in range(self.sizey)]
        notblank = lambda loc: self[loc] is not blank
        same_side = lambda a, b: self[a].id.lower() == self[b].id.lower()
        diff_side = lambda a, b: not same_side(a, b)
        in_bounds = lambda L: (0 <= L.x < self.sizex) and (0 <= L.y < self.
                                                           sizey)
        can_move = lambda a, b: in_bounds(b) and (self[b] is blank or
                                                  diff_side(a, b))

        cols = [mkcol(x) for x in range(self.sizex)]
        below = lambda L: L.modified(1, 1)
        moved = None
        n = 0
        while moved != 0:
            moved = 0
            for col in cols[:]:
                n += 1
                pieces = list(
                    reversed([loc for loc in col if self[loc] is not blank]))
                for loc in pieces[:]:
                    if can_move(loc, below(loc)):
                        p = self[loc]
                        new = below(loc)
                        p.move(new)
                        moved += 1
            if n > 50: break
Example #4
0
def line(loc1, loc2):
    coord = int(loc1[0] == loc2[0])
    n, m = loc1[coord], loc2[coord]
    assert m > n
    for a in range(n, m):
        opp = inverted(coord)
        yield Loc(vals={coord: a, opp: loc1[opp]})
Example #5
0
 def __init__(self, sizex, sizey, cursor=(0, 0)):
     self.cursor = Loc(*cursor)
     self.sizex, self.sizey = sizex, sizey
     self.board = [mkrow(sizex) for _ in range(sizey)]
     self.generated_viewports = set()
     self.messages = []
     self.gen_viewport()
Example #6
0
class Piece:
    def __init__(self, x, y, z):
        self.loc = Loc(x, y, z)
        self.neighbors = []

    def x(self):
        return self.loc.x

    def y(self):
        return self.loc.y

    def z(self):
        return self.loc.z

    def friend(self, piece):
        if self.legal_neighbor(piece):
            self.neighbors.append(piece)
            if not piece.is_friend(self):
                piece.friend(self)

    def legal_neighbor(self, piece):
        return self.loc.distance(piece.loc) == 1

    def is_friend(self, piece):
        return piece.loc in [x.loc for x in self.neighbors]

    def defriend(self, piece):
        self.neighbors = [x for x in self.neighbors if x.loc != piece.loc]
        if piece.is_friend(self):
            piece.defriend(self)

    def __repr__(self):
        return "Loc(" + str(self.loc) + ") Neighbors(" + str([x.loc for x in self.neighbors]) + ")"
Example #7
0
 def loc(self):
     if(len(self.filenames)==0):
         self.filenames = askopenfilenames()
     lineCount = 0
     blankLineCount = 0
     commentLineCount = 0
     importLineCount = 0
     final=0
     reportStr='The final result of LOC '
     for name in self.filenames:
         result=Loc(name)
         lineCount+=result.lineCount
         blankLineCount+=result.blankLineCount
         commentLineCount+=result.commentLineCount
         importLineCount+=result.importLineCount
         final = lineCount - blankLineCount - commentLineCount - importLineCount
     if(self.chkLoc1.get()):
         final+=commentLineCount
         reportStr+='with comment lines, '
     if(self.chkLoc2.get()):
         final+=blankLineCount
         reportStr+='empty lines, '
     if(self.chkLoc3.get()):
         final+=importLineCount
         reportStr+='import lines, '
     self.label2['text'] = reportStr + "is " +str(final)
Example #8
0
class Piece:
    def __init__(self, x, y, z):
        self.loc = Loc(x, y, z)
        self.neighbors = []

    def x(self):
        return self.loc.x

    def y(self):
        return self.loc.y

    def z(self):
        return self.loc.z

    def friend(self, piece):
        if self.legal_neighbor(piece):
            self.neighbors.append(piece)
            if not piece.is_friend(self):
                piece.friend(self)

    def legal_neighbor(self, piece):
        return self.loc.distance(piece.loc) == 1

    def is_friend(self, piece):
        return piece.loc in [x.loc for x in self.neighbors]

    def defriend(self, piece):
        self.neighbors = [x for x in self.neighbors if x.loc != piece.loc]
        if piece.is_friend(self):
            piece.defriend(self)

    def __repr__(self):
        return "Loc(" + str(self.loc) + ') Neighbors(' + str(
            [x.loc for x in self.neighbors]) + ')'
Example #9
0
 def add_platforms(self, v):
     # TODO: allow same height platforms
     last = None
     for rnd in (0.8, 0.8):
         if rand() > rnd:
             if vpsize.x - 10 > 5 and vpsize.y - 10 > 5:
                 sx = v.x + randrange(5, vpsize.x - 10)
                 sy = ey = v.y + randrange(5, vpsize.y - 10)
                 if not last or abs(sy - last) >= 4:
                     X = vpsize.x - 5
                     if X > sx:
                         ex = randrange(sx, vpsize.x - 5)
                         if ex - sx >= 4:
                             for loc in line(Loc(sx, sy), Loc(ex, ey)):
                                 if self[loc] == [ladder] and rand() > .5:
                                     pass
                                 else:
                                     self[loc] = rock
                     last = sy
Example #10
0
def createTest():
    print "createTest"
    worked = True
    header = ''
    meta_header = ''
    num_wrong = 0
    num_tested = 0
    with open("data/createTest.txt",
              'r') as input_file, open("data/createTest.log",
                                       'w') as output_file:
        for line in input_file.readlines():
            line = line.strip()
            if line[:2] == "#!":
                header = line[3:]
            elif line[:2] == "#@":
                meta_header = line[3:]
            elif line[:1] != "#":
                split = line.split(",")
                x, y, z, xd, yd, zd = [int(num) for num in split[:-1]]
                should_be_same = True if split[-1] == 'true' else False
                loc1 = Loc(x, y, z, True)
                loc2 = Loc(xd, yd, zd, False)
                same = (loc1 == loc2) == should_be_same
                worked = same and worked
                if not same:
                    num_wrong += 1
                num_tested += 1
                result = str(same) + '\n'
                full_result = "%s ------------\n%s\n%s\n%r\n%r\n" % (
                    same, meta_header, header, loc1, loc2)
                if debug == 2 or (debug == 1 and not same):
                    output_file.write(full_result)
                    sys.stdout.write(full_result)
                else:
                    output_file.write(result)

    print """Results:
debug: %s
%s
%s/%s succedded
""" % (debug, "Success!" if worked else "Failure!", num_tested - num_wrong,
       num_tested)
Example #11
0
 def loc_loop_helper(self, i, j, verts, window):
     i_arr = [-1, 0, 1, 2]
     j_arr = [-1, 0, 1]
     # empty_loc = pygame.image.load('assets/empty_loc.png').convert_alpha()
     # empty_loc = pygame.transform.scale(blank, (4, 4)
     good_points = set(((0, 1), (1, 0), (2, 0), (3, 1), (1, 2), (2, 2)))
     counter = 0
     for i_coord, i_num in enumerate(i_arr):
         for j_coord, j_num in enumerate(j_arr):
             if (i_coord, j_coord) not in good_points:
                 continue
             row = int(2 * i + i_num)
             col = int(2 * j + j_num)
             #print(row, col)
             # maybe I should just choose one for row and row - 1
             loc = Loc(row, col, verts[counter], None, None)
             pygame.draw.circle(window, (0, 255, 0), verts[counter], 6)
             self.loc_board[row - 1][col - 1] = loc
             counter += 1
Example #12
0
 def js(self):
     """ Описание пользователя (отдаем на клиент).
     """
     res = {"name": self.name, "id": str(self.id), "hp": self.hp, "hp_regen": self.hp_regen_rate()}
     res.update(self.data)
     del res["deck"]
     del res["reserve"]
     if "dialog" in res:
         del res["dialog"]
     prev_up = exp_to_levelup(self["level"] - 1)
     res["exp"] = res["exp"] - prev_up
     res["exp_to_levelup"] = exp_to_levelup(self["level"]) - prev_up
     res["inventory"] = self["inventory"].js(self)
     res["effects"] = [extend(eff.js_adv(), {"time_left": limit - now()}) for eff, limit in res["effects"]]
     res["quests"] = [q.js(self) for q in self["quests"]]
     loc = Loc.js(self)
     if loc:
         for key in loc.keys():
             res[key] = loc[key]
     self.need_update(False)
     return res
Example #13
0
 def __init__(self, x, y, z):
     self.loc = Loc(x, y, z)
     self.neighbors = []
Example #14
0
 def viewport(self, loc=None):
     "Current viewport based on `self.loc`"
     L = loc or self.cursor
     return Loc(L[0] - (L[0] % vpsize[0]), L[1] - (L[1] % vpsize[1]))
Example #15
0
 def go_noupdate(self, where):
     Loc.leave(self)
     self["loc"] = where
     Loc.enter(self)
Example #16
0
 def add_piece(self, id, *locs):
     locs = [Loc(*a) for a in locs]
     pieces[id] = Piece(id, *locs)
     for l in locs:
         self[l] = id
Example #17
0
 def __iter__(self):
     for y in range(sizey):
         for x in range(sizex):
             yield Loc(x, y)
Example #18
0
 def __init__(self, x, y, z):
     self.loc = Loc(x, y, z)
     self.neighbors = []