Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thunderpoot
Created November 2, 2020 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thunderpoot/6815f3307e443311d1b4e9a2d8ae2142 to your computer and use it in GitHub Desktop.
Save thunderpoot/6815f3307e443311d1b4e9a2d8ae2142 to your computer and use it in GitHub Desktop.
...ported from Perl version
#!/usr/bin/python
import random
import time
import sys
class Unbuffered( object ) :
def __init__( self, stream ) :
self.stream = stream
def write( self, data ) :
self.stream.write( data )
self.stream.flush()
def writelines( self, datas ) :
self.stream.writelines( datas )
self.stream.flush()
def __getattr__( self, attr ) :
return getattr( self.stream, attr )
sys.stdout = Unbuffered( sys.stdout )
distance = random.randint( 1, 50 )
stones = [ "_", "-" ]
print( "\033[?25l" ), # hide cursor
for i in range( 1, distance ) :
print( "\r" ),
print( " " * i ),
print( random.choice( stones ) ),
time.sleep( 0.09 )
print( "\r" + " " * i + "'splash!'" )
print( "\033[?25h" ), # show cursor
print( "\r%You scored: " + str( distance ) ),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment