changeset 95:e9d3ed7d477c

small fixes
author Szymon Wróblewski <bluex0@gmail.com>
date Sun, 08 Jul 2012 15:59:39 +0200
parents b7c8e0e15395
children 42a4ef9956e4
files zrpn/board.py zrpn/client.py zrpn/display.py zrpn/pygame_network/server.py zrpn/server.py
diffstat 5 files changed, 21 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/zrpn/board.py	Sun Jul 08 15:44:05 2012 +0200
+++ b/zrpn/board.py	Sun Jul 08 15:59:39 2012 +0200
@@ -6,12 +6,12 @@
 
 class Board(object):
     def __init__(self):
-        self.parent=None
+        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
+        self.id_next = max([max(c) for c in self.cells]) + 1
 
     def update(self):
         animations = []
@@ -23,22 +23,21 @@
 
         while True:
             turns += 1
-            killed, ex = self.kill_groups(turns)    
+            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
-                        net_adds.append([x,y,self.board[y][x],self.cells])
-                        self.id_next+=1
-                        
+                        self.cells[y][x] = self.id_next
+                        net_adds.append([x, y, self.board[y][x], self.cells])
+                        self.id_next += 1
+
             animations.extend(self.apply_gravity(turns))
             if not killed:
                 return animations, extra, net_adds
 
-
     def apply_gravity(self, turn):
         animations = []
         has_holes = True
@@ -63,7 +62,7 @@
         """
         Alternative gravity implementation
         """
-        for row in range(len(self.board)-1, -1, -1):
+        for row in range(len(self.board) - 1, -1, -1):
             for col in range(len(self.board[row])):
                 if self.board[row][col] == 0:
                     for i in range(row, -1, -1):
@@ -90,10 +89,10 @@
                             self.die((i, y), turn, animations)
                         killed += 1
                         animations.append(('collumn_row', None, turn))
-                        extra.append(((count+1) - GROUP_SIZE))
+                        extra.append(((count + 1) - GROUP_SIZE))
                     count = 1
                 last_cell = cell
-            
+
             if count >= GROUP_SIZE:
                 # x = column after the end of the line
                 x += 1
@@ -116,7 +115,7 @@
                             self.die((x, i), turn, animations)
                         killed += 1
                         animations.append(('collumn_row', None, turn))
-                        extra.append(((count+1) - GROUP_SIZE))
+                        extra.append(((count + 1) - GROUP_SIZE))
                     count = 1
                 last_cell = cell
         return animations, extra
@@ -151,12 +150,10 @@
             checked[y][x] = True
             for i, j in ((-1, 0), (0, -1), (1, 0), (0, 1)):
                 points, checked = self.check_neighbours(y + j, x + i,
-                                                          checked, mons, 
+                                                          checked, mons,
                                                           points)
         return points, checked
 
-
-
     #def kill_groups2(self, turn):
     #    """Alternative kill_groups implementation (look for any shape)"""
     #    GROUP_SIZE = 5
--- a/zrpn/client.py	Sun Jul 08 15:44:05 2012 +0200
+++ b/zrpn/client.py	Sun Jul 08 15:59:39 2012 +0200
@@ -18,9 +18,6 @@
     def __init__(self, address, port):
         self.display = display.Display()
 
-
-
-        
         self.connected = False
         self.client = net.Client()
         self.connection = self.client.connect(address, port)
@@ -46,10 +43,6 @@
                 elif event.type == pygame.MOUSEBUTTONDOWN:
                     x, y = event.pos[0] // 24, event.pos[1] // 24
                     self.connection.net_click(x, y)
-
-
-
-
                 elif event.type == net.event.NETWORK:
                     if event.net_type == net.event.NET_RECEIVED:
                         if event.p_type == packets.INIT:
@@ -57,24 +50,17 @@
                                     event.packet.sprites)
                         elif event.p_type == packets.ANIMATIONS:
                             self.display.do_animations(event.packet.animations)
-
-
-                            
-
-
                         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.display.add_zrpn(*event.packet)
             self.client.step()
             t = time.time() - self.start
             self.lbl_time.config(text="time\nwasted=\n" + str(round(t, 5)))
             self.display.frame()
 
 
-
-
 def main():
     net.event.init()
     logging.basicConfig(level=logging.DEBUG)
--- a/zrpn/display.py	Sun Jul 08 15:44:05 2012 +0200
+++ b/zrpn/display.py	Sun Jul 08 15:59:39 2012 +0200
@@ -12,36 +12,30 @@
     def __init__(self):
         pygame.init()
         pygame.font.init()
-        
+
         self.screen = sgc.surface.Screen((800, 600))
         self.screen.fill((0x33, 0x33, 0x33))
         self.background = self.screen.copy()
         self.sprites = pygame.sprite.LayeredDirty()
         self.cids = {}
         self.clock = pygame.time.Clock()
-        self.sgc_rect=((720,0),(800,200))
-
+        self.sgc_rect = ((720, 0), (800, 200))
 
-
-    
         self.zombie = pygame.mixer.Sound(data_dir("zombie.ogg"))
         self.robot = pygame.mixer.Sound(data_dir("robot.ogg"))
         self.pirate = pygame.mixer.Sound(data_dir("pirate.ogg"))
         self.ninja = pygame.mixer.Sound(data_dir("ninja.ogg"))
         self.skeleton = pygame.mixer.Sound(data_dir("ninja.ogg"))
 
-
         self.sound_types = dict(enumerate([None, self.ninja, self.pirate, self.robot, self.skeleton, self.zombie]))
 
-
-
     def load_board(self, board, board_ids):
         for y, line in enumerate(board):
             for x, cell in enumerate(line):
-                self.add_zrpn(x,y,cell,board_ids)
+                self.add_zrpn(x, y, cell, board_ids)
         pygame.display.update()
 
-    def add_zrpn(self,x,y,cell,board_ids):
+    def add_zrpn(self, x, y, cell, board_ids):
         sprite = sprites.Cell((x, y), cell)
         self.sprites.add(sprite)
         cid = board_ids[y][x]
@@ -66,8 +60,7 @@
         self.sprites.update()
         dirty = self.sprites.draw(self.screen)
         time = self.clock.tick(15)
-        self.screen.fill((0x33, 0x33, 0x33),self.sgc_rect)
+        self.screen.fill((0x33, 0x33, 0x33), self.sgc_rect)
         sgc.update(time)
         dirty.append(self.sgc_rect)
         pygame.display.update(dirty)
-
--- a/zrpn/pygame_network/server.py	Sun Jul 08 15:44:05 2012 +0200
+++ b/zrpn/pygame_network/server.py	Sun Jul 08 15:59:39 2012 +0200
@@ -52,11 +52,11 @@
                 self.peers[event.peer.data]._receive(event.packet.data, event.channelID)
             event = host.check_events()
 
-    def connections(self, exclude=None):
+    def connections(self, exclude=[]):
         if exclude is None:
             return self.peers.itervalues()
         else:
             return (c for c in self.peers.itervalues() if c not in exclude)
 
-    def receivers(self, exclude=None):
+    def receivers(self, exclude=[]):
         return (c._receivers[0] for c in self.peers.itervalues() if c not in exclude)
--- a/zrpn/server.py	Sun Jul 08 15:44:05 2012 +0200
+++ b/zrpn/server.py	Sun Jul 08 15:59:39 2012 +0200
@@ -36,11 +36,10 @@
             receiver.connection.net_animations(animations)
 
             for net_add in net_adds:
-                receiver.connection.net_add(net_add)
+                receiver.connection.net_add(*net_add)
 
             receiver.connection.net_score(self.scores[receiver], max_score)
 
-
     def on_connect(self):
         self.connection.net_init(self.board.board, self.board.cells)
         self.scores[self] = 0