Example #1
0
    def setSize(self, width, height):
        self.width = width
        self.height = height
        self.num_darts = 4 * width * height - 2 * width - 2 * height
        self.num_nodes = width * height

        for h in range(0, self.height):
            for w in range(0, self.width):
                node = Node(self, h, w)
                # add outgoing darts if possible
                if h > 0:
                    node.addOutgoing(Dart("N"))
                if h < self.height - 1:
                    node.addOutgoing(Dart("S"))
                if w < self.width - 1:
                    node.addOutgoing(Dart("E"))
                if w > 0:
                    node.addOutgoing(Dart("W"))
                self.nodes.append(node)

        # add ingoing darts if possible
        for n in self.nodes:
            for dart in n.getAllOut():
                (w, h) = direction.getPositionChange(
                    n.w_pos, n.h_pos, dart.direction)
                to_node = self.getNode(h, w)
                oppdir = direction.getOppositeDirection(dart.direction)
                dart_out = to_node.getOut(oppdir)
                assert dart_out is not None
                dart.from_node.addIngoing(dart_out)
            n.calcPermutation()
Example #2
0
 def play(self):
     clock = pygame.time.Clock()
     # render score
     self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
     self.score.render(self.score_surface)
     # render start splash
     self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
     splash1 = self.splash_font.render('Next target:', 1, CLR_RED)
     splash2 = self.splash_font.render('%s' % self.get_turn_name(), 1,
                                       CLR_RED)
     self.game_surface.blit(splash1, (300 - splash1.get_width() / 2, 200))
     self.game_surface.blit(splash2, (300 - splash2.get_width() / 2, 280))
     self.screen.blit(self.game_surface, (0, 0))
     self.screen.blit(self.score_surface, (600, 0))
     pygame.display.update()
     clock.tick(0.8)
     # turn loop
     while True:
         # pause
         clock.tick(FPS)
         # initial fill
         self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
         # check dropped dart
         if self.active_dart.dropped:
             self.score.keep(self.turn_number, self.active_dart)
             self.dropped_darts.append(self.active_dart)
             if self.darts_remain > 0:
                 self.active_dart = Dart()
                 self.darts_remain -= 1
                 # re-render score cause it changed
                 self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
                 self.score.render(self.score_surface)
             else:
                 break
         # render dropped darts
         for dart in self.dropped_darts:
             dart.render(self.game_surface)
         # handle events
         for e in pygame.event.get():
             if e.type == QUIT:
                 raise GameInterruptedError
             elif e.type == KEYDOWN and e.key == K_ESCAPE:
                 raise GameEscapedError
             elif e.type == MOUSEBUTTONDOWN:
                 self.active_dart.drop()
         # handle and render active dart
         self.active_dart.handle()
         self.active_dart.move()
         self.active_dart.render(self.game_surface)
         # render turn number
         self.game_surface.blit(
             self.font.render('Target: %s' % self.get_turn_name(), 1,
                              CLR_RED),
             (60, 540),
         )
         # draw game surfaces
         self.screen.blit(self.game_surface, (0, 0))
         self.screen.blit(self.score_surface, (600, 0))
         # update
         pygame.display.update()
Example #3
0
 def __init__(self, turn_number, screen, game_surface, score_surface,
              score):
     # top-level properties
     self.screen = screen
     self.game_surface = game_surface
     self.score_surface = score_surface
     self.score = score
     # self properties
     self.turn_number = turn_number
     self.active_dart = Dart()
     self.darts_remain = 2  # one is already active
     self.dropped_darts = []
     self.font = pygame.font.Font(get_res_path('EraserRegular.ttf'), 32)
     self.splash_font = pygame.font.Font(get_res_path('EraserRegular.ttf'),
                                         52)
Example #4
0
 def __init__(self, turn_number, screen, game_surface, score_surface, score):
     # top-level properties
     self.screen = screen
     self.game_surface = game_surface
     self.score_surface = score_surface
     self.score = score
     # self properties
     self.turn_number = turn_number
     self.active_dart = Dart()
     self.darts_remain = 2  # one is already active
     self.dropped_darts = []
     self.font = pygame.font.Font(get_res_path('EraserRegular.ttf'), 32)
     self.splash_font = pygame.font.Font(
         get_res_path('EraserRegular.ttf'), 52
     )
Example #5
0
 def play(self):
     clock = pygame.time.Clock()
     # render score
     self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
     self.score.render(self.score_surface)
     # render start splash
     self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
     splash1 = self.splash_font.render(
        'Next target:', 1, CLR_RED
     )
     splash2 = self.splash_font.render(
         '%s' % self.get_turn_name(), 1, CLR_RED
     )
     self.game_surface.blit(splash1, (300 - splash1.get_width() / 2, 200))
     self.game_surface.blit(splash2, (300 - splash2.get_width() / 2, 280))
     self.screen.blit(self.game_surface, (0, 0))
     self.screen.blit(self.score_surface, (600, 0))
     pygame.display.update()
     clock.tick(0.8)
     # turn loop
     while True:
         # pause
         clock.tick(FPS)
         # initial fill
         self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
         # check dropped dart
         if self.active_dart.dropped:
             self.score.keep(self.turn_number, self.active_dart)
             self.dropped_darts.append(self.active_dart)
             if self.darts_remain > 0:
                 self.active_dart = Dart()
                 self.darts_remain -= 1
                 # re-render score cause it changed
                 self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
                 self.score.render(self.score_surface)
             else:
                 break
         # render dropped darts
         for dart in self.dropped_darts:
             dart.render(self.game_surface)
         # handle events
         for e in pygame.event.get():
             if e.type == QUIT:
                 raise GameInterruptedError
             elif e.type == KEYDOWN and e.key == K_ESCAPE:
                 raise GameEscapedError
             elif e.type == MOUSEBUTTONDOWN:
                 self.active_dart.drop()
         # handle and render active dart
         self.active_dart.handle()
         self.active_dart.move()
         self.active_dart.render(self.game_surface)
         # render turn number
         self.game_surface.blit(
             self.font.render('Target: %s' % self.get_turn_name(), 1, CLR_RED),
             (60, 540),
         )
         # draw game surfaces
         self.screen.blit(self.game_surface, (0, 0))
         self.screen.blit(self.score_surface, (600, 0))
         # update
         pygame.display.update()
Example #6
0
class Turn(object):

    def __init__(self, turn_number, screen, game_surface, score_surface, score):
        # top-level properties
        self.screen = screen
        self.game_surface = game_surface
        self.score_surface = score_surface
        self.score = score
        # self properties
        self.turn_number = turn_number
        self.active_dart = Dart()
        self.darts_remain = 2  # one is already active
        self.dropped_darts = []
        self.font = pygame.font.Font(get_res_path('EraserRegular.ttf'), 32)
        self.splash_font = pygame.font.Font(
            get_res_path('EraserRegular.ttf'), 52
        )

    def get_turn_name(self):
        if self.turn_number == 20:
            return "Bull's eye"
        else:
            return '%s' % (self.turn_number + 1)

    def play(self):
        clock = pygame.time.Clock()
        # render score
        self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
        self.score.render(self.score_surface)
        # render start splash
        self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
        splash1 = self.splash_font.render(
           'Next target:', 1, CLR_RED
        )
        splash2 = self.splash_font.render(
            '%s' % self.get_turn_name(), 1, CLR_RED
        )
        self.game_surface.blit(splash1, (300 - splash1.get_width() / 2, 200))
        self.game_surface.blit(splash2, (300 - splash2.get_width() / 2, 280))
        self.screen.blit(self.game_surface, (0, 0))
        self.screen.blit(self.score_surface, (600, 0))
        pygame.display.update()
        clock.tick(0.8)
        # turn loop
        while True:
            # pause
            clock.tick(FPS)
            # initial fill
            self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
            # check dropped dart
            if self.active_dart.dropped:
                self.score.keep(self.turn_number, self.active_dart)
                self.dropped_darts.append(self.active_dart)
                if self.darts_remain > 0:
                    self.active_dart = Dart()
                    self.darts_remain -= 1
                    # re-render score cause it changed
                    self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
                    self.score.render(self.score_surface)
                else:
                    break
            # render dropped darts
            for dart in self.dropped_darts:
                dart.render(self.game_surface)
            # handle events
            for e in pygame.event.get():
                if e.type == QUIT:
                    raise GameInterruptedError
                elif e.type == KEYDOWN and e.key == K_ESCAPE:
                    raise GameEscapedError
                elif e.type == MOUSEBUTTONDOWN:
                    self.active_dart.drop()
            # handle and render active dart
            self.active_dart.handle()
            self.active_dart.move()
            self.active_dart.render(self.game_surface)
            # render turn number
            self.game_surface.blit(
                self.font.render('Target: %s' % self.get_turn_name(), 1, CLR_RED),
                (60, 540),
            )
            # draw game surfaces
            self.screen.blit(self.game_surface, (0, 0))
            self.screen.blit(self.score_surface, (600, 0))
            # update
            pygame.display.update()
Example #7
0
class Turn(object):
    def __init__(self, turn_number, screen, game_surface, score_surface,
                 score):
        # top-level properties
        self.screen = screen
        self.game_surface = game_surface
        self.score_surface = score_surface
        self.score = score
        # self properties
        self.turn_number = turn_number
        self.active_dart = Dart()
        self.darts_remain = 2  # one is already active
        self.dropped_darts = []
        self.font = pygame.font.Font(get_res_path('EraserRegular.ttf'), 32)
        self.splash_font = pygame.font.Font(get_res_path('EraserRegular.ttf'),
                                            52)

    def get_turn_name(self):
        if self.turn_number == 20:
            return "Bull's eye"
        else:
            return '%s' % (self.turn_number + 1)

    def play(self):
        clock = pygame.time.Clock()
        # render score
        self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
        self.score.render(self.score_surface)
        # render start splash
        self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
        splash1 = self.splash_font.render('Next target:', 1, CLR_RED)
        splash2 = self.splash_font.render('%s' % self.get_turn_name(), 1,
                                          CLR_RED)
        self.game_surface.blit(splash1, (300 - splash1.get_width() / 2, 200))
        self.game_surface.blit(splash2, (300 - splash2.get_width() / 2, 280))
        self.screen.blit(self.game_surface, (0, 0))
        self.screen.blit(self.score_surface, (600, 0))
        pygame.display.update()
        clock.tick(0.8)
        # turn loop
        while True:
            # pause
            clock.tick(FPS)
            # initial fill
            self.game_surface.blit(IMG_DARTSBOARD, (0, 0))
            # check dropped dart
            if self.active_dart.dropped:
                self.score.keep(self.turn_number, self.active_dart)
                self.dropped_darts.append(self.active_dart)
                if self.darts_remain > 0:
                    self.active_dart = Dart()
                    self.darts_remain -= 1
                    # re-render score cause it changed
                    self.score_surface.blit(IMG_CHALKBOARD, (0, 0))
                    self.score.render(self.score_surface)
                else:
                    break
            # render dropped darts
            for dart in self.dropped_darts:
                dart.render(self.game_surface)
            # handle events
            for e in pygame.event.get():
                if e.type == QUIT:
                    raise GameInterruptedError
                elif e.type == KEYDOWN and e.key == K_ESCAPE:
                    raise GameEscapedError
                elif e.type == MOUSEBUTTONDOWN:
                    self.active_dart.drop()
            # handle and render active dart
            self.active_dart.handle()
            self.active_dart.move()
            self.active_dart.render(self.game_surface)
            # render turn number
            self.game_surface.blit(
                self.font.render('Target: %s' % self.get_turn_name(), 1,
                                 CLR_RED),
                (60, 540),
            )
            # draw game surfaces
            self.screen.blit(self.game_surface, (0, 0))
            self.screen.blit(self.score_surface, (600, 0))
            # update
            pygame.display.update()
Example #8
0
    def __init__(self):

        self.state = "arret"
        self.nxtState = "arret"
        self.robot = Dart()