Esempio n. 1
0
 def trigger(self,
             char: Character,
             event: Event,
             results: Optional[Result] = None) -> Optional[Result]:
     if not results:
         results = Result(char)
     state, subEvents = event.trigger(results)
     if subEvents:
         sub = self.chooseFromEvents(char, subEvents, state)
         if not sub: return results
         self.trigger(char, sub, results)
     return results
Esempio n. 2
0
    def set_data(self, data):

        # all the actual data is contained in here, so let's just throw away the outer
        # shells of the json
        self._core_data = data
        self._id = self._core_data['id']
        self._game_type = 'Regular Season'
        date_string = self._core_data['start']['local'].split('T')[0]
        self._date = dt.datetime.strptime(date_string, '%Y-%m-%d')
        self._teams = self._core_data['teams']
        self._home_team = self._teams[0]
        self._away_team = self._teams[1]
        self._home_boxscore = self._core_data['box_scores'][0]
        self._away_boxscore = self._core_data['box_scores'][1]
        self._pbp = self._core_data['play_by_play']
        self._events = sorted([Event(play_data) for play_data in self._pbp])

        self._add_custom_fields()
        self._pre_cache_lineups()
Esempio n. 3
0
 def __init__(self):
     '''
     construction du jeu
     '''
     self.event = Event()
     self.loader = Loader()
     self.mainWindow = pygame.display.set_mode((1024, 600), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE)
     self.mainScene = LoadScene(self.loader)
     self.fullscreen = False
     self.lastSize = [1152, 768]
     self.fullSize = [0, 0]
     
     pygame.init()
     pygame.display.set_caption("Python Game Cards")
     self.modes = pygame.display.list_modes()
     
     self.fullSize[0] = self.modes[0][0]
     self.fullSize[1] = self.modes[0][1]
     
     self.loader.addFont("mainTitle", "../img/LSANS.ttf", 48)
     self.loader.addFont("text", "../img/LSANS.ttf", 15)
     
     self.event.keyboard[pygame.K_F11] = True
