def print_slow(str):
for letter in str:
sys.stdout.write(letter)
sys.stdout.flush()
time.sleep(0.1)
Однако, поскольку оно пишется по буквам, если слово не заканчивается до конца строки, оно будет обрезано, т.е.:
bla bla bla bla rea
ding.
Хотя я бы предпочел:
bla bla bla bla
reading
Есть ли простой способ сделать это?
ПОЛНЫЙ КОД: Пожалуйста, игнорируйте плохую историю, это было всего лишь доказательством того, что я могу заставить ее работать!
from __future__ import print_function
import textwrap
import sys,time,random
import pygame
from pygame.locals import *
def print_slow(str):
for letter in str:
sys.stdout.write(letter)
sys.stdout.flush()
time.sleep(0.1)
def displayIntro():
pygame.mixer.init()
pygame.mixer.music.load('storm.wav')
pygame.mixer.music.play()
print('')
print('')
for line in textwrap.wrap(a,20):
print_slow('The year is 2054, you have just arrived home from four years of travelling ')
print()
print_slow('The year is 2054, you have just arrived home from four years of travelling ')
print_slow('Europe, studying the virus that has killed all the grass in the mainland. ')
time.sleep(1)
print('\n')
pygame.mixer.music.load('metaldoor.wav')
pygame.mixer.music.play(0)
print_slow('As you open the gates of your estate, you hear a familar voice coming from ')
print_slow('the house. ')
time.sleep(1)
def gateDecision():
decision = ''
print('\n')
print_slow('As you walk down the drive, the voice suddenly turns into a scream. ')
time.sleep(1)
print('\n')
print_slow('You start running, getting to the door which is locked. ')
time.sleep(1)
print('\n')
print_slow('You reach into your pocket to get the key, but it is locked from the inside. ')
time.sleep(1)
print('\n')
while decision != 'a' and decision != 'b':
print_slow('Do you: ')
print('\n')
print_slow('(a) Climb in through the open window, or (b) Go around and try the back door?')
decision = raw_input()
if decision == "a":
time.sleep(1)
print('')
print_slow('As you open the window, you feel the shotgun against your forehead and the ')
pygame.mixer.music.load('shotgun.wav')
pygame.mixer.music.play(0)
print_slow('cool breeze of air that rushes through your skull as you drop to the ')
print_slow('ground dead. ')
print('\n')
print_slow('THE END... ')
print('\n')
print('\n')
else:
time.sleep(1)
print_slow('You get to the back door to find it ajar, you slowly step in... ')
print('-------------------------------------------------------------')
print('\n')
print('\n')
print('\n')
print('\n')
print('\n')
print('\n')
print('\n')
print(' # # # ##### # # #### ')
print(' # # # # # # # # ')
print(' # # # # # # # #### ')
print(' # # # ##### # # # ')
print(' # # # # # # # # # ')
print(' ## # # # #### #### ')
displayIntro()
gateDecision()
Подробнее здесь: https://stackoverflow.com/questions/444 ... ting-words
Полная версия