Skip to content

Instantly share code, notes, and snippets.

@maxfire2008
Created September 1, 2022 02:39
Show Gist options
  • Save maxfire2008/961195924d407b0f3e76c8577cc76658 to your computer and use it in GitHub Desktop.
Save maxfire2008/961195924d407b0f3e76c8577cc76658 to your computer and use it in GitHub Desktop.
I made this game in 2020 for a python course in Grade 6 - I published because we played this in maths today (1 Sep 2022) - so I went digging
#!/usr/bin/python3
import random, time
min = 1
max = 6
pa = 0
pb = 0
startdone = 0
gamedone = 0
read = 'n'
#Instructions
print('PIG by Max B')
print('---------------------------INTERACTION--------------------------')
print('This version is a 2 player game. Type anything other then the')
print('specified options in a y/n question and the game will crash.')
print('This is a good way to quit the game!')
print('')
print('------------------------------RULES-----------------------------')
print('To decide who goes first the game will roll 2 dice. The highest')
print('number is the player who goes first!')
print('')
print('On a turn, a player rolls the die repeatedly. The goal is to')
print('accumulate as many points as possible, adding up the numbers')
print('rolled on the die. However, if a player rolls a 1, the player\'s')
print('turn is over and any points they have accumulated during this')
print('turn are forfeited. Rolling a 1 doesn\'t wipe out your entire')
print('score from previous turns, just the total earned during that')
print('particular roll.')
print('')
print('A player can also choose to hold (stop rolling the die) if they')
print('do not want to take a chance of rolling a 1 and losing all of')
print('their points from this turn. If the player chooses to hold, all')
print('of the points rolled during that turn are added to his or her')
print('score.')
while read != 'y':
read = input('Have you read ALL of the instructions? y/n')
print('''
''')
#First Person
while startdone != 1:
rolla = random.randint(min, max)
print(f'Player 1 you rolled a {rolla}!')
time.sleep(1)
rollb = random.randint(min, max)
print(f'Player 2 you rolled a {rollb}!')
if rolla > rollb:
currentgo = 1
startdone = 1
elif rolla < rollb:
currentgo = 2
startdone = 1
elif rolla == rollb:
print('Results equal rolling again.')
startdone = 0
else:
quit('Error 65')
time.sleep(1)
#Game Start
while gamedone != 1:
if currentgo == 1:
print('')
print('Scoreboard')
print(f'Player 1: {pa}')
print(f'Player 2: {pb}')
print('')
print('Player 1\'s go!')
rounddone = 0
rolla = 0
ra = 0
stopq = 0
time.sleep(1)
while rounddone != 1:
rolla = random.randint(min, max)
print(f'Player 1 you rolled a {rolla}!')
time.sleep(1)
ra = ra + rolla
if rolla != 1:
stopq = input(f'Player 1 do you want to stop and go away with {ra} points? y/n')
if stopq == 'y':
pa = pa + ra
rounddone = 1
currentgo = 2
elif rolla == 1:
time.sleep(1)
print('Points not gained sorry.')
rounddone = 1
currentgo = 2
elif stopq != 'n':
quit('Error 98')
if pa >= 100:
gamedone = 1
elif pb >= 100:
gamedone = 1
elif currentgo == 2:
print('')
print('Scoreboard')
print(f'Player 1: {pa}')
print(f'Player 2: {pb}')
print('')
print('Player 2\'s go!')
rounddone = 0
rollb = 0
rb = 0
stopq = 0
time.sleep(1)
while rounddone != 1:
rollb = random.randint(min, max)
print(f'Player 2 you rolled a {rollb}!')
time.sleep(1)
rb = rb + rollb
if rollb != 1:
stopq = input(f'Player 2 do you want to stop and go away with {rb} points? y/n')
if stopq == 'y':
pb = pb + rb
rounddone = 1
currentgo = 1
elif rollb == 1:
time.sleep(1)
print('Points not gained sorry.')
rounddone = 1
currentgo = 1
elif stopq != 'n':
quit('Error 132')
if pa >= 100:
gamedone = 1
elif pb >= 100:
gamedone = 1
else:
quit('Error 140')
if pa > pb:
print('Scoreboard')
print(f'Player 1: {pa}')
print(f'Player 2: {pb}')
print('')
print('Player 1 won!')
elif pa < pb:
print('Scoreboard')
print(f'Player 1: {pa}')
print(f'Player 2: {pb}')
print('')
print('Player 2 won!')
elif pa == pb:
print('Scoreboard')
print(f'Player 1: {pa}')
print(f'Player 2: {pb}')
print('')
print('It was a Draw!')
else:
quit('Error 161')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment