Пример #1
0
def index():
    user = current_user()
    id = int(request.args.get('id', -1))
    if id == -1:
        ms = Word.all(wall_id=1)
        wall = Wall.one(id=1)
    else:
        ms = Word.all(wall_id=id)
        wall = Wall.one(id=id)
    ws = Wall.all()

    return render_template("wall/index.html",
                           ms=ms,
                           ws=ws,
                           wall=wall,
                           login_user=user)
Пример #2
0
 def __init__(self):
     self.ball_in_pallet = True
     self.clock = pygame.time.Clock()
     self.point: Point = Point()
     self.live: Live = Live()
     self.ball: Ball = Ball()
     self.pallet: Pallet = Pallet()
     self.wall: Wall = Wall()
     self.window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
Пример #3
0
def main():
    game = GameWorld(20)
    cell1 = Cell(Food(), Vector2D(4, 4))
    cell2 = Cell(Food(), Vector2D(6, 7))
    cell3 = Cell(Food(), Vector2D(6, 8))
    cell4 = Cell(Food(), Vector2D(2, 1))
    cell5 = Cell(Food(), Vector2D(0, 17))
    cell6 = Cell(Food(), Vector2D(13, 15))
    cell7 = Cell(Food(), Vector2D(14, 2))
    cell8 = Cell(Wall(), Vector2D(5, 5))
    cell9 = Cell(Wall(), Vector2D(7, 6))
    cell10 = Cell(Wall(), Vector2D(8, 9))
    cell11 = Cell(Wall(), Vector2D(11, 15))
    cell12 = Cell(Wall(), Vector2D(18, 12))
    cell13 = Cell(Wall(), Vector2D(19, 1))
    cell14 = Cell(BlackHole(), Vector2D(2, 2))
    game.add_content([cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8,
                      cell9, cell10, cell11, cell12, cell13, cell14])
    p = Python(game, (5, 2), 5, Python.DOWN)
    p.set_head()
    p.set_body()
    game.print_world()
    direction = getch.getch()
    with start_log('game_start.txt', 'a') as s:
        pass
    while direction:
        os.system('clear')
        p.move(direction)
        with move_log('move_log.txt', 'a',
                      p.direction_by_ascii_code(direction)) as f:
            pass
        flag = p.is_dead()
        try:
            if not flag:
                game.print_world()
                direction = getch.getch()
            else:
                raise DeathError
        except DeathError:
            print("GAME OVER")
            break
        if game.no_food_board():
            print("GAME WON!")
            break
    with end_log('game_end.txt', 'a') as e:
                pass
Пример #4
0
 def __init__(self, map_input, ques_input):
     self.width = len(map_input)
     self.height = len(map_input[0]) - 1
     self.wall = []
     self.ques = []
     check_ques = [True] * len(ques_input)
     for y in range(self.height):
         for x in range(self.width):
             if map_input[y][x] == "P":
                 self.player = Player(x, y)
             elif map_input[y][x] == "B":
                 self.boss = Boss(x, y)
             elif map_input[y][x] == "D":
                 self.door_win = DoorWin(x, y)
             elif map_input[y][x] == "#":
                 self.wall.append(Wall(x, y))
             elif map_input[y][x] == "Q":
                 while True:
                     index_ques = random.randint(0, len(ques_input)-1)
                     if check_ques[index_ques]:
                         break
                 self.ques.append(Ques(x, y, ques_input[index_ques]))
                 check_ques[index_ques] = False
Пример #5
0
def finish_ques(map, index_ques, result, request):
    if result:
        del map.ques[index_ques]
        done = False
        true_eff.play(0)
        while not done:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    done = True
                if event.type == pygame.KEYDOWN:
                    done = True
            screen.blit(pass_target_image, (0, 100))
            pygame.display.flip()
    else:
        del map.ques[index_ques]
        map.wall.append(Wall(map.player.x, map.player.y))
        done = False
        false_eff.play(0)
        while not done:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    done = True
                if event.type == pygame.KEYDOWN:
                    done = True
            screen.blit(fail_target_image, (0, 100))
            pygame.display.flip()

        dx, dy = 0, 0
        if request == pygame.K_UP:
            dy = -1
        elif request == pygame.K_DOWN:
            dy = +1
        elif request == pygame.K_LEFT:
            dx = -1
        elif request == pygame.K_RIGHT:
            dx = +1
        map.player.move(-dx, -dy)