Esempio n. 4
0
    def draw(self):
        self.screen.fill((255, 255, 255))

        if pygame.mouse.get_pressed()[0]:
            self.pressed = True
        else:
            self.pressed = False

        if pygame.mouse.get_pressed(
        )[1] and self.frame_cooldown + 40 < self.frames:
            self.frame_cooldown = self.frames
            self.middle_pressed = True
        else:
            self.middle_pressed = False

        if pygame.mouse.get_pressed()[2]:
            self.left_pressed = True
        else:
            self.left_pressed = False

        if key_is_down(pygame.K_ESCAPE):
            name = ''
            if len(glob.glob('./*.npz')) != len(self.maps):
                name = 'data' + str(len(self.maps) + 1)
            else:
                name = 'data' + str(self.current_map + 1)
            np.savez(name, self.tiles_holder, self.pokemon_strings)
            self.Running = False

        if self.switch:
            self.current_map = (self.current_map + 1) % len(self.maps)
            self.load = True

        if self.load:
            np_load_old = np.load
            np.load = lambda *a, **k: np_load_old(*a, allow_pickle=True, **k)
            npzfile = np.load(self.maps[self.current_map])
            self.tiles_holder = npzfile['arr_0']
            self.pokemon_strings = npzfile['arr_1']
            np.load = np_load_old
            for x in range(self.tiles_holder.shape[0]):
                for y in range(self.tiles_holder.shape[1]):
                    c: CellHolder
                    c = self.tiles_holder[x][y]
                    self.tiles[x][y] = Cell(
                        c.x, c.y, c.sheet_x, c.sheet_y, c.size,
                        self.cell_size / 16, self.offset_width,
                        self.offset_height, self.sprite_group,
                        self.sprite_sheet, c.movable, c.event)

        self.grid_select_x = int(
            (pygame.mouse.get_pos()[0] - self.offset_width) / self.cell_size)
        self.grid_select_y = int(
            (pygame.mouse.get_pos()[1] - self.offset_height) / self.cell_size)

        # Calculate cell size based on the world size and window size
        self.cell_size_width = int((
            (self.window_size[0] - 30) / self.grid_width) + 0.5)
        self.cell_size_height = int((
            (self.window_size[1] - 30) / self.grid_height) + 0.5)
        self.cell_size = self.cell_size_width if self.cell_size_width < self.cell_size_height else self.cell_size_height
        self.offset_width = (self.window_size[0] -
                             (self.grid_width * self.cell_size)) / 2
        self.offset_height = (self.window_size[1] -
                              (self.grid_height * self.cell_size)) / 2

        # draw
        for x in range(self.grid_width):
            for y in range(self.grid_height):
                pygame.draw.rect(self.screen, [0, 0, 0], [
                    x * self.cell_size + self.offset_width,
                    y * self.cell_size + self.offset_height, self.cell_size,
                    self.cell_size
                ], 1)

        self.sprite_group.draw(self.screen)

        # print([(self.selection[0] - self.window_size[0]) / 16, self.selection[1] / 16,
        #        self.cell_size, self.cell_size])

        if self.pressed and pygame.mouse.get_pos(
        )[0] > self.window_size[0] and self.show_sheet:
            self.select_x = int(
                (pygame.mouse.get_pos()[0] - self.window_size[0]) / 16)
            self.select_y = int(pygame.mouse.get_pos()[1] / 16)
            self.selection = (int((pygame.mouse.get_pos()[0]) / 16) * 16 + 8,
                              int(pygame.mouse.get_pos()[1] / 16) * 16)

        if self.pressed and pygame.mouse.get_pos()[0] < self.window_size[0]:
            self.tiles[self.grid_select_y][self.grid_select_x].kill()
            self.tiles_holder[
                self.grid_select_y][self.grid_select_x] = CellHolder(
                    self.grid_select_x, self.grid_select_y, self.select_x,
                    self.select_y, 16, self.cell_size / 16, self.offset_width,
                    self.offset_height, True, Event.NONE)
            c: CellHolder
            c = self.tiles_holder[self.grid_select_y][self.grid_select_x]
            self.tiles[self.grid_select_y][self.grid_select_x] = Cell(
                c.x, c.y, c.sheet_x, c.sheet_y, c.size, self.cell_size / 16,
                c.offset_w, c.offset_h, self.sprite_group, self.sprite_sheet,
                c.movable, c.event)

        if self.show_sheet:
            pygame.draw.rect(self.screen, [0, 0, 0],
                             [self.selection[0], self.selection[1], 16, 16], 1)

        if self.left_pressed and pygame.mouse.get_pos(
        )[0] < self.window_size[0]:
            c = self.tiles_holder[self.grid_select_y][self.grid_select_x]
            self.tiles_holder[
                self.grid_select_y][self.grid_select_x] = CellHolder(
                    self.grid_select_x, self.grid_select_y, c.sheet_x,
                    c.sheet_y, 16, self.cell_size / 16, self.offset_width,
                    self.offset_height, not c.movable, c.event)

        if self.middle_pressed and pygame.mouse.get_pos(
        )[0] < self.window_size[0]:
            c = self.tiles_holder[self.grid_select_y][self.grid_select_x]
            self.tiles_holder[self.grid_select_y][
                self.grid_select_x] = CellHolder(
                    self.grid_select_x, self.grid_select_y, c.sheet_x,
                    c.sheet_y, 16, self.cell_size / 16, self.offset_width,
                    self.offset_height, c.movable,
                    Event((c.event.value + 1) % 4))

        for x in range(self.tiles_holder.shape[0]):
            for y in range(self.tiles_holder.shape[1]):
                if not self.tiles_holder[x][y].movable:
                    self.draw_cross(
                        pygame.Rect(
                            (self.tiles_holder[x][y].x * self.cell_size +
                             self.offset_width,
                             self.tiles_holder[x][y].y * self.cell_size +
                             self.offset_height),
                            (self.cell_size, self.cell_size)))

        if self.show_event:
            for x in range(self.tiles_holder.shape[0]):
                for y in range(self.tiles_holder.shape[1]):
                    textsurface = self.font.render(
                        str(self.tiles_holder[x][y].event.value), True,
                        (255, 255, 255))
                    self.screen.blit(
                        textsurface,
                        (y * self.cell_size + 22 + self.offset_width,
                         x * self.cell_size + 15 + self.offset_height))

        if pygame.mouse.get_pos()[0] < self.window_size[0]:
            pygame.draw.rect(self.screen, [0, 0, 0], [
                self.grid_select_x * self.cell_size + self.offset_width,
                self.grid_select_y * self.cell_size + self.offset_height,
                self.cell_size, self.cell_size
            ], 1)

        if self.show_sheet:
            self.screen.blit(self.sprite_sheet, self.sprite_sheet_rect)
        else:
            textsurface = self.font.render(
                "Pokédex ID + Probability Percentage", True, (0, 0, 0))
            self.screen.blit(textsurface, (self.window_size[0], 0))
            i = 1
            for x in range(len(self.pokemon_strings)):
                if x % 2 == 1:
                    continue
                textsurface = self.font.render(
                    str(self.pokemon_strings[x] + " " +
                        self.pokemon_strings[x + 1]), True, (0, 0, 0))
                self.screen.blit(textsurface, (self.window_size[0], i * 30))
                i += 1
            self.screen.blit(self.text_input.get_surface(),
                             (self.window_size[0], 30 * i))

        pygame.display.flip()
Esempio n. 5
0
class Game(object):
    '''
    Class modélisant le jeu
    '''
    
    def __init__(self):
        '''
        construction du jeu
        '''
        self.event = Event()
        self.loader = Loader()
        self.mainWindow = pygame.display.set_mode((1024, 600), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE)
        self.mainScene = LoadScene(self.loader)
        self.fullscreen = False
        self.lastSize = [1152, 768]
        self.fullSize = [0, 0]
        
        pygame.init()
        pygame.display.set_caption("Python Game Cards")
        self.modes = pygame.display.list_modes()
        
        self.fullSize[0] = self.modes[0][0]
        self.fullSize[1] = self.modes[0][1]
        
        self.loader.addFont("mainTitle", "../img/LSANS.ttf", 48)
        self.loader.addFont("text", "../img/LSANS.ttf", 15)
        
        self.event.keyboard[pygame.K_F11] = True
    
    def play(self):
        '''
        Démarre le jeu
        '''
        laps = 20
        next_ = pygame.time.get_ticks() + laps
        
        while (self.mainScene is not None):
            self.event.update()
            
            if (self.event.keyboard[pygame.K_F11]):
                self.event.keyboard[pygame.K_F11] = False
                self.fullscreen = not self.fullscreen
                self.event.resize = True
                
                if self.fullscreen:
                    self.event.width = self.fullSize[0]
                    self.event.height = self.fullSize[1]
                else:
                    self.event.width = self.lastSize[0]
                    self.event.height = self.lastSize[1]
            
            if (self.event.resize == True):
                self.event.resize = False
                if self.fullscreen:
                    pygame.display.set_mode((self.event.width, self.event.height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                else:
                    pygame.display.set_mode((self.event.width, self.event.height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE)
                self.mainScene.resizeWindow(self.loader, self.event.width, self.event.height)
            
            self.mainScene = self.mainScene.update(self.event, self.loader)
            
            tick = pygame.time.get_ticks()
            if tick > next_:
                next_ += laps
                if self.mainScene is not None:
                    self.loader.update(self.mainWindow)
                    
                pygame.display.flip()
Esempio n. 6
0
    def eventFromYamlNew(name: str,
                         data: OrderedDict[str, Union[str, int, OrderedDict]],
                         defaultReq: str = ""):
        text: str = None
        checks: dict[str, list[list[str]]] = {}
        effects: dict[str, list[list[str]]] = {}

        if not isinstance(data, dict):
            raise LoadException(
                f"Data for event {name} was not a dict (got: {data})")

        print(f"Beginning load for event {name}")

        subEvents = []

        for key in data:
            val = data[key]
            if key == "text":
                if not isinstance(val, str):
                    raise LoadException(
                        f"`text` value in event {name} was not a string (got: {val})"
                    )
                text = [t.strip() for t in newlines.split(val.strip())]
            elif key.startswith("->"):
                if not isinstance(val, dict):
                    raise LoadException(
                        f"`->` (sub) value in event {name} was not a dict (got: {val})"
                    )
                subEvents.append(
                    All.eventFromYamlNew(name + "." + key[3:], val,
                                         defaultReq))
            else:
                if not val: val = ""
                if not any([isinstance(val, str), isinstance(val, int)]):
                    raise LoadException(
                        f"`{key}` value in event {name} was not a string or int (got: {val})"
                    )
                charShort = str(key)
                parts = semicolons.split(val)
                if len(parts) > 2:
                    raise LoadException(
                        f"`{charShort}` value in event {name} had too many semicolons (got: {val})"
                    )
                reqStr = parts[0]
                resStr = parts[1] if len(parts) == 2 else ""
                if defaultReq:  # one off - only apply default to the main char requirement
                    if reqStr:
                        reqStr = defaultReq + ", " + reqStr
                    else:
                        reqStr = defaultReq
                    defaultReq = None
                checks[charShort] = [
                    spaces.split(allArgs) for allArgs in commas.split(reqStr)
                ] if reqStr else []
                effects[charShort] = [
                    spaces.split(allArgs) for allArgs in commas.split(resStr)
                ] if resStr else []

        if text == None:
            raise LoadException(f"`text` value in event {name} not found")

        return Event(name, text, checks, effects, subEvents)