Mercurial > zrpn
changeset 89:35f4c26609fc
auto fillin gaps at top
| author | Michael Rochseter <m.rochester93@googlemail.com> |
|---|---|
| date | Sun, 08 Jul 2012 15:01:30 +0200 |
| parents | 0683012417ec |
| children | 97996cdd1a53 |
| files | zrpn/board.py zrpn/client.py zrpn/display.py zrpn/packets.py zrpn/server.py |
| diffstat | 5 files changed, 22 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/zrpn/board.py Sun Jul 08 13:57:27 2012 +0200 +++ b/zrpn/board.py Sun Jul 08 15:01:30 2012 +0200 @@ -6,10 +6,12 @@ class Board(object): def __init__(self): + self.parent=None self.board = [[random.randint(1, 5) for x in range(30)] for y in range(25)] self.cells = [[y * 30 + x for x in range(30)] for y in range(25)] + self.id_next = max([max(c) for c in self.cells])+1 def update(self): animations = [] @@ -21,6 +23,15 @@ killed, ex = self.kill_groups(turns) extra.extend(ex) animations.extend(killed) + for y, line in enumerate(self.board): + for x, b in enumerate(line): + if b == 0 and y == 0: + self.board[y][x] = random.randint(1, 5) + self.cells[y][x]= self.id_next + for connection in parent.server.peers.values(): + connection.net_add(x,y,self.board[y][x],self.cells) + self.id_next+=1 + animations.extend(self.apply_gravity(turns)) if not killed: return animations, extra
--- a/zrpn/client.py Sun Jul 08 13:57:27 2012 +0200 +++ b/zrpn/client.py Sun Jul 08 15:01:30 2012 +0200 @@ -48,6 +48,8 @@ elif event.p_type == packets.SCORE: self.lbl_score.config(text="score=\n" + str(event.packet.score_num)) self.lbl_highscore.config(text="first=\n" + str(event.packet.highscore)) + elif event.p_type == packets.ADD: + self.display.add_zrpn(event.packet.x,event.packet.y,event.packet.cell,event.packet.board_ids) self.client.step() t = time.time() - self.start self.lbl_time.config(text="time\nwasted=\n" + str(round(t, 5)))
--- a/zrpn/display.py Sun Jul 08 13:57:27 2012 +0200 +++ b/zrpn/display.py Sun Jul 08 15:01:30 2012 +0200 @@ -24,12 +24,15 @@ def load_board(self, board, board_ids): for y, line in enumerate(board): for x, cell in enumerate(line): - sprite = sprites.Cell((x, y), cell) - self.sprites.add(sprite) - cid = board_ids[y][x] - self.cids[cid] = sprite + self.add_zrpn(x,y,cell,board_ids) pygame.display.update() + def add_zrpn(self,x,y,cell,board_ids): + sprite = sprites.Cell((x, y), cell) + self.sprites.add(sprite) + cid = board_ids[y][x] + self.cids[cid] = sprite + def do_animations(self, animations): for kind, cid, turn in animations: try:
--- a/zrpn/packets.py Sun Jul 08 13:57:27 2012 +0200 +++ b/zrpn/packets.py Sun Jul 08 15:01:30 2012 +0200 @@ -3,3 +3,4 @@ ANIMATIONS = net.register('animations', ('animations',)) CLICK = net.register('click', ('x', 'y')) SCORE = net.register('score', ('score_num', 'highscore')) +ADD = net.register('add', ('x','y','cell','board_ids'))
--- a/zrpn/server.py Sun Jul 08 13:57:27 2012 +0200 +++ b/zrpn/server.py Sun Jul 08 15:01:30 2012 +0200 @@ -11,6 +11,7 @@ def __init__(self): self.click_time = time.time() + board.parent=self def net_click(self, channel, packet_id, packet): t = time.time() @@ -24,8 +25,6 @@ collumn_rows = [a for a in animations if a[0] == 'collumn_row'] #TODO: who gets the points? - print collumn_rows - print extra if collumn_rows: for x, cr in enumerate(collumn_rows): self.scores[self] += 20 + (10*extra[x])
