def play_game(): """ Starts tetris game in terminal. """ board_instance = Board(20) current_piece = Piece(board_instance) board_instance.print(current_piece) game = Game() player_move = input() while (game.status): msg = move.make_move(player_move, board_instance, current_piece) board_instance.print(current_piece, msg) game.is_over(board_instance, current_piece) player_move = input() print("GAME OVER!")
def playGame(): # build the solar system sun = Celestial("resources/images/sun.jpg", 75, 0, 1) player1 = Player( 1, Celestial("resources/images/player1.png", mass=20, radius=85, eccentricity=0.95)) player2 = Player( 2, Celestial("resources/images/player2.png", mass=20, radius=340, eccentricity=0.95)) # this collection is everything that can attract the ship planets = [ sun, player1.celestial, Celestial("resources/images/planet.png", mass=15, radius=123, eccentricity=1.05), Celestial("resources/images/planet.png", mass=10, radius=175, eccentricity=0.90), Celestial("resources/images/planet.png", mass=10, radius=250, eccentricity=0.85), Celestial("resources/images/planet.png", mass=20, radius=300, eccentricity=0.95), player2.celestial ] ship = Ship() game = Game([player1, player2], ship, planets, screen) # the game is over when all but one player is dead while not game.is_over(): # this is listening for someone to close the window event = pygame.event.poll() if event.type == pygame.QUIT: sys.exit(0) # clear the screen screen.fill(black) # let the player know whose turn it is, and how # much fuel is left on the spaceship game.render_state() # move the planets in their orbits for p in planets: p.move() p.blit(screen) # move the ship by # - dragging it towards the sun and each planet # - if the player is pressing the direction keys, then apply that thrust if ship.is_launched: # while the ship is launching we ignore the home planet attracting_planets = planets if ship.is_launching: attracting_planets = [ e for e in planets if e != game.current_player().celestial ] ship.apply_acceleration(attracting_planets) ship.move() # if the ship has hit something, or has run out of fuel, then # then it's the next player's turn # : if the ship hit a player and killed them then game.is_over() # will say so game.check_collisions() if ship.is_ship_dead(): game.next_player() else: # the ship isn't launched, so check if we've been asked # to do so game.check_launch_trigger() game.heal_other_players() # redraw the frame, but we don't want a framerate > 40 pygame.display.flip() clock.tick(40) # if we're here, then the game is over game.render_game_over()