Two Player Dice Game - Lindsay Newbold - GCSE Computer Science Coursework
Documented report of my 'Two Player Dice Game' python code project. Includes: Front page; contents page; analysis (Success criteria); design (Pseudocode); development (Python code); testing (passes/failures within the code); the evaluation page (written review of how successfull my program was; followed by the new skills I have developed from coding in this project). Enjoy! ( ͡~ ͜ʖ ͡°)
Documented report of my 'Two Player Dice Game' python code project.
Includes:
Front page;
contents page;
analysis (Success criteria);
design (Pseudocode);
development (Python code);
testing (passes/failures within the code);
the evaluation page (written review of how successfull my program was; followed by the new skills I have developed from coding in this project).
Enjoy! ( ͡~ ͜ʖ ͡°)
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Two Player Dice
Game
Coursework
Lindsay Newbold
Contents
1. Analysis - Page 3
2. Design - Page 4
3. Development - Page 5
4. Testing - Page 12
5. Evaluation - Page 19
HOLD Ctrl + Click on the page
you want to go to
Analysis
The success criteria I created for my program are the
following:
➔ Users can authenticate
➔ Users can create an account
➔ Both players have their scores added / subtracted from
their score each round WITH a reason why.
➔ Total score of the winner announced at the end
➔ Winner of the game is announced
➔ Rounds counter functional
➔ Tiebreaker round functional
Design
Pseudocode:
Python Code
Pseudocode
Here, I have translated 21 lines
of my python code into 23 lines
of pseudocode.
Development
"Hello and welcome to Lindsay's casino!
You are playing a luck dice game.
Whoever scores the highest at the end of
the round WINS! Good luck. Type 'next'
"The rules: Each player will roll 2 dice per round. If you get two of
the same number you can roll an extra dice :), if your score for
the round is even you get 10 points extra :D, however if it is odd
then 5 points are taken. Your score can only be <=0 and there are
5 rounds"
#Lindsay's Casino Dice Game
import random
import time
player1Score = 0
player2Score = 0
global player1
global player2
player1 = ""
player2 = ""
viewrule = False
#Introduction
viewrule = str(input("Hello and welcome to Lindsay's casino! You are playing a luck dice
game. Whoever scores the highest at the end of the round WINS! Good luck. Type 'next'
to proceed."))
if viewrule == "next":
#The rules
print("The rules: Each player will roll 2 dice per round. If you get two of the same
number you can roll an extra dice :), if your score for the round is even you get 10
points extra :D, however if it is odd then 5 points are taken. Your score can only be <=0
and there are 5 rounds")
#The login for Player1
def authentication1():
global player1
print("Player1, Do you want to log in or make an account with us today?")
print("1.Login")
time.sleep(1)
print("2.Signup")
IflogInIs = False
#Can either Create a new account or login
then = str(input("Type either 'log in' OR 'sign up': "))
if then == "log in":
IflogInIs = True
if then == "sign up":
IflogInIs = True
while IflogInIs == False:
then = str(input("Incorrect please type either 'log in'/'sign up'"))
if then == "log in":
IflogInIs = True
if then == "sign up":
IflogInIs = True
if then == "log in":
isLogin = False
while isLogin == False:
print ("Do you have your membership details?")
userName = str(input("Enter your username: "))
password = str(input("Enter your password: "))
#Text file with users saved
login = open("users.txt", "r")
users = login.readlines()
for lines in users:
details = lines.split(",")
linePassword = details[1].split("\n")
if details[0] == userName:
if linePassword[0] == password:
print("Great to see you again!",userName)
player1 = userName
isLogin = True
if isLogin == False:
print ("Incorrect details, please re-enter")
if then == "Signup":
print("Player 1, Do you want to log in or make an account with us
today?")
print("1.Create your own username")
time.sleep(1)
print("2.Generate a username")
userNameChoice = input("Type either 'create'/'generate'")
if userNameChoice == "create":
nameRight = False
while nameRight == False:
newUserName = input("Create a username: ")
isNameRight = input("press 5 to move on")
if isNameRight == "5":
nameRight = True
#Generating a username
elif userNameChoice == "generate":
print ("To generate a username we need your first name, last name and the last
two digits of your birth year")
firstname = input("What is your first name: ")
lastname = input("What is your last name: ")
birthdate = input("What is the last two digits of your birth year: ")
newUserName =
firstname[0]+firstname[1]+firstname[2]+lastname[1]+lastname[2]+birthdate[0]+birthdate[1]
print ("Abracadabra...",newUserName,".This is your new username!")
print("Time to set your password")
player1Pass = input("Enter your password: ")
print("Your password is",player1Pass)
login = open("users.txt", "a")
login.write(newUserName+","+player1Pass)
login.write("\n")
player1 = newUserName
#Player 1 is authenticated
login.close()
return True
#Player 2 login system
def authentication2():
global player2
print("Player2, Would you like to log in or make an account with us today?")
print("1.Login")
time.sleep(1)
print("2.Signup")
a = False
b = str(input("Type either 'login' OR 'signup'"))
if b == "login":
a = True
if b == "signup":
a = True
while a == False:
b = str(input("Incorrect please enter either login/signup: "))
if b == "login":
a = True
if b == "signup":
a = True
if b == "login":
c = False
while c == False:
print ("Do you have your membership details?")
userName = str(input("Enter your username: "))
password = str(input("Enter your password: "))
login = open("users.txt", "r")
users = login.readlines()
for lines in users:
details = lines.split(",")
linePassword = details[1].split("\n")
if details[0] == userName:
if linePassword[0] == password:
print("Great to see you again!",userName)
player2 = userName
isLogin = True
if isLogin == False:
print ("Incorrect details, please re-enter your credentials")
if b == "signup":
print("Player2, Do you want to make your own username or generate one")
print("1.Create your own username")
time.sleep(1)
print("2.Generate a username")
userNameChoice = input("Type either create/generate: ")
if userNameChoice == "create":
nameRight = False
while nameRight == False:
newUserName = input("Create a username: ")
isNameRight = input("Press 5 to move on")
if isNameRight == "5":
nameRight = True
elif userNameChoice == "generate":
print ("To generate a username we need your first name, last name and the last
2 digits of your year of birth")
firstname = input("What is your first name: ")
lastname = input("What is your last name: ")
birthdate = input("What is the last two digits of your birth year: ")
newUserName =
firstname[0]+firstname[1]+firstname[2]+lastname[1]+lastname[2]+birthdate[0]+birthdate[1]
print ("Abracadabra...",newUserName,".This is your new username!")
print("Time to set your password")
player2Pass = input("Enter your password: ")
print("Your password is",player2Pass)
login = open("users.txt", "a")
login.write(newUserName+","+player2Pass+"\n")
player2 = newUserName
#End of authenticating
login.close()
return True
#The game!
def attemptgame():
global player1Score
global player2Score
print("It is round",str(roundNo),".")
print("It is "+player1+"'s turn")
#An input that does nothing but is user interaction for when they want to roll
input("Press enter to roll")
#Random pick of a number between 0 and 7
die1 =random.randint(1,6)
die2 =random.randint(1,6)
print("You got a",str(die1),"and",str(die2),".")
diceTotal = die1 + die2
#Checking if the total is even
if (diceTotal%2) == 0:
print("Wow your total for this round is even. Plus 10 for you!")
player1Score = player1Score + 10
else:
print("Not good. You got an odd roll so you lose 5 points, disappointing")
player1Score = player1Score -5
#Has the player rolled a double? If so, an extra throw is available
if die1 == die2:
print("Lucky you! You rolled two of the same number so now you get an extra
roll")
input("Press enter to roll your extra dice")
die3 =random.randint(1,6)
print("You got a",str(die3),".")
player1Score= player1Score+diceTotal+die3
if player1Score<0:
player1Score=0
print("You are on",str(player1Score))
else:
player1Score= player1Score+diceTotal
if player1Score<0:
player1Score=0
print("You are on",str(player1Score))
#An input for user interaction for when they want to roll
print("It is "+player2+"'s turn to roll")
input("Press enter to roll")
die1 =random.randint(1,6)
die3 =random.randint(1,6)
print("You got a",str(die1),"and",str(die2),".")
diceTotal = die1 + die2
#Is the roll even or odd?
if (diceTotal%2) == 0:
print("Even roll! 10 points for you!")
player2Score = player2Score + 10
else:
print("Not good. You got an odd roll so you lose 5 points, disappointing")
player2Score = player2Score -5
#If the value on the 2 die are the same, the player gets an extra roll
if die1 == die2:
print("Luck you! A double! Have a free extra roll.")
input("Press enter to roll your extra dice. Make it count!")
die3 =random.randint(1,6)
print("You got a",str(die3),".")
player2Score= player2Score+diceTotal+die3
if player2Score<0:
player2Score=0
print("You are on",str(player2Score))
else:
player2Score= player2Score+diceTotal
if player2Score<0:
player2Score=0
print("You are on",str(player2Score))
authentication1()
authentication2()
for roundNo in range(1,6):
attemptgame()
#Tiebreaker round IF scores are the same
while player1Score == player2Score:
input("You both scored the same, but it's not over... Time for the deciding
tiebreaker!")
print("It is",player1+"'s turn")
input("Press enter to roll")
die1 =random.randint(1,6)
player1Score= player1Score+die1
print("Currently, you are on",str(player1Score),player1+"\n")
print("It is",player2+"'s turn")
input("Press enter to roll")
die1 =random.randint(1,6)
player2Score= player2Score+die1
print("Currently, you are on",str(player2Score),player2+"\n")
#Comparing scores and announcing the winner
if player1Score > player2Score:
print ("Player 1 WINS! Congratulations with a score of",player1Score,"! Better Luck
next time",player2,"!")
if player1Score < player2Score:
print (player2,"WINS! Congratulations with a score of",player2Score,"! Better luck
next time Player 1!")
input("Thanks for playing! Press the 'e' to exit")
if input == "e":
exit()
Testing
Test
Testing
for…
Pass / Fail
How I would
change my
program to
improve this issue
Player 1
Sign up
system
Fail. Skips
the whole of
player 1’s
sign-up
system.
Look over the
code and make
sure the
variables for
player 1’s login
system are
different from
player 2’s to
prevent jumps in
the code (Skips).
Jumps to Player 2 login
system without Player
1 logged in.
Test
Testing
for…
Player 2
Sign up
system
Pass / Fail
Pass
How I would
change my
program to
improve this issue
Test
Testing
for…
Player 1
log in
system
Pass / Fail
Pass
How I would
change my
program to
improve this issue
Test
Testing
for…
Player 2
log in
system
Pass / Fail
Pass
How I would
change my
program to
improve this issue
Test
Testing
for…
Scores
totaled
correctly.
Pass / Fail
Pass
How I would
change my
program to
improve this issue
Test
Testing
for…
Pass / Fail
How I would
change my
program to
improve this issue
Typo redo for
user input
when
choosing to
create /
generate a
username.
Fail
Add a loop to
the
create/generate
option so if the
user doesn’t
input either, the
program will ask
them to try
again
Test
Testing
for…
Pass / Fail
How I would
change my
program to
improve this issue
Line spacing
to make the
game more
readable
Pass
Insert “/n/n” into
the code to
make an empty
space between
the current line
and the next line
Testing
Evaluation
How successful was my program?
My program was overall successful because most components of
the code were able to function properly, allowing the game to be
played to the end of the script. The authentication script was a
success with users having the ability to have their usernames
and passwords saved to the database, permitting them to quickly
login next time they play the dice game. Moving on to the game
itself, users are notified on what round they are on, their current
scores, and who the winner is. Major components like these are
what makes the game effective. Also, bonus rolls are available if
the user rolls 2 equivalent numbers. And if the users score the
same at the end of the game, there is an additional tiebreaker
round to decide the winner. Even though there are a few issues
with the script, for example line spacing, player 1’s signup
system, I’m certain that this game comprises of all the
requirements needed for a two-player dice game: The login script
was a success, the instructions and key messages were readable,
the dice was unbiased, and lastly, the score counter summed the
scores correctly.
New skills I have developed
Working on this project has really increased my confidence with
coding in general. I have learnt many new reserved words which
I decided to use in my project. I also learnt how to use lists, which
allows me to display certain letters from a variable, simplifying
the code. Another thing I have learnt from programming is how
to link text files to my code for users and passwords. Lastly, I
have learnt what Pseudocode is, why it is used, and how to use
it. One key thing that I have gained from this project is a better
understanding of programming concepts.