Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #An example of the threading module
- #This "Game" doesn't really work, is more of a tech demo
- from threading import Thread
- import msvcrt
- import time
- import sys
- import random
- log = ""
- def out(s, spaces=True):
- global log
- if spaces: extra = " "*(79-len(s))
- else: extra = ""
- sys.stdout.write("\r{0}{1}".format(s,extra))
- sys.stdout.flush()
- log += s+"\n"
- out("It's time.")
- timer = 0
- pts = 0
- def up():
- out("UP")
- def down():
- out("DOWN")
- def left():
- out("LEFT")
- def right():
- out("RIGHT")
- def dtime():
- out("Seconds Active: {0}".format(timer))
- def points():
- out("Points: {0}".format(pts))
- events = {
- 'w': up,
- 'a': left,
- 's': down,
- 'd': right,
- 't': dtime,
- 'p': points,
- }
- def time_manager():
- global timer
- while True:
- time.sleep(1)
- timer += 1
- def keyEvent():
- while True:
- key = msvcrt.getch()
- if key in events.keys():
- events[key]()
- elif key.encode('hex') == '03':
- with open('Log.txt', 'w') as ld:
- ld.write(log)
- raise KeyboardInterrupt
- def getEvent():
- mats = "abcdefghijklmnopqrstuvwxyz"
- event = ''.join(random.choice(mats) for i in range(random.randint(3,7)))
- out("A wild fucking {0} is totes about to fuck you up.".format(event))
- def randomEvent():
- while True:
- e = random.randint(1,100)
- if 1 <= e <= 5:
- getEvent()
- time.sleep(1)
- if __name__ == "__main__":
- try:
- Thread(target = keyEvent).start()
- Thread(target = time_manager).start()
- Thread(target = randomEvent).start()
- except Exception, e:
- out("Error: {0}".format(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement