Exemplo n.º 1
0
 def serve(self, direction=1):
     if glob.player1.score < 10 and glob.player2.score < 10:
         # Next round
         self.x = self.xstart
         self.y = self.ystart
         self.xvelocity = 2 * direction
         self.yvelocity = 0
     else:
         # Game Over!
         glob.hud_sprite.draw_clear()
         x = glob.hud_sprite.width / 2
         p1score = glob.player1.score
         p2score = glob.player2.score
         p1text = "WIN" if p1score > p2score else "LOSE"
         p2text = "WIN" if p2score > p1score else "LOSE"
         glob.hud_sprite.draw_text(glob.hud_font, p1text, x - 16, 16,
                                   color="white", halign=sge.ALIGN_RIGHT,
                                   valign=sge.ALIGN_TOP)
         glob.hud_sprite.draw_text(glob.hud_font, p2text, x + 16, 16,
                                   color="white", halign=sge.ALIGN_LEFT,
                                   valign=sge.ALIGN_TOP)
         m = "What is the name of the winner?"
         name = sge.get_text_entry(m, 'Nobody')
         if name is not None:
             m = "Congratulations, {0}! You win!".format(name)
             sge.show_message(m)
         self.destroy()
Exemplo n.º 2
0
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(
                    os.path.realpath(
                        os.path.join(DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {'views': [], 'objects': []}
        config['class'] = self.cls
        config['width'] = self.width
        config['height'] = self.height
        config['background'] = self.background.id
        config['background_x'] = self.background_x
        config['background_y'] = self.background_y

        for view in self.views:
            config['views'].append({
                'x': view.x,
                'y': view.y,
                'xport': view.xport,
                'yport': view.yport,
                'width': view.width,
                'height': view.height
            })

        for obj in self.objects:
            config['objects'].append({
                'class': obj.cls,
                'x': obj.x,
                'y': obj.y,
                'z': obj.z,
                'args': obj.args,
                'kwargs': obj.kwargs
            })

        with open(fname, 'w') as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True
Exemplo n.º 3
0
    def close(self):
        if self.unchanged:
            self.opened = False
            sge.game.room_goto_next()
        else:
            m = "Save changes to {0} before closing?".format(self.name)
            answer = sge.show_message(m, ("Cancel", "No", "Yes"), 2)
            if answer != 0:
                if answer == 2:
                    self.save(None)

                self.opened = False
                sge.game.room_goto_next()
Exemplo n.º 4
0
    def close(self):
        if self.unchanged:
            self.opened = False
            sge.game.room_goto_next()
        else:
            m = "Save changes to {0} before closing?".format(self.name)
            answer = sge.show_message(m, ("Cancel", "No", "Yes"), 2)
            if answer != 0:
                if answer == 2:
                    self.save(None)

                self.opened = False
                sge.game.room_goto_next()
Exemplo n.º 5
0
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(os.path.realpath(os.path.join(DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {"views": [], "objects": []}
        config["class"] = self.cls
        config["width"] = self.width
        config["height"] = self.height
        config["background"] = self.background.id
        config["background_x"] = self.background_x
        config["background_y"] = self.background_y

        for view in self.views:
            config["views"].append(
                {
                    "x": view.x,
                    "y": view.y,
                    "xport": view.xport,
                    "yport": view.yport,
                    "width": view.width,
                    "height": view.height,
                }
            )

        for obj in self.objects:
            config["objects"].append(
                {"class": obj.cls, "x": obj.x, "y": obj.y, "z": obj.z, "args": obj.args, "kwargs": obj.kwargs}
            )

        with open(fname, "w") as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True
    def save(self, fname=None):
        """Save settings to a file."""
        if fname is None:
            if self.fname is not None:
                fname = self.fname
            else:
                # TODO: Create a file selection dialog for this.
                m = "Please enter the name of the file to save to."
                d = os.path.normpath(os.path.realpath(os.path.join(
                    DIRNAME, "data", "rooms", "*.rmj")))
                entry = sge.get_text_entry(m, d)
                if entry is not None:
                    fname = entry
                else:
                    return
        elif os.path.exists(fname):
            m = "{0} already exists. Overwrite?".format(fname)
            if not sge.show_message(m, ("No", "Yes")):
                return

        config = {'views': [], 'objects': []}
        config['class'] = self.cls
        config['width'] = self.width
        config['height'] = self.height
        config['background'] = self.background.id
        config['background_x'] = self.background_x
        config['background_y'] = self.background_y

        for view in self.views:
            config['views'].append(
                {'x': view.x, 'y': view.y, 'xport': view.xport,
                 'yport': view.yport, 'width': view.width,
                 'height': view.height})

        for obj in self.objects:
            config['objects'].append(
                {'class': obj.cls, 'x': obj.x, 'y': obj.y, 'z': obj.z,
                 'args': obj.args, 'kwargs': obj.kwargs})

        with open(fname, 'w') as f:
            json.dump(config, f, indent=4, sort_keys=True)

        self.unchanged = True
Exemplo n.º 7
0
 def event_close(self):
     m = "Are you sure you want to quit?"
     if sge.show_message(m, ("No", "Yes")):
         self.end()
Exemplo n.º 8
0
 def event_close(self):
     m = "Are you sure you want to quit?"
     if sge.show_message(m, ("No", "Yes")):
         self.end()