Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final, working version #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 82 additions & 50 deletions game.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,99 @@
from random import randint


goalScore = input("Please enter the score you would like to count up to: ")
player = player1
goalScore = int(input("Please enter the score you would like to count up to: "))
player = "player1"
turnscore = 0
p1totalScore = 0
p2totalScore = 0

def game(goalScore, player):
if player == player1:
turnscore = turn(input("It's player 1's turn. Please type 'r' to roll or 'b' to bank: "))
p1totalScore += turnscore
if p1totalScore >= goalScore:
return ("Player 1 has won the game with a score of " + str(p1totalScore))

def game(goalScore, player, turnscore,p1totalScore,p2totalScore):
if player == "player1":
if turnscore == "SNAKE EYES":
p1totalScore = 0
turnscore = 0
player = "player2"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif turnscore == "ONE 1":
turnscore = 0
p1totalScore += turnscore
player = "player2"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif turnscore == 0:
choice = input("It's player 1's turn. Please type 'r' to roll or 'b' to bank: " )
return turn(player, choice, turnscore, p1totalScore, p2totalScore)
else:
return (game(goalScore, player2))
else:
turnscore = turn(input("It's player 2's turn. Please type 'r' to roll or 'b' to bank: "))
p2totalScore += turnscore
if p2totalScore >= goalScore:
return ("Player 2 has won the game with a score of " + str(p1totalScore))
p1totalScore += turnscore
if p1totalScore >= goalScore:
return ("Player 1 has won the game with a score of " + str(p1totalScore))
else:
turnscore = 0
player = "player2"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif player == "player2":
if turnscore == "SNAKE EYES":
p2totalScore = 0
turnscore = 0
player = "player1"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif turnscore == "ONE 1":
turnscore = 0
p2totalScore += turnscore
player = "player1"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif turnscore == 0:
choice = input("It's player 2's turn. Please type 'r' to roll or 'b' to bank: ")
return turn(player, choice, turnscore, p1totalScore, p2totalScore)
else:
return (game(goalScore, player1))
p2totalScore += turnscore
if p2totalScore >= goalScore:
return ("Player 2 has won the game with a score of " + str(p2totalScore))
else:
turnscore = 0
player = "player1"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))

#after each roll prompt user to roll or bank again
def turn(choice):
turnOn = True
while turnOn == True:
turnscore = 0
dice = []
dicesum = 0
if choice == "r":
notEnd = True
while notEnd == True:
randNum1 = randint(1,6)
randNum2 = randint(1,6)
dice.append(randNum2)
dice.append(randNum1)
if (randNum1+randNum2) == 2:
notEnd = False
print("Snake eyes!! ", dice)
turnOn = False
#somehow set total score = to 0
elif randNum1 == 1 or randNum2 == 1:
turnscore = 0
notEnd = False
turnOn = False
elif randNum1 == randNum2:
turnscore += dicesum
#can't bank: print(You rolled 2 of the same number, press r to toll again!)
def turn(player, choice, turnscore, p1totalScore, p2totalscore):

else:
print("You rolled: ", dice)
dicesum = sum(dice)
turnscore += dicesum
notEnd = False
print("The turn score is: ", dicesum)
dice = []
dicesum = 0
if choice == "r":
randNum1 = randint(1,6)
randNum2 = randint(1,6)
dice.append(randNum2)
dice.append(randNum1)
if (randNum1+randNum2) == 2:
print("Snake eyes!! ", dice)
print ("Your total score will be reset to 0 and your turn is over.")
turnscore = "SNAKE EYES"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))
elif randNum1 == 1 or randNum2 == 1:
print ("You rolled: ", dice)
print ("Your score for this turn is 0 and your turn is over.")
turnscore = "ONE 1"
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))

elif randNum1 == randNum2:
print ("You rolled: ", dice)
dicesum = sum(dice)
print ("Since you rolled 2 of the same number, " + str(dicesum) + " will be added to your score for this turn and you have to roll again.")
turnscore += dicesum
return (turn (player, (input("Please type r to roll again: ")), turnscore, p1totalScore, p2totalScore))

else:
print("You rolled: ", dice)
dicesum = sum(dice)
turnscore += dicesum
turnOn = False
return turnscore
print ("The score for your turn is now " + str(turnscore))
return (turn (player, (input("Type r to roll again or b to bank: ")), turnscore, p1totalScore, p2totalScore))
else:
turnscore += dicesum
return (game(goalScore, player, turnscore, p1totalScore, p2totalScore))






game(goalScore)
game(goalScore, player, turnscore, p1totalScore, p2totalScore)