Created
November 2, 2020 17:46
-
-
Save thunderpoot/6815f3307e443311d1b4e9a2d8ae2142 to your computer and use it in GitHub Desktop.
...ported from Perl version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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