示例#1
0
def menu(canvas: Window) -> None:
    """Preparing game field, creating all objects, starting game loop."""
    curses.curs_set(False)
    canvas.nodelay(True)

    title_path: Path = MODELS_PATH.joinpath("start_game")
    game_title_frames: List[str] = [
        read_frame(title_path.joinpath(f"{word}.txt")) for word in "starwar"
    ]
    border_frame: str = read_frame(title_path.joinpath("border.txt"))

    height: int
    width: int
    frame_border_height: int
    frame_border_width: int
    height, width = canvas.getmaxyx()
    frame_border_height, frame_border_width = get_frame_size(border_frame)
    ship_window: Window = canvas.derwin(
        frame_border_height + 2, frame_border_width + 2,
        round(height / 2 - frame_border_height - 1),
        round(width / 2 - frame_border_width / 2))

    canvas.addstr(height - 2, int(width / 2 - 10), "PRESS SPACE FOR START")

    ship: Ship = Ship(ship_window)
    draw_frame(ship_window, 1, 1, border_frame)
    eventloop.add_coroutine(
        show_title(canvas, game_title_frames, height, width))
    eventloop.add_coroutine(ship.animate(2, round(frame_border_width / 2 - 1)))
    eventloop.add_coroutine(blink_star(ship_window, 30))
    eventloop.add_coroutine(wait_for_space(canvas))
    eventloop.loop_forever([canvas, ship_window])
示例#2
0
async def fill_orbit_with_garbage(canvas: Window) -> None:
    """Add garbage to window every tics count."""
    width: int

    _, width = getmaxyx_border(canvas)
    while True:
        tics: Union[int, None] = get_garbage_delay_tics()
        if tics is None:
            await eventloop.sleep(1)
            continue
        await eventloop.sleep(tics)

        frame: str = random.choice(garbage_frames)
        column: int = _find_place_for_garbage(width, frame)
        if column:
            eventloop.add_coroutine(fly_garbage(canvas, column, frame))
示例#3
0
    def make_controls(self, row: int, column: int) -> Tuple[int, int]:
        """If user make a turn we changing row & colls of the ship."""
        rows_direction: int
        columns_direction: int
        fire_on: bool
        rows_direction, columns_direction, fire_on = read_controls(self.canvas)

        if fire_on:
            eventloop.add_coroutine(
                fire(self.canvas, self.row * 1.0,
                     self.column + self.width / 2))

        self.row_speed, self.column_speed = update_speed(
            self.row_speed, self.column_speed, rows_direction,
            columns_direction)
        row = round(min(row + self.row_speed, self.max_y))
        row = max(1, row)
        column = round(min(column + self.column_speed, self.max_x))
        column = max(1, column)
        return row, column
示例#4
0
def start_game(canvas: Window) -> None:
    """Preparing game field, creating all objects, starting game loop."""
    height: int
    width: int

    height, width = canvas.getmaxyx()
    stat_height_rows: int = 7

    head_window: Window = canvas.derwin(1, width, 0, 0)
    stat_window: Window = canvas.derwin(stat_height_rows, width, height - stat_height_rows, 0)
    space_window: Window = canvas.derwin(height - stat_height_rows, width, 1, 0)
    space_window.border()

    ship: Ship = Ship(space_window)
    eventloop.add_coroutine(ship.fly())
    eventloop.add_coroutine(ship.animate())
    eventloop.add_coroutine(show_head_stats(head_window, stat_window, ship))
    eventloop.add_coroutine(blink_star(space_window))

    eventloop.add_coroutine(fill_orbit_with_garbage(space_window))
    eventloop.add_coroutine(new_year())

    curses.beep()
    eventloop.loop_forever([head_window, space_window, stat_window])
示例#5
0
 async def explode_ship_and_game_over(self):
     self.dead = True
     await explode(self.canvas, int(self.row + self.height / 2),
                   int(self.column + self.width / 2))
     eventloop.add_coroutine(show_game_over(self.canvas))