Пример #6
0
def main():

    pygame.init()

    WIDTH = 800
    HEIGHT = 600
    WALL_WIDTH = 20
    PADDING = 10

    BALL_VELOCITY = 0.2
    PADDLE_VELOCITY = 0.2

    BLOCK_COLS = 5
    BLOCK_ROWS = 10

    screen = pygame.display.set_mode((WIDTH, HEIGHT))

    walls = {
        'top': Wall(0, 0, WIDTH, WALL_WIDTH),
        'left': Wall(0, 0, WALL_WIDTH, HEIGHT),
        'bottom': Wall(0, HEIGHT - WALL_WIDTH, WIDTH, WALL_WIDTH),
    }

    lose_wall = Wall(WIDTH, 0, WALL_WIDTH,
                     HEIGHT)  # behind the paddle, hit this wall to lose

    paddle = Paddle(WIDTH - WALL_WIDTH, HEIGHT / 2)

    ball = Ball(WIDTH / 2, HEIGHT / 2, BALL_VELOCITY, 0)

    blocks = []
    block_width = 20
    block_height = (HEIGHT - (2 * WALL_WIDTH) - PADDING) / BLOCK_ROWS
    for nx in range(BLOCK_COLS):
        for ny in range(BLOCK_ROWS):
            x = WALL_WIDTH + PADDING + (nx * (block_width + PADDING))
            y = WALL_WIDTH + PADDING + (ny * block_height)
            blocks.append(Block(x, y, block_width, block_height - PADDING))

    done = False

    while not done:
        # event handling
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        # keyboard handling
        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_UP] and paddle.detectCollision(
                walls['top']) == Side.NONE:
            paddle.y -= PADDLE_VELOCITY
        if pressed[pygame.K_DOWN] and paddle.detectCollision(
                walls['bottom']) == Side.NONE:
            paddle.y += PADDLE_VELOCITY

        # physics stuff
        ball.update()
        paddle.update()

        # wall collisions
        for wall in walls:
            side = ball.detectCollision(walls[wall])
            if side != Side.NONE:
                ball.bounce(side)

        # paddle collision
        side = ball.detectCollision(paddle)
        if side != Side.NONE:
            ball.bounce(side)
            offset_normalized = (ball.y - paddle.y - (paddle.height / 2)) / (
                paddle.height / 2)  # -1 to 1, offset from center of paddle
            ball.vy = offset_normalized * BALL_VELOCITY  # steer ball by hitting off-center

        # block collisions
        for i in range(len(blocks) - 1, -1, -1):
            block = blocks[i]
            side = block.detectCollision(ball)
            if side != Side.NONE:
                ball.bounce(side)
                # block.alive = False
                del blocks[i]

        # lose condition
        if ball.detectCollision(lose_wall) != Side.NONE:
            # reset ball position
            ball.x = WIDTH / 2
            ball.y = HEIGHT / 2
            ball.vx = BALL_VELOCITY
            ball.vy = 0

        # win condition
        if len(blocks) == 0:
            print("win yey")

        # clear screen
        screen.fill((0, 0, 0))

        # draw walls
        for side in walls:
            walls[side].draw(screen)

        # draw paddle
        paddle.draw(screen)

        # draw ball
        ball.draw(screen)

        # draw blocks
        for block in blocks:
            block.draw(screen)

        pygame.display.flip()
Пример #7
0
def generate_fake_date():
    # 测试账号
    form = dict(
        username='******',
        password=User.salted_password('123'),
    )
    u1 = User.register(form)

    form = dict(
        username='******',
        password=User.salted_password('123'),
        image='/images/dance.gif',
    )
    u2 = User.register(form)

    # 留言墙
    w = Wall.new({'title': '校务'})
    # w = Wall.new({'title': '树洞'})
    w = Wall.new({'title': '兼职'})
    w = Wall.new({'title': '物品'})

    # 文件分类
    c = College.new({'title': '公共'})
    c = College.new({'title': 'A学院'})
    c = College.new({'title': 'B学院'})

    # 板块
    form = dict(title='全部')
    b = Board.new(form)

    form = dict(title='分享')
    b = Board.new(form)

    form = dict(title='问答')
    b = Board.new(form)

    # 帖子
    with open('markdown_demo.md', encoding='utf8') as f:
        content = f.read()

    rd_string = "一段随sfSDSD机文字大sada矿购买fda痛亏本龙Zxfasf凤你耨周xzc哈嘿"

    for i in range(5):
        log('begin topic <{}>'.format(i))
        topic_form = dict(
            title='markdown demo' + str(i),
            board_id=random.randint(2, 3),
            content=content,
        )
        u_id = random.randint(1, 2)
        t = Topic.new(topic_form, u_id)

        reply_form = dict(
            content='reply test',
            topic_id=t.id,
        )
        for j in range(5):
            u_id = random.randint(1, 2)
            reply_form['content'] = 'reply test' + ''.join(
                random.sample(rd_string, 2))
            Reply.new(reply_form, u_id)

    for i in range(15):
        log('begin topic <{}>'.format(i))
        num1 = random.randint(5, 15)
        num2 = random.randint(10, 35)
        topic_form = dict(
            title=''.join(random.sample(rd_string, num1)),
            board_id=random.randint(2, 3),
            content=''.join(random.sample(rd_string, num2)),
        )
        u_id = random.randint(1, 2)
        t = Topic.new(topic_form, u_id)

        reply_form = dict(
            content='reply test',
            topic_id=t.id,
        )
        for j in range(random.randint(1, 5)):
            u_id = random.randint(1, 2)
            reply_form['content'] = 'reply test' + ''.join(
                random.sample(rd_string, 2))
            Reply.new(reply_form, u_id)

    # 留言

    # 文件
    form = dict(
        filename='3.gif',
        localname='3.gif',
        user_id=1,
        college_id=1,
    )
    FileIndex.new(form)
Пример #8
0
def switch_coefficient(first_wall: Wall, second_wall: Wall):
    temp = first_wall.coefficient
    first_wall.coefficient = second_wall.coefficient
    second_wall.coefficient = temp