示例#1
0
def test_move_lrrl(bf_crate):
    for d in [
            DOWN, RIGHT, RIGHT, UP, LEFT, DOWN, LEFT, LEFT, UP, RIGHT, RIGHT,
            DOWN, RIGHT, RIGHT, UP, LEFT
    ]:
        move(bf_crate, d)
    assert bf_crate[0][2] == 'o'
示例#2
0
def handle_key(key):
    """Handles key events in the game"""
    direction = DIRECTIONS.get(key)
    if direction:
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224)))
    pygame.display.update()
示例#3
0
def handle_key(key):
    """Handles key events in the game"""
    direction = DIRECTIONS.get(key)
    if direction:
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224)))
    pygame.display.update()
示例#4
0
def handle_key(key):
    """Obsluguje zdarzenia nacisniecia klawiszy w grze"""
    direction = DIRECTIONS.get(key)
    if direction:
        move(maze, DIRECTIONS.get(key))
    img = draw_grid(maze, tile_img, tiles)
    display.blit(img, Rect(0, 0, 384, 224), Rect(0, 0, 384, 224))
    pygame.display.update()
示例#5
0
def handle_key(key):

    """Handles key events in the game"""

    direction = DIRECTIONS.get(key)

    if direction:

        move(maze, direction)

    draw()
示例#6
0
def test_push_crate_to_wall():
    maze = parse_grid("*o#")
    move(maze, RIGHT)
    assert maze[0] == ['*', 'o', '#']
示例#7
0
def main(gameOn):
    TURN = moves.move()

    while gameOn:
        # for loop through the event queue
        for event in pygame.event.get():

            if event.type == KEYDOWN:

                if event.key == K_BACKSPACE:

                    gameOn = False

            elif event.type == QUIT:
                gameOn = False

            elif event.type == pygame.MOUSEBUTTONUP:
                pos = pygame.mouse.get_pos()
                n_pos = [pos[0], pos[1]]
                coordinate = coordinate_to_matrix(n_pos, 80, 30)
                selected = chess_board.board[coordinate[0]][coordinate[1]]

                if selected == 0:
                    if len(SELECTED) > 0:
                        Enlist(selected, coordinate)
                elif selected != 0 and len(SELECTED) == 0:
                    if selected.color == TURN.current_turn:
                        Enlist(selected, coordinate)
                elif selected != 0 and len(SELECTED) > 0:
                    Enlist(selected, coordinate)

        screen.blit(Background_1.surf, (5, 5))
        screen.blit(Background_2.surf, (10, 10))
        screen.blit(background_3.surf, (15, 15))

        for (spot, square) in zip(outer_spots, outer_squares):
            screen.blit(spot.surf, square)

        for piece in ALIVE:
            screen.blit(piece.surf, (piece.pos[1], piece.pos[0]))

        DOTS = []

        if len(SELECTED) != 0:
            for each in SELECTED:
                each.check_surrounding(chess_board)

                dots = each.moves
                DOTS = dots

        if len(DOTS) != 0:
            for dot in DOTS:
                red_dot = pygame.draw.circle(screen, RED,
                                             center_coordinate(dot, 80, 20),
                                             10)

        if len(SELECTED) > 0 and len(DESTINATION) > 0:
            for (piece, destination) in zip(SELECTED, DESTINATION):
                oppo = chess_board.board[destination[0]][destination[1]]
                if oppo != 0:
                    kill_piece(PIECE_BOND.get(oppo), ALIVE, KILLED)
                    piece.move(chess_board, destination)
                    TURN.turn_queue.append(piece.color)
                    del SELECTED[0]
                    del DESTINATION[0]

                elif oppo == 0:
                    piece.move(chess_board, destination)
                    TURN.turn_queue.append(piece.color)
                    del SELECTED[0]
                    del DESTINATION[0]

        pygame.display.flip()
示例#8
0
def test_paths(path):
    """Different paths to the same spot"""
    maze = parse_grid(SMALL_MAZE)
    for direction in path:
        move(maze, direction)
    assert maze[2][3] == '*'
示例#9
0
def move_crate(direction, plr_pos, crate_pos):
    """Helper function for testing crate moves"""
    maze = parse_grid(LEVEL)
    move(maze, direction)
    assert maze[plr_pos[0]][plr_pos[1]] == '*'
    assert maze[crate_pos[0]][crate_pos[1]] == 'o'
def handle_key(key):
    """Handles key events in the game"""
    move(maze, DIRECTIONS.get(key))
    draw()
示例#11
0
def move_crate(direction, plr_pos, crate_pos):
    """Helper function for testing crate moves"""
    maze = parse_grid(LEVEL)
    move(maze, direction)
    assert maze[plr_pos[0]][plr_pos[1]] == '*'
    assert maze[crate_pos[0]][crate_pos[1]] == 'o'
示例#12
0
 def push_crate_to_wall(self, direction, retezec):
     """Help function to test push to wall."""
     maze = parse_grid(retezec)
     mazepuv = maze
     move(maze, direction)
     assert maze[0] == mazepuv[0]
示例#13
0
 def test_move_crate(self, level, direction, plr_pos, crate_pos):
     """After move player and crate moved by one square."""
     print(direction, plr_pos, crate_pos)
     move(level, direction)
     assert level[plr_pos[0]][plr_pos[1]] == '*'
     assert level[crate_pos[0]][crate_pos[1]] == 'o'
示例#14
0
def move_crate(direction, plr_pos, crate_pos):
    """Help function for testing crate moves."""
    #maze = parse_grid(LEVEL)
    move(level, direction)
    assert level[plr_pos[0]][plr_pos[1]] == '*'
    assert level[crate_pos[0]][crate_pos[1]] == 'o'
示例#15
0
 def test_move_to_none(self, level):
     """Direction None generate an Exception."""
     with pytest.raises(TypeError):
         move(level, None)
示例#16
0
def handle_key(key):
    """Handles key events in the game"""
    direction = DIRECTIONS.get(key)
    if direction:
        move(maze, direction)
    draw()
示例#17
0
def test_move_to_none():
    """direction=None generates an Exception"""
    maze = parse_grid(LEVEL)
    with pytest.raises(TypeError):
        move(maze, None)
示例#18
0
def test_push_crate_to_exit():
    maze = parse_grid("*ox")
    with pytest.raises(NotImplementedError):
        move(maze, RIGHT)
示例#19
0
 def test_push_crate_to_crate(self):
     """Test_push_crate_to_crate."""
     maze = parse_grid('*oo')
     move(maze, RIGHT)
     assert maze == [['*', 'o', 'o']]
示例#20
0
def test_move_to_none():
    """direction=None generates an Exception"""
    maze = parse_grid(LEVEL)
    with pytest.raises(TypeError):
        move(maze, None)
示例#21
0
def test_move_crate(direction, pos, tile):
    """Move a crate and check a given tile"""
    maze = parse_grid(LEVEL)
    move(maze, direction)
    assert maze[pos[0]][pos[1]] == tile
示例#22
0
def branch_out(grid, score=0):
    games = []
    for k in range(4):
        games.append(move(grid, score, k)[0])
    return games
示例#23
0
def test_push_crate_to_crate():
    maze = parse_grid("*oo")
    move(maze, RIGHT)
    assert maze == [['*', 'o', 'o']]
示例#24
0
from pygame import image, Rect, Surface
from load_tiles import load_tiles, get_tile_rect, SIZE
from generate_maze import create_maze
from moves import move
import random

def parse_grid(data):
    """Parsuje reprezentacje tekstową do postaci zagnieżdżonej listy"""
    return [list(row) for row in data.strip().split("\n")]

def draw_grid(data, tile_img, tiles):
    """Zwraca obraz siatki złożonej z płytek"""
    xs = len(data[0]) * SIZE
    ys = len(data) * SIZE
    img = Surface((xs, ys))
    for y, row in enumerate(data):
        for x, char in enumerate(row):
            img.blit(tile_img, get_tile_rect(x, y), tiles[char])
    return img

if __name__ == "__main__":
    tile_img, tiles = load_tiles()
    maze = create_maze(12, 7)
    maze = parse_grid(maze)
    maze[1][1] = '*'
    for i in range(100):
        direction = random.choice([LEFT, RIGHT, UP, DOWN])
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    image.save(img, 'maze.png')
示例#25
0
def test_move_right_left(bf_crate):
    for d in [RIGHT, DOWN, RIGHT, RIGHT, UP, LEFT]:
        move(bf_crate, d)
    assert bf_crate[0][2] == 'o'
