Advertisement
lil_blizzard

Untitled

Aug 4th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.89 KB | None | 0 0
  1. import random
  2.  
  3. #beginning balance
  4. playerBalance = 5
  5. enemyBalance = 5
  6. again = True
  7.  
  8. isPlayerTurn = True
  9.  
  10. while True:
  11.     response = input('Are you ready to play ceelo?: ')
  12.     #continue if user enters yes
  13.     if response=='yes' or response=='y':
  14.         print('You have $' + str(playerBalance))
  15.         break
  16.     elif response=='no' or response=='n' or response=='nope':
  17.         exit()
  18.     else:
  19.         print('Not really what I wanted to hear.')
  20.  
  21. def SetPlayerBet(bal):
  22. #runs while this condition is true & until it is broken by 'break'
  23.     while True:
  24.         bet = input('Enter your bet: ')
  25.         print('.')
  26.         #try loop is accounting for ValueError - in case the user inputs something besides a number
  27.         try:
  28.             if int(bet) <= 5:
  29.                 print('Your bet is $' + str(bet))
  30.                 bal-=int(bet)
  31.                 break
  32.             elif int(bet) < 1:
  33.                 print('You have to bet something!')
  34.             else:
  35.                 print("You can't bet that much.")
  36.         except ValueError:
  37.             print('Enter a number please.')
  38.  
  39.     print('You have $' + str(bal) + ' left')
  40.     print('.')
  41.  
  42. def SetEnemyBet(bal):
  43.     b = random.randint(0,5)
  44.     bal-=b
  45.     print('Your opponent bet $' + str(b) + '.')
  46.     print('They have $' + str(bal) + ' left.')
  47.     print('.')
  48.  
  49. #dice roll function
  50. def RollDice():
  51.     return [random.randint(1,6) for _ in range(3)]
  52.  
  53. #analyze the roll list
  54. def AnalyzeRoll(inputRoll):
  55.     inputRoll.sort()
  56.     if isPlayerTurn:
  57.         print('Your roll is: ' + str(inputRoll))
  58.     else:
  59.         print("Your opponent's roll is: " + str(inputRoll))
  60.     if inputRoll == [4,5,6] or len(set(inputRoll)) == 1:
  61.         #456 or triple - auto win
  62.         return(-1)
  63.     elif inputRoll[0] == inputRoll[1] or inputRoll[1] == inputRoll[2]:
  64.         if inputRoll[2] == 6 and inputRoll[1] != inputRoll[2]:
  65.             #pair of non 6 and 6 - auto win
  66.             return(-1)
  67.         elif inputRoll[0] == 1 and inputRoll[0] != inputRoll[1]:
  68.             #pair of non 1 and 1 - auto lose
  69.             return(-2)
  70.         elif inputRoll[1] != inputRoll[2]:
  71.             #left pair
  72.             if isPlayerTurn:
  73.                 print('Your score is: ' + str(inputRoll[2]))
  74.             else:
  75.                 print("Your opponent's score is: " + str(inputRoll[2]))
  76.             again = False
  77.             return(inputRoll[2])
  78.         elif inputRoll[0] != inputRoll[1]:
  79.             #right pair
  80.             if isPlayerTurn:
  81.                 print('Your score is: ' + str(inputRoll[0]))
  82.             else:
  83.                 print("Your opponent's score is: " + str(inputRoll[0]))
  84.             again = False
  85.             return(inputRoll[0])
  86.     elif inputRoll == [1,2,3]:
  87.         #auto lose 123
  88.         return(-2)
  89.     else:
  90.         #special case code - no valid roll
  91.         return(-3)
  92.  
  93. def UpdateScore(score):
  94.     global again
  95.     global playerScore
  96.     global r
  97.  
  98.     if score == -1:
  99.         if isPlayerTurn:
  100.             print('You win everything!')
  101.         else:
  102.             print('Your opponent takes it all!')
  103.         again = False
  104.     elif score == -2:
  105.         if isPlayerTurn:
  106.             print('You lose everything!')
  107.         else:
  108.             print('You take it all!')
  109.         again = False
  110.     elif score == -3:
  111.         print('Rolling...')
  112.         r = RollDice()
  113.     else:
  114.         again = False
  115.  
  116. SetPlayerBet(playerBalance)
  117. SetEnemyBet(enemyBalance)
  118. playerRoll = RollDice()
  119. while again is True:
  120.     scorecode = AnalyzeRoll(playerRoll)
  121.     UpdateScore(scorecode)
  122.  
  123. #trying to roll for the enemy - not sure about how to handle this
  124. #after the again variable is set to false in the above loop
  125. #i would include it in the above loop, but it requires isPlayerTurn
  126. #to be false in order to succeed
  127. isPlayerTurn = False
  128. enemyRoll = RollDice()
  129. while True:
  130.     scorecode = AnalyzeRoll(enemyRoll)
  131.     UpdateScore(scorecode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement