Exemple #1
0
 def set_suggestion(self, filename, hashh):
     self.suggest_data = ("0", filename, hashh)
     dec_filename = "data/maps/" + filename + ".skb"
     _filename = filename.replace("_", " ")
     self.suggest_text = "How about '" + _filename + "'"
     if LevelLoad.file_exists(dec_filename):  # I have this file...
         if not LevelLoad.check_hash(dec_filename, hashh):  # and it's not the same
             self.suggest_data = ("1", filename, hashh)
             self.suggest_text = "How about my version of '" + _filename + "'"
     else:
         self.suggest_data = ("1", filename, hashh)
     self.redraw_suggest()
Exemple #2
0
 def handle_key(self, event):
     if event.key == pygame.K_TAB:
         self.load_box.cur_tab ^= 1
         self.load_box.reload_files()
         self.load_box.redraw()
     elif valid_file_char(event.unicode):
         self.load_box.add_char(event.unicode)
     elif event.key == pygame.K_BACKSPACE:
         self.load_box.del_char()
     elif event.key == pygame.K_ESCAPE:
         self.dx, self.dy = (0, 0)
         self.main.ui_back()
     elif event.key == pygame.K_UP:
         self.load_box.up_key()
     elif event.key == pygame.K_DOWN:
         self.load_box.down_key()
     elif event.key in (pygame.K_RETURN, pygame.K_KP_ENTER):
         filename = self.load_box.load_results.files[
             self.load_box.load_results.selection]
         full_filename = self.load_box.tab_data[2] + "/" + filename + ".skb"
         start, board = LevelLoad.load(full_filename)
         board.stuff.show_numbers = True
         self.parent.set_start(start)
         self.parent.board = board
         self.parent.board.full_redraw()
         self.parent.view[:] = start
         self.dx, self.dy = (0, 0)
         self.main.ui_back()
Exemple #3
0
 def load_level(self, name=None):
     if name is None:
         name = self.boardname
     loc, self.board = LevelLoad.load_level(name)
     self.boardname = name
     for slot in self.slots:
         slot.player.pos = loc
         slot.player.board = self.board
Exemple #4
0
 def process_received(self, message):
     msg = message.split(" ")
     if msg[0] == "MOVED":
         person, dx, dy = map(int, msg[1:])
         p = self.main.ui.player1
         if person:
             p = self.main.ui.player2
         p.move(dx, dy)
     elif msg[0] == "START":
         self.main.change_screen("level select")
     elif msg[0] == "MSG":
         self.main.ui.chatbox.message(int(msg[1]), ' '.join(msg[2:]))
     elif msg[0] == "RESTART":
         self.main.restart()
     elif msg[0] == "LEVELOFF":  # make sure you're correct
         filename, hashh = msg[1:3]
         self.main.ui.set_suggestion(filename, hashh)
     elif msg[0] == "LEVELACC":  # Level accepted: start?
         send_map, filename, hashh = msg[1:]
         print msg[1:]
         if int(send_map):
             with open("data/maps/" + filename + ".skb", "r") as f:
                 self.main.send_msg("LEVELULD " + filename + " " + f.read())
                 print "Message sent????"
         else:
             self.main.send_msg("STARTGAME " + filename)
     elif msg[0] == "LEVELULD":  # Level uploaded: save it!
         print "got a level ULD"
         filename = msg[1]
         full_filename = LevelLoad.full_path(filename)
         data = ' '.join(msg[2:])
         if LevelLoad.file_exists(full_filename):
             LevelLoad.archive(full_filename)
         with open(full_filename, "w") as f:
             f.write(data)
         self.main.send_msg("STARTGAME " + filename)
     elif msg[0] == "STARTGAME":  # everyone's ready!
         print msg
         self.main.change_screen("game", level=msg[1])
     elif msg[0] == "FULL":  # couldn't join
         pass
     elif msg[0] == "SOKOPONG":
         pass
Exemple #5
0
    def __init__(self, main, parent, level="division_of_labor"):
        super(GameUI, self).__init__(main, parent)
        self.level_name = level

        self.chatbox = Chatbox()

        player2 = parent.player2
        loc, self.board = LevelLoad.load_level(level)
        self.board.add_client(self.main.client)

        self.player1 = Player(self.board, loc, not player2)
        self.player2 = Player(self.board, loc, player2, self.player1)
        self.which_player = player2
        self.view_player = player2

        self.mode = GameUI.PLAY_MODE
Exemple #6
0
 def handle_key(self, event):
     if valid_file_char(event.unicode):
         self.load_box.add_char(event.unicode)
     elif event.key == pygame.K_BACKSPACE:
         self.load_box.del_char()
     elif event.key == pygame.K_UP:
         self.load_box.up_key()
     elif event.key == pygame.K_DOWN:
         self.load_box.down_key()
     elif event.key in (pygame.K_RETURN, pygame.K_KP_ENTER):
         filename = self.load_box.load_results.files[
             self.load_box.load_results.selection]
         dec_filename = "data/maps/" + filename + ".skb"
         self.main.send_msg("LEVELOFF " + filename + " " +
             LevelLoad.check_hash(dec_filename))
     elif event.key == pygame.K_TAB:
         if self.suggest_data is not None:  # accept the suggestion
             self.main.send_msg("LEVELACC " + ' '.join(self.suggest_data))