Exemple #1
0
print("To move down: s")
print("To move left: a")
print("To move right: d")

print("Try to get to the end! Good Luck!")
print("-----------------------------")

# TODO
# Create a new GameBoard called board
board = gameboard.GameBoard()
# Create a new Player called player starting at position 3,2
player = player.Player(3, 2)

while True:
    board.printBoard(player.rowPosition, player.columnPosition)
    selection = input("Make a move: ")
    # TODO
    # Move the player through the board
    if selection == "w":
        player.moveUp()
    elif selection == "s":
        player.moveDown()
    elif selection == "a":
        player.moveLeft()
    elif selection == "d":
        player.moveRight()
    else:
        print("Invalid Direction!!!")

    # Check if the player has won, if so print a message and break the loop!
Exemple #2
0
level = map.Map()
map = level.getmap()

clock = pygame.time.Clock()
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    pressed = pygame.key.get_pressed()
    if pressed[pygame.K_UP]:
        player.moveUp(map)
    if pressed[pygame.K_DOWN]:
        player.moveDown(map)
    if pressed[pygame.K_LEFT]:
        player.moveLeft(map)
    if pressed[pygame.K_RIGHT]:
        player.moveRigth(map)
    if pressed[pygame.K_ESCAPE]:
        done = True

    if map[player.y / 30][player.x / 30] == 2:
        map[player.y / 30][player.x / 30] = 1
        score += 100

    for ghost in ghosts:
        ghost.move(map)

    screen.fill((0, 0, 0))
    map_y = len(map[0])
    map_x = len(map)