Skip to content

Instantly share code, notes, and snippets.

@tullyhansen
Created July 30, 2015 08:34
Show Gist options
  • Save tullyhansen/f12370d5992888a16dd4 to your computer and use it in GitHub Desktop.
Save tullyhansen/f12370d5992888a16dd4 to your computer and use it in GitHub Desktop.
My first Python code (2008-12-16)
import random, time
dice_superlatives = ['laughable','shoddy','poor','pretty weak','below average','mediocre','reasonable','pretty good','handsome','superlative','outstanding']
result_list = []
player_count = 0
# TO DO - handle negative or 0 players
def preroll(player_num): # Handles selecting number of players
player_num = raw_input("Choose number of players:")
while True:
try:
player_num = int(player_num)
break
except:
player_num = raw_input("Sorry, I didn't catch that. Choose number of players:")
time.sleep(0.6)
return player_num
def roll(player_num,results): # Handles rolling
are_you_ready = raw_input("PLAYER %d: Are you ready? (YES/NO)" % (player_num))
while are_you_ready.lower() not in ['yes','y']:
are_you_ready = raw_input("PLAYER %d: I can't hear you! I said are you ready?! (YES/NO)" % (player_num))
print "PLAYER %d:\n" % (player_num)
time.sleep(0.6)
print "Roll..."
time.sleep(0.4)
print "Your..."
time.sleep(0.4)
print "DESTINY!\n"
time.sleep(0.6)
die_one = random.randint(1,6)
die_two = random.randint(1,6)
dice_roll = die_one + die_two
results.append([player_num, dice_roll])
print "It\'s a %s throw. You roll a %d and a %d for a total of %d.\n" % (dice_superlatives[dice_roll - 2], die_one, die_two, dice_roll)
time.sleep(0.6)
player_count = preroll(player_count)
for i in range (1, player_count + 1):
roll(i,result_list)
else:
print 'The results are in... '
time.sleep(1)
print "... but I'm not quite sure how to handle them yet. You played very well, though."
result_list.sort(key=lambda x:x[1], reverse=True)
# TO DO - determine winner, handle ties
print result_list
# [[1, 8], [2, 7]]
print result_list[0][1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment