Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dice game extended for two players
- # Again please DON'T just copy this, understand each step as I walk through the video
- # You may find other ways of achieving the same objective
- import random, time
- def roll():
- d1 = random.randint(1,6)
- d2 = random.randint(1,6)
- #d1 = int(input("Enter d1 >>"))
- #d2 = int(input("Enter d2 >>"))
- d3 = 0
- tot = d1 + d2
- if tot % 2 ==0: # testing there for an even number
- tot +=10
- else:
- tot -= 5 # tot = tot -5
- if tot < 0:
- tot = 0
- if d1 == d2: # checking for both the same
- d3 = random.randint(1,6)
- tot += d3
- #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot) # for testing
- return tot
- p1score = 0 # initalising total variables
- p2score = 0
- for i in range(5):
- print("round", i+1)
- p1roll = roll()
- p2roll = roll()
- time.sleep(1)
- print("P1 scored", p1roll)
- time.sleep(1)
- print("P2 scored", p2roll)
- p1score +=p1roll
- p2score +=p2roll # p2score = p2score +p2roll
- time.sleep(1)
- print("Total scores P1 -", p1score,"P2 -", p2score)
- #input()
- #forcing the score to be the same
- #p1score = 100
- #p2score = 100
- while p1score == p2score:
- print("Draw round")
- p1roll = roll()
- p2roll = roll()
- time.sleep(1)
- print("P1 Draw roll scored", p1roll)
- time.sleep(1)
- print("P2 Draw roll scored", p2roll)
- p1score +=p1roll
- p2score +=p2roll # p2score = p2score +p2roll
- time.sleep(1)
- print("Total scores P1 -", p1score,"P2 -", p2score)
- if p1score > p2score:
- print("Player 1 wins score", p1score)
- else:
- print("Player 2 wins score", p2score)
- #print("die1=",d1,"die2=", d2, "die3=",d3,"total=", tot)
- #print("die1= " + str(d1) +" die2= " +str(d2) + " tot= " +str(tot)) # concatenation + casting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement