コード例 #1
0
 def add_houses(self, amount):
     while amount > 0:
         try:
             game.server_call(
                 "new_house",
                 (
                     randint(0, common.field_size[0] - 1),
                     randint(0, common.field_size[1] - 1),
                 ),
             )
             amount -= 1
         except common.ActionNotPossible:
             pass
コード例 #2
0
 def handle(self):
     if self.phase_end():
         game.server_call("next_phase")
     else:
         passed_milliseconds = min(self.clock.tick(), 500)
         # handle redraws and other actions that occur each frame
         self.actions(passed_milliseconds)
         for player in game.players:
             player.handle_movement(passed_milliseconds)
             player.draw_cursor()
         self.time_left -= passed_milliseconds * 0.001
         game.print_time()
         common.update()
コード例 #3
0
ファイル: cannon.py プロジェクト: szpak-forks/castle-combat
 def handle(self, passed_milliseconds):
     self.time_since_start += passed_milliseconds
     try:
         self.ratio = self.time_since_start / self.time_to_target
     except ZeroDivisionError:
         self.ratio = 1
     if self.ratio >= 1:
         # target hit
         sound.wall_hit.play()
         self.ratio = 1
         game.shots.remove(self)
         if game.server:
             x = int(self.get_pos()[0]) // common.block_size
             y = int(self.get_pos()[1]) // common.block_size
             game.server_call("hit", (x, y), self.cannon.id)
コード例 #4
0
 def handle(self, passed_milliseconds):
     self.time_to_action -= passed_milliseconds
     if self.time_to_action <= 0:
         # have a look at my movement possibilities
         new_pos = tuple(add(self.pos, self.movement[self.direction]))
         if common.is_in_bounds(new_pos):
             wall_in_front = game.field[new_pos] >= 0
         else:
             wall_in_front = False
         wall_in_sight = randint(0, 3)
         for i in range(randint(0, 10)):
             test_pos = tuple(
                 add(self.pos, multiply(self.movement[self.direction], i)))
             if (not common.is_in_bounds(test_pos) or game.field[test_pos]
                     in (Field.CASTLE, Field.HOUSE, Field.RIVER) +
                     Field.ANY_GARBAGE):
                 wall_in_sight = False
                 break
             if game.field[test_pos] >= 0:
                 wall_in_sight = True
                 break
         # make decision
         if wall_in_front:
             game.server_call("hit", tuple(new_pos))
             self.time_to_action += randint(2000, 4500)
         elif (common.is_in_bounds(new_pos) and wall_in_sight
               and game.field[new_pos] == Field.EMPTY):
             game.server_call("move_grunt", self.id, tuple(new_pos))
             self.time_to_action += randint(1000, 1500)
         else:
             new_dir = (self.direction + 1 - 2 * randint(0, 1)) % 4
             game.server_call("rotate_grunt", self.id, new_dir)
             self.time_to_action += randint(1000, 1500)
コード例 #5
0
    def handle_keypress(self, event):
        if common.debug and event.type == KEYDOWN:
            if event.key == K_BACKSPACE:
                d = game.server_call("next_phase")
                raise IgnoreEvent(d)
            if event.key == K_EQUALS:
                try:
                    import cannon

                    reload(cannon)
                    print("reload successful")
                except:
                    print("WARNING: Module reload failed!")
                    import traceback

                    traceback.print_exc()
コード例 #6
0
    def __init__(self, pos):
        self.pos = pos
        self.direction = randint(0, 3)
        if not self.instances:
            self.id = 0
        else:
            self.id = max([g.id for g in self.instances]) + 1
        self.instances.append(self)
        self.time_to_action = randint(500, 1000)
        game.field[pos] = Field.GRUNT

        # display grunt on the server and all clients (via callLater because __init__ was called from game.call())
        from twisted.internet import reactor

        reactor.callLater(
            0,
            lambda: game.server_call("rotate_grunt", self.id, self.direction))
コード例 #7
0
 def proceed_if_waited_long_enough(self, event):
     if pygame.time.get_ticks() > self.start_time + 500:
         game.server_call("next_phase")
         raise IgnoreEvent