示例#26
0
 def test_move_crate_to_corner(self, level):
     """Move tom crate to upper left corner."""
     for d in [UP, RIGHT, UP, LEFT, LEFT, LEFT]:
         move(level, d)
     assert level[1][1] == "o"
示例#27
0
def game(key):
    """Handles key events in the game"""
    move(level, DIRECTIONS.get(key, 0))
    map_img = draw_map(level, tile_img, tiles)
    display.blit(map_img, Rect((0, 0, 224, 224)), Rect((0, 0, 224, 224)))
    pygame.display.update()
示例#28
0
def test_push_crate_to_wall():
    maze = parse_grid("*o#")
    move(maze, RIGHT)
    assert maze[0] == ['*', 'o', '#']
示例#29
0
 def test_move_crate_back_forth(self, level):
     """Sanity check: move the top crate twice."""
     for d in [LEFT, UP, RIGHT, UP, RIGHT, RIGHT, DOWN, LEFT, LEFT, LEFT]:
         move(level, d)
     assert level[2] == list('#o*   #')
示例#30
0
def test_push_crate_to_exit():
    maze = parse_grid("*ox")
    with pytest.raises(NotImplementedError):
        move(maze, RIGHT)
示例#31
0
 def test_move_player(self, level, path, expected_x, expected_y):
     """Korektní změna pozice hráče. Více parametrů - path, expected_x, expected_y."""
     for direction in path:
         move(level, direction)
     assert level[expected_y][expected_x] == '*'
示例#32
0
def test_move_lrrl(bf_crate):
    for d in [DOWN, RIGHT, RIGHT, UP, LEFT, DOWN, LEFT, LEFT, UP,
              RIGHT, RIGHT, DOWN, RIGHT, RIGHT, UP, LEFT]:
        move(bf_crate, d)
    assert bf_crate[0][2] == 'o'
示例#33
0
文件: cube.py 项目: pbardea/rubik
def move(moveArray):
  moves.move(moveArray)
示例#34
0
def handle_key(key):
    """Handles key events in the game"""
    move(maze, DIRECTIONS.get(key))
    draw()
示例#35
0
def test_paths(path, expected_x, expected_y, level):
    """różne ścieżki prowadzą do tego samego miejsca"""
    for direction in path:
        move(level, direction)
    assert level[expected_x][expected_y] == '*'
示例#36
0
def test_move_crate(direction, pos, tile):
    """Move a crate and check a given tile"""
    maze = parse_grid(LEVEL)
    move(maze, direction)
    assert maze[pos[0]][pos[1]] == tile
示例#37
0
 def test_move_crate(self, level, direction, plr_pos, crate_pos):
     """Po wykonaniu funkcji move gracz i skrzynia przesunieci o jedna kratke"""
     print(direction, plr_pos, crate_pos)
     move(level, direction)
     assert level[plr_pos[0]][plr_pos[1]] == '*'
     assert level[crate_pos[0]][crate_pos[1]] == 'o'
示例#38
0
def test_push_crate_to_crate():
    maze = parse_grid("*oo")
    move(maze, RIGHT)
    assert maze == [['*', 'o', 'o']]
示例#39
0
 def test_move_to_none(self):
     """direction=None generuje wyjatek"""
     with pytest.xfail(TypeError):
         move(level, None)
示例#40
0
def test_move_right_left(bf_crate):
    for d in [RIGHT, DOWN, RIGHT, RIGHT, UP, LEFT]:
        move(bf_crate, d)
    assert bf_crate[0][2] == 'o'
示例#41
0
 def test_move_player(self, level, path, expected_x, expected_y):
     """pozycja gracza prawidlowo zmienila polozenie"""
     for direction in path:
         move(level, direction)
     assert level[expected_y][expected_x]
示例#42
0
def test_paths(path):
    """Different paths to the same spot"""
    maze = parse_grid(SMALL_MAZE)
    for direction in path:
        move(maze, direction)
    assert maze[2][3] == '*'
示例#43
0
def test_push_crate_to_crate():
    maze = parse_grid('*oo')
    move(maze, RIGHT)
    assert maze[0] == ['*', 'o', 'o']