Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################
- # Author: Anthony Romero
- # Date: 2/23/2017
- ####################################
- #This program will simulate a game involving rolling dice.
- #This program will simulate a game of Craps. It will roll the pair of dice three times. It will keep score for the “house” (the computer), and for the player.
- #It will then display these scores each time the dice are rolled based on the rules listed below. It will lastly display a final winner at the end of the game.
- # First, we have our general variables.
- Number_of_Rolls = 0
- Dice1 = 0
- Dice2 = 0
- Is_Craps = 0
- h_score = 0
- p_score = 0
- total_h = 0
- total_p = 0
- Start_Game = True #Keeps Game in Loop
- #Now we create our functions.
- def Check(): # Runs all scenarios.
- Craps()
- Dble_Evn()
- Dble_Odd()
- Low()
- High()
- def Craps(): #Logic for CRAPS dice.
- global h_score
- global Dice1
- global Dice2
- if Dice1 + Dice2 == 7 or 11:
- print ("\nCRAPS!")
- h_score += 2
- Is_Craps = 1
- def Dble_Evn(): # Logic for Dble_Evn.
- global p_score
- global Dice1
- global Dice2
- if Dice1 == Dice2:
- if Dice1 % 2 == 0:
- if Dice2 % 2 == 0:
- p_score += 2
- print ('\nDouble and Even!')
- def Dble_Odd(): # Logic for Dble_Odd.
- global h_score
- global Dice1
- global Dice2
- if Dice1 == Dice2:
- if Dice1 % 2 >= 1:
- if Dice2 % 2 >= 1:
- h_score += 2
- print ('\nDouble and Odd!')
- def Low(): #Logic for lower than seven.
- global h_score
- global Dice1
- global Dice2
- if Dice1 != Dice2:
- if Dice1 + Dice2 < 7:
- if Is_Craps == 0:
- h_score += 2
- Is_Craps = 0
- print ("\nLow!")
- def High(): # Logic for higher than seven.
- global p_score
- global Dice1
- global Dice2
- if Dice1 != Dice2:
- if Dice1 + Dice2 > 7:
- if Dice1 + Dice2 != 11:
- p_score += 2
- print ("\nHigh!")
- def Roll_Dice(): # Logic for the main functioning of the program.
- start_dice = 1
- global h_score
- global p_score
- global Dice1
- global Dice2
- global Number_Of_Rolls
- while start_dice == 1: # Begins dice rolling.
- Number_Of_Rolls += 1
- Dice1 = randint(1, 6)
- Dice2 = randint(1, 6)
- if Number_Of_Rolls == 1: # Roll 1.
- print('Roll 1\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
- Check() # checks winner
- print('\nYour score: \t{}\nHouse score: \t{}\n'.format(p_score, h_score))
- if Number_Of_Rolls == 2: # Roll 2.
- input ('Press Enter to continue.')
- print('Roll 2\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
- Check()# checks winner
- print('\nYour score: \t{}\nHouse score: \t{}\n'.format(p_score, h_score))
- if Number_Of_Rolls == 3: #Roll 3.
- input ('Press Enter to continue.')
- print('Roll 3\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
- Check()# Checks winner.
- print('\nYour score: \t{}\nHouse score: \t{}'.format(p_score, h_score))
- start_dice = 0 # Ends rolls after three rolls.
- ################################################################
- # Time to begin the game.
- ################################################################
- input ('Welcome to CRAPS. Press ENTER to begin.')
- ### Program begins.
- from random import randint # turn on random
- Start_Game = True # keeps game in loop
- while Start_Game is True:
- Number_Of_Rolls = 0 #resets last games scores
- p_score = 0
- h_score = 0
- Roll_Dice() # <------ Most of the program is ran by this function
- if p_score > h_Score:
- total_p += 1 # Player wins
- input('\nYou Win!\n\nYour total wins: {}\t House total wins: {}' \
- '\n\nPress Enter to start a new game: '.format(total_p, total_h))
- if h_score > p_score:
- total_h += 1 # House wins
- input('\nHouse Wins!\n\nYour total wins: {}\t House total wins: {}' \
- '\n\nPress Enter to start a new game: '.format(total_p, total_h))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement