changeset 98:7e4195d0ca17

updated scoring
author Szymon Wróblewski <bluex0@gmail.com>
date Sun, 08 Jul 2012 17:34:04 +0200
parents 8ce25533406d
children c8dab4eedc02
files zrpn/client.py zrpn/main.py zrpn/packets.py zrpn/server.py
diffstat 4 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/zrpn/client.py	Sun Jul 08 17:12:38 2012 +0200
+++ b/zrpn/client.py	Sun Jul 08 17:34:04 2012 +0200
@@ -51,7 +51,8 @@
                         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))
+                            if event.packet.score_num is not None:
+                                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)
--- a/zrpn/main.py	Sun Jul 08 17:12:38 2012 +0200
+++ b/zrpn/main.py	Sun Jul 08 17:34:04 2012 +0200
@@ -14,7 +14,6 @@
 from skelutil import data_dir
 
 
-
 class Game(object):
     def __init__(self, display):
         self.board = board.Board()
@@ -37,11 +36,12 @@
 
                     for n in net_adds:
                         self.display.add_zrpn(*n)
-                    
+
                     self.display.do_animations(animations)
 
             self.display.frame()
 
+
 class MainMenu(sgc.Menu):
     func_dict = lambda self: {"single": self.single, "multi": self.multi,
                               "exit": sys.exit}
@@ -52,18 +52,17 @@
 
     def multi(self):
         self.remove()
-        
+
         import pygame_network as net
         net.event.init()
         logging.basicConfig(level=logging.DEBUG)
-        
+
         ip = self["ip"].text
         ip = str(ip)
         client.Client(ip, 10000).run()
 
 
 def main():
-    
     screen = display.Display()
 
     pygame.display.set_caption("Zombies Robots Pirates Ninjas")
@@ -78,7 +77,6 @@
                           ("f:multi", "Multiplayer"), ("f:exit", "Quit")))
     menu.screen = screen
 
-
     clock = pygame.time.Clock()
     menu.add(0)
     while True:
--- a/zrpn/packets.py	Sun Jul 08 17:12:38 2012 +0200
+++ b/zrpn/packets.py	Sun Jul 08 17:34:04 2012 +0200
@@ -3,4 +3,5 @@
 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'))
+ADD = net.register('add', ('x', 'y', 'cell', 'board_ids'))
+NEW_PLAYER = ('new_player', ('player_count',))
--- a/zrpn/server.py	Sun Jul 08 17:12:38 2012 +0200
+++ b/zrpn/server.py	Sun Jul 08 17:34:04 2012 +0200
@@ -6,12 +6,11 @@
 
 
 class ClientReceiver(net.Receiver):
-    scores = {}
     board = board.Board()
 
     def __init__(self):
         self.click_time = time.time()
-        board.parent = self
+        self.score = 0
 
     def net_click(self, channel, packet_id, packet):
         t = time.time()
@@ -27,23 +26,24 @@
         #TODO: who gets the points?
         if collumn_rows:
             for x, cr in enumerate(collumn_rows):
-                self.scores[self] += 20 + (10 * extra[x])
+                self.score += 20 + (10 * extra[x])
         else:
-            self.scores[self] -= 1
+            self.score -= 1
 
-        max_score = max(self.scores.values())
-        for receiver in self.server.receivers():
-            receiver.connection.net_animations(animations)
+        print self.score, id(self)
+
+        max_score = max(r.score for r in self.server.receivers())
+        self.connection.net_score(self.score, max_score)
+        for connection in self.server.connections():
+            connection.net_animations(animations)
 
             for net_add in net_adds:
-                receiver.connection.net_add(*net_add)
+                connection.net_add(*net_add)
 
-            receiver.connection.net_score(self.scores[receiver], max_score)
+            connection.net_score(None, max_score)
 
     def on_connect(self):
         self.connection.net_init(self.board.board, self.board.cells)
-        self.scores[self] = 0
-        print self.scores
 
 
 class Server(